-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholed_test.py
More file actions
69 lines (51 loc) · 1.7 KB
/
Copy patholed_test.py
File metadata and controls
69 lines (51 loc) · 1.7 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
#!/usr/bin/env python3
"""
Simple 128x64 I2C OLED test for Raspberry Pi.
Expected device:
- SSD1309 OLED
- I2C address: 0x3C
- Resolution: 128x64
Install dependencies on the Pi if needed:
python3 -m pip install luma.oled pillow
"""
import time
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106, ssd1306, ssd1309
WIDTH = 128
HEIGHT = 64
I2C_ADDRESS = 0x3C
def main():
print("Opening I2C bus...")
serial = i2c(port=1, address=I2C_ADDRESS)
drivers = (
("SSD1309", ssd1309),
("SSD1306", ssd1306),
("SH1106", sh1106),
)
try:
for name, driver in drivers:
print(f"Trying {name} at 0x{I2C_ADDRESS:02X}...")
display = driver(serial, width=WIDTH, height=HEIGHT)
print("Flashing display...")
display.clear()
time.sleep(0.5)
with canvas(display) as draw:
draw.rectangle((0, 0, WIDTH - 1, HEIGHT - 1), fill=255)
time.sleep(1)
print(f"Showing {name} test image for 5 seconds...")
with canvas(display) as draw:
draw.rectangle((0, 0, WIDTH - 1, HEIGHT - 1), outline=255)
draw.text((4, 4), "OLED Test", fill=255)
draw.text((4, 20), f"{name} 128x64", fill=255)
draw.text((4, 36), "I2C: 0x3C", fill=255)
draw.text((4, 52), "Hello Pi Zero 2", fill=255)
time.sleep(5)
display.clear()
print("Done trying drivers. Press Ctrl+C to exit.")
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nExiting.")
if __name__ == "__main__":
main()