Skip to content

Commit e9c1d6d

Browse files
committed
Successful TFT display test script
1 parent ea6d606 commit e9c1d6d

37 files changed

+2289
-3
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ myvenv/
157157
.vscode
158158
myenv
159159

160-
# installation flags
160+
# installation flags and installed libraries
161161
installers/i2s_mic_installed.flag
162162
installers/i2s_speech_recognition_installed.flag

config/i2c.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
i2c:
2-
enabled: true
2+
enabled: false
33
path: modules.i2c.I2C
44
config:
55
port: 1 # port 1 is used for i2c on the raspberry pi newer than October 2012, port 0 is used for older models

config/tft_display.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tft_display:
2+
enabled: false
3+
path: modules.display.tft_display.TFTDisplay
4+
config:
5+
bus: 0 # Use `ls /dev/spi*` to identify. (/dev/spidev0.0) is bus 0, device 0
6+
device: 0 # Use `ls /dev/spi*` to identify. (/dev/spidev0.0) is bus 0, device 0
7+
rst_pin: 27
8+
dc_pin: 25
9+
bl_pin: 18 # Not used if no backlight pin on device
10+
test_on_boot: true
11+
dependencies:
12+
unix:
13+
- python3-pip
14+
- python3-pil
15+
- python3-numpy
16+
python:
17+
- spidev

config/ttsmodule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ tts:
88
python:
99
- pyttsx3
1010
- elevenlabs
11+
additional:
12+
- installers/install-amp.sh

installers/install-mics.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ else
143143
fi
144144

145145
# Create the install flag file to prevent reinstallation
146-
# touch $INSTALL_FLAG
146+
touch $INSTALL_FLAG
147147

148148
cat << EOF
149149
DONE.

installers/install-spi-tft.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Not required on latest attempt, leaving this in for now but will probably remove.
4+
# # if lg-master already exists, then exit
5+
# if [ -d "lg-master" ]; then
6+
# echo "lg-master already exists. Exiting."
7+
# exit 1
8+
# fi
9+
10+
# wget https://github.com/joan2937/lg/archive/master.zip
11+
# unzip master.zip
12+
# cd lg-master
13+
# sudo make install
14+
# #for more details, you can refer to https://github.com/gpiozero/lg

