-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple_screen_1_44_LCD.py
More file actions
executable file
·207 lines (178 loc) · 5.39 KB
/
simple_screen_1_44_LCD.py
File metadata and controls
executable file
·207 lines (178 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# WS128x128 1.44" lcd Minimum
# Called Pico-LCD-1.44"
# Tony Goodhew 21st April 2022 for thepihut.com
from machine import Pin,SPI,PWM
import machine
import framebuf
import utime
import gc
BL = 13
DC = 8
RST = 12
MOSI = 11
SCK = 10
CS = 9
class lcd_1inch44(framebuf.FrameBuffer): # WS 128 x 128 Display
def __init__(self):
self.width = 128
self.height = 128
self.cs = Pin(CS,Pin.OUT)
self.rst = Pin(RST,Pin.OUT)
self.cs(1)
self.spi = SPI(1)
self.spi = SPI(1,1000_000)
self.spi = SPI(1,10000_000,polarity=0, phase=0,sck=Pin(SCK),mosi=Pin(MOSI),miso=None)
self.dc = Pin(DC,Pin.OUT)
self.dc(1)
self.buffer = bytearray(self.height * self.width * 2)
super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
self.init_display()
def write_cmd(self, cmd):
self.cs(1)
self.dc(0)
self.cs(0)
self.spi.write(bytearray([cmd]))
self.cs(1)
def write_data(self, buf):
self.cs(1)
self.dc(1)
self.cs(0)
self.spi.write(bytearray([buf]))
self.cs(1)
def init_display(self):
"""Initialize dispaly"""
self.rst(1)
self.rst(0)
self.rst(1)
self.write_cmd(0x36);
self.write_data(0x70);
self.write_cmd(0x3A);
self.write_data(0x05);
#ST7735R Frame Rate
self.write_cmd(0xB1);
self.write_data(0x01);
self.write_data(0x2C);
self.write_data(0x2D);
self.write_cmd(0xB2);
self.write_data(0x01);
self.write_data(0x2C);
self.write_data(0x2D);
self.write_cmd(0xB3);
self.write_data(0x01);
self.write_data(0x2C);
self.write_data(0x2D);
self.write_data(0x01);
self.write_data(0x2C);
self.write_data(0x2D);
self.write_cmd(0xB4); #Column inversion
self.write_data(0x07);
#ST7735R Power Sequence
self.write_cmd(0xC0);
self.write_data(0xA2);
self.write_data(0x02);
self.write_data(0x84);
self.write_cmd(0xC1);
self.write_data(0xC5);
self.write_cmd(0xC2);
self.write_data(0x0A);
self.write_data(0x00);
self.write_cmd(0xC3);
self.write_data(0x8A);
self.write_data(0x2A);
self.write_cmd(0xC4);
self.write_data(0x8A);
self.write_data(0xEE);
self.write_cmd(0xC5); #VCOM
self.write_data(0x0E);
#ST7735R Gamma Sequence
self.write_cmd(0xe0);
self.write_data(0x0f);
self.write_data(0x1a);
self.write_data(0x0f);
self.write_data(0x18);
self.write_data(0x2f);
self.write_data(0x28);
self.write_data(0x20);
self.write_data(0x22);
self.write_data(0x1f);
self.write_data(0x1b);
self.write_data(0x23);
self.write_data(0x37);
self.write_data(0x00);
self.write_data(0x07);
self.write_data(0x02);
self.write_data(0x10);
self.write_cmd(0xe1);
self.write_data(0x0f);
self.write_data(0x1b);
self.write_data(0x0f);
self.write_data(0x17);
self.write_data(0x33);
self.write_data(0x2c);
self.write_data(0x29);
self.write_data(0x2e);
self.write_data(0x30);
self.write_data(0x30);
self.write_data(0x39);
self.write_data(0x3f);
self.write_data(0x00);
self.write_data(0x07);
self.write_data(0x03);
self.write_data(0x10);
self.write_cmd(0xF0); #Enable test command
self.write_data(0x01);
self.write_cmd(0xF6); #Disable ram power save mode
self.write_data(0x00);
#sleep out
self.write_cmd(0x11);
#Turn on the lcd display
self.write_cmd(0x29);
def show(self):
self.write_cmd(0x2A)
self.write_data(0x00)
self.write_data(0x01)
self.write_data(0x00)
self.write_data(0x80)
self.write_cmd(0x2B)
self.write_data(0x00)
self.write_data(0x02)
self.write_data(0x00)
self.write_data(0x82)
self.write_cmd(0x2C)
self.cs(1)
self.dc(1)
self.cs(0)
self.spi.write(self.buffer)
self.cs(1)
# ====================== End of screen driver ===============
pwm = PWM(Pin(BL))
pwm.freq(1000)
#pwm.duty_u16(32768)#max 65535 ========= HALF BRIGHTNESS
pwm.duty_u16(65535)#max 65535 ========== FULL BRIGHTNESS
lcd = lcd_1inch44() # Start screen
width = 128 # Display size in pixels
height = 128
# Set up buttons
key0 = Pin(15,Pin.IN,Pin.PULL_UP) # Buttons for 1.44 display
key1 = Pin(17,Pin.IN,Pin.PULL_UP)
key2 = Pin(2 ,Pin.IN,Pin.PULL_UP)
key3 = Pin(3 ,Pin.IN,Pin.PULL_UP)
def colour(R,G,B): # Convert RGB888 to RGB565
return (((G&0b00011100)<<3) +((R&0b11111000)>>3)<<8) + (B&0b11111000)+((G&0b11100000)>>5)
def clear(c):
lcd.fill(c)
clear(colour(0,0,0))
lcd.show()
width = 128 # Screen size in pixels
height = 128
# ==== Board now setup ========== MAIN BELOW====================
lcd.text("Red",5,5,colour(255,0,0))
lcd.text("Green",5,15,colour(0,255,0))
lcd.text("Blue",5,25,colour(0,0,255))
lcd.text('1.44" 128x128"',5,35,colour(255,255,0))
lcd.show()
utime.sleep(3)
# Tidy Up ============
pwm.duty_u16(32768)# HALF BRIGHTNESS
clear(0)
lcd.show()