modules/display/lib/LCD_0inch96.py

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
2+
import time
3+
from . import lcdconfig
4+
5+
class LCD_0inch96(lcdconfig.RaspberryPi):
6+
7+
width = 160
8+
height = 80
9+
def command(self, cmd):
10+
self.digital_write(self.DC_PIN, False)
11+
self.spi_writebyte([cmd])
12+
13+
def data(self, val):
14+
self.digital_write(self.DC_PIN, True)
15+
self.spi_writebyte([val])
16+
17+
def reset(self):
18+
"""Reset the display"""
19+
self.digital_write(self.RST_PIN,True)
20+
time.sleep(0.01)
21+
self.digital_write(self.RST_PIN,False)
22+
time.sleep(0.01)
23+
self.digital_write(self.RST_PIN,True)
24+
time.sleep(0.01)
25+
26+
def Init(self):
27+
"""Initialize dispaly"""
28+
self.module_init()
29+
self.reset()
30+
31+
self.command(0x11)
32+
time.sleep(0.1)
33+
self.command(0x21)
34+
self.command(0x21)
35+
36+
self.command(0xB1)
37+
self.data(0x05)
38+
self.data(0x3A)
39+
self.data(0x3A)
40+
41+
self.command(0xB2)
42+
self.data(0x05)
43+
self.data(0x3A)
44+
self.data(0x3A)
45+
46+
self.command(0xB3)
47+
self.data(0x05)
48+
self.data(0x3A)
49+
self.data(0x3A)
50+
self.data(0x05)
51+
self.data(0x3A)
52+
self.data(0x3A)
53+
54+
self.command(0xB4)
55+
self.data(0x03)
56+
57+
self.command(0xC0)
58+
self.data(0x62)
59+
self.data(0x02)
60+
self.data(0x04)
61+
62+
self.command(0xC1)
63+
self.data(0xC0)
64+
65+
self.command(0xC2)
66+
self.data(0x0D)
67+
self.data(0x00)
68+
69+
self.command(0xC3)
70+
self.data(0x8D)
71+
self.data(0x6A)
72+
73+
self.command(0xC4)
74+
self.data(0x8D)
75+
self.data(0xEE)
76+
77+
self.command(0xC5)
78+
self.data(0x0E)
79+
80+
self.command(0xE0)
81+
self.data(0x10)
82+
self.data(0x0E)
83+
self.data(0x02)
84+
self.data(0x03)
85+
self.data(0x0E)
86+
self.data(0x07)
87+
self.data(0x02)
88+
self.data(0x07)
89+
self.data(0x0A)
90+
self.data(0x12)
91+
self.data(0x27)
92+
self.data(0x37)
93+
self.data(0x00)
94+
self.data(0x0D)
95+
self.data(0x0E)
96+
self.data(0x10)
97+
98+
self.command(0xE1)
99+
self.data(0x10)
100+
self.data(0x0E)
101+
self.data(0x03)
102+
self.data(0x03)
103+
self.data(0x0F)
104+
self.data(0x06)
105+
self.data(0x02)
106+
self.data(0x08)
107+
self.data(0x0A)
108+
self.data(0x13)
109+
self.data(0x26)
110+
self.data(0x36)
111+
self.data(0x00)
112+
self.data(0x0D)
113+
self.data(0x0E)
114+
self.data(0x10)
115+
116+
self.command(0x3A)
117+
self.data(0x05)
118+
119+
self.command(0x36)
120+
self.data(0xA8)
121+
122+
self.command(0x29)
123+
124+
def SetWindows(self, Xstart, Ystart, Xend, Yend):
125+
#set the X coordinates
126+
Xstart=Xstart+1
127+
Xend=Xend+1
128+
Ystart=Ystart+26
129+
Yend=Yend+26
130+
self.command(0x2A)
131+
self.data(0x00) #Set the horizontal starting point to the high octet
132+
self.data(Xstart & 0xff) #Set the horizontal starting point to the low octet
133+
self.data(0x00) #Set the horizontal end to the high octet
134+
self.data((Xend - 1) & 0xff) #Set the horizontal end to the low octet
135+
136+
#set the Y coordinates
137+
self.command(0x2B)
138+
self.data(0x00)
139+
self.data((Ystart & 0xff))
140+
self.data(0x00)
141+
self.data((Yend - 1) & 0xff )
142+
143+
self.command(0x2C)
144+
145+
def ShowImage(self,Image):
146+
"""Set buffer to value of Python Imaging Library image."""
147+
"""Write display buffer to physical display"""
148+
imwidth, imheight = Image.size
149+
if imwidth != self.width or imheight != self.height:
150+
if imwidth != self.height or imheight != self.width:
151+
raise ValueError('Image must be same dimensions as display \
152+
({0}x{1}).' .format(self.height,self.width))
153+
else:
154+
img = self.np.asarray(Image)
155+
pix = self.np.zeros((self.width,self.hight,2), dtype = self.np.uint8)
156+
pix[...,[0]] = self.np.add(self.np.bitwise_and(img[...,[0]],0xF8), self.np.right_shift(img[...,[1]],5))
157+
pix[...,[1]] = self.np.add(self.np.bitwise_and(self.np.left_shift(img[...,[1]],3),0xE0), self.np.right_shift(img[...,[2]],3))
158+
else:
159+
img = self.np.asarray(Image)
160+
pix = self.np.zeros((self.height,self.width,2), dtype = self.np.uint8)
161+
pix[...,[0]] = self.np.add(self.np.bitwise_and(img[...,[0]],0xF8), self.np.right_shift(img[...,[1]],5))
162+
pix[...,[1]] = self.np.add(self.np.bitwise_and(self.np.left_shift(img[...,[1]],3),0xE0), self.np.right_shift(img[...,[2]],3))
163+
164+
pix = pix.flatten().tolist()
165+
self.SetWindows ( 0, 0, self.width, self.height)
166+
self.digital_write(self.DC_PIN,True)
167+
168+
for i in range(0,len(pix),4096):#The length is 160*160*2 Actually 160*80*2 So take 2
169+
self.spi_writebyte(pix[i:i+4096])
170+
171+
172+
def clear(self):
173+
"""Clear contents of image buffer"""
174+
_buffer = [0xff]*(self.width * self.height )
175+
self.SetWindows ( 0, 0, self.width, self.height)
176+
self.digital_write(self.DC_PIN,True)
177+
for i in range(0,len(_buffer),4096):
178+
self.spi_writebyte(_buffer[i:i+4096])

modules/display/lib/LCD_1inch14.py

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
2+
import time
3+
from . import lcdconfig
4+
5+
class LCD_1inch14(lcdconfig.RaspberryPi):
6+
7+
width = 240
8+
height = 135
9+
def command(self, cmd):
10+
self.digital_write(self.DC_PIN, False)
11+
self.spi_writebyte([cmd])
12+
13+
def data(self, val):
14+
self.digital_write(self.DC_PIN, True)
15+
self.spi_writebyte([val])
16+
17+
def reset(self):
18+
"""Reset the display"""
19+
self.digital_write(self.RST_PIN,True)
20+
time.sleep(0.01)
21+
self.digital_write(self.RST_PIN,False)
22+
time.sleep(0.01)
23+
self.digital_write(self.RST_PIN,True)
24+
time.sleep(0.01)
25+
26+
def Init(self):
27+
"""Initialize dispaly"""
28+
self.module_init()
29+
self.reset()
30+
31+
self.command(0x36)
32+
self.data(0x70) #self.data(0x00)
33+
34+
self.command(0x3A)
35+
self.data(0x05)
36+
37+
self.command(0xB2)
38+
self.data(0x0C)
39+
self.data(0x0C)
40+
self.data(0x00)
41+
self.data(0x33)
42+
self.data(0x33)
43+
44+
self.command(0xB7)
45+
self.data(0x35)
46+
47+
self.command(0xBB)
48+
self.data(0x19)
49+
50+
self.command(0xC0)
51+
self.data(0x2C)
52+
53+
self.command(0xC2)
54+
self.data(0x01)
55+
56+
self.command(0xC3)
57+
self.data(0x12)
58+
59+
self.command(0xC4)
60+
self.data(0x20)
61+
62+
self.command(0xC6)
63+
self.data(0x0F)
64+
65+
self.command(0xD0)
66+
self.data(0xA4)
67+
self.data(0xA1)
68+
69+
self.command(0xE0)
70+
self.data(0xD0)
71+
self.data(0x04)
72+
self.data(0x0D)
73+
self.data(0x11)
74+
self.data(0x13)
75+
self.data(0x2B)
76+
self.data(0x3F)
77+
self.data(0x54)
78+
self.data(0x4C)
79+
self.data(0x18)
80+
self.data(0x0D)
81+
self.data(0x0B)
82+
self.data(0x1F)
83+
self.data(0x23)
84+
85+
self.command(0xE1)
86+
self.data(0xD0)
87+
self.data(0x04)
88+
self.data(0x0C)
89+
self.data(0x11)
90+
self.data(0x13)
91+
self.data(0x2C)
92+
self.data(0x3F)
93+
self.data(0x44)
94+
self.data(0x51)
95+
self.data(0x2F)
96+
self.data(0x1F)
97+
self.data(0x1F)
98+
self.data(0x20)
99+
self.data(0x23)
100+
101+
self.command(0x21)
102+
103+
self.command(0x11)
104+
105+
self.command(0x29)
106+
107+
def SetWindows(self, Xstart, Ystart, Xend, Yend):
108+
#set the X coordinates
109+
self.command(0x2A)
110+
self.data((Xstart+40)>>8& 0xff) #Set the horizontal starting point to the high octet
111+
self.data((Xstart+40) & 0xff) #Set the horizontal starting point to the low octet
112+
self.data((Xend-1+40)>>8& 0xff) #Set the horizontal end to the high octet
113+
self.data((Xend-1+40) & 0xff) #Set the horizontal end to the low octet
114+
115+
#set the Y coordinates
116+
self.command(0x2B)
117+
self.data((Ystart+53)>>8& 0xff)
118+
self.data((Ystart+53) & 0xff)
119+
self.data((Yend-1+53)>>8& 0xff)
120+
self.data((Yend-1+53) & 0xff)
121+
122+
self.command(0x2C)
123+
124+
def ShowImage(self,Image):
125+
"""Set buffer to value of Python Imaging Library image."""
126+
"""Write display buffer to physical display"""
127+
128+
imwidth, imheight = Image.size
129+
if imwidth != self.width or imheight != self.height:
130+
raise ValueError('Image must be same dimensions as display \
131+
({0}x{1}).' .format(self.width, self.height))
132+
img = self.np.asarray(Image)
133+
pix = self.np.zeros((self.height,self.width,2), dtype = self.np.uint8)
134+
135+
pix[...,[0]] = self.np.add(self.np.bitwise_and(img[...,[0]],0xF8),self.np.right_shift(img[...,[1]],5))
136+
pix[...,[1]] = self.np.add(self.np.bitwise_and(self.np.left_shift(img[...,[1]],3),0xE0),self.np.right_shift(img[...,[2]],3))
137+
138+
pix = pix.flatten().tolist()
139+
self.SetWindows ( 0, 0, self.width, self.height)
140+
self.digital_write(self.DC_PIN,True)
141+
for i in range(0,len(pix),4096):
142+
self.spi_writebyte(pix[i:i+4096])
143+
144+
def clear(self):
145+
"""Clear contents of image buffer"""
146+
_buffer = [0xff]*(self.width * self.height * 2)
147+
self.SetWindows ( 0, 0, self.width, self.height)
148+
self.digital_write(self.DC_PIN,True)
149+
for i in range(0,len(_buffer),4096):
150+
self.spi_writebyte(_buffer[i:i+4096])
151+
152+

0 commit comments

Comments
 (0)