Skip to content

Commit 0c9e0bc

Browse files
committed
ssd1327: Add driver
1 parent cb3186c commit 0c9e0bc

20 files changed

Lines changed: 904 additions & 0 deletions

lib/ssd1327/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# MicroPython library for SSD1327 128x128 4-bit greyscale OLED displays
2+
3+
This library is a port of the [MicroPython library for SSD1327 128x128 4-bit greyscale OLED displays](https://github.com/mcauser/micropython-ssd1327).
4+
5+
The examples could be easily tested with [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) with the following command :
6+
7+
```sh
8+
mpremote mount . run examples/hello_world.py
9+
```

lib/ssd1327/examples/bitmap.py

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# draw a bitmap
2+
# draw 16x15 smiley in horizontal mode
3+
# .....#####...... 00 00 0F FF FF 00 00 00
4+
# ...##.....##.... 00 0F F0 00 00 FF 00 00
5+
# ..#.........#... 00 F0 00 00 00 00 F0 00
6+
# .#...........#.. 0F 00 00 00 00 00 0F 00
7+
# .#...........#.. 0F 00 00 00 00 00 0F 00
8+
# ###############. FF FF FF FF FF FF FF F0
9+
# #.#..####..##.#. F0 F0 0F FF F0 0F F0 F0
10+
# #.#.###.#.###.#. F0 F0 FF F0 F0 FF F0 F0
11+
# #..###...###..#. F0 0F FF 00 0F FF 00 F0
12+
# #.............#. F0 00 00 00 00 00 00 F0
13+
# .#........#..#.. 0F 00 00 00 00 F0 0F 00
14+
# .#....####...#.. 0F 00 00 FF FF 00 0F 00
15+
# ..#.........#... 00 F0 00 00 00 00 F0 00
16+
# ...##.....##.... 00 0F F0 00 00 FF 00 00
17+
# .....#####...... 00 00 0F FF FF 00 00 00
18+
19+
import ssd1327
20+
21+
from machine import SPI, Pin
22+
23+
# Setup display on SPI bus
24+
spi = SPI(1)
25+
dc = Pin("DATA_COMMAND_DISPLAY")
26+
res = Pin("RST_DISPLAY")
27+
cs = Pin("CS_DISPLAY")
28+
29+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
30+
31+
data = bytearray(
32+
[
33+
0x00,
34+
0x00,
35+
0x0F,
36+
0xFF,
37+
0xFF,
38+
0x00,
39+
0x00,
40+
0x00,
41+
0x00,
42+
0x0F,
43+
0xF0,
44+
0x00,
45+
0x00,
46+
0xFF,
47+
0x00,
48+
0x00,
49+
0x00,
50+
0xF0,
51+
0x00,
52+
0x00,
53+
0x00,
54+
0x00,
55+
0xF0,
56+
0x00,
57+
0x0F,
58+
0x00,
59+
0x00,
60+
0x00,
61+
0x00,
62+
0x00,
63+
0x0F,
64+
0x00,
65+
0x0F,
66+
0x00,
67+
0x00,
68+
0x00,
69+
0x00,
70+
0x00,
71+
0x0F,
72+
0x00,
73+
0xFF,
74+
0xFF,
75+
0xFF,
76+
0xFF,
77+
0xFF,
78+
0xFF,
79+
0xFF,
80+
0xF0,
81+
0xF0,
82+
0xF0,
83+
0x0F,
84+
0xFF,
85+
0xF0,
86+
0x0F,
87+
0xF0,
88+
0xF0,
89+
0xF0,
90+
0xF0,
91+
0xFF,
92+
0xF0,
93+
0xF0,
94+
0xFF,
95+
0xF0,
96+
0xF0,
97+
0xF0,
98+
0x0F,
99+
0xFF,
100+
0x00,
101+
0x0F,
102+
0xFF,
103+
0x00,
104+
0xF0,
105+
0xF0,
106+
0x00,
107+
0x00,
108+
0x00,
109+
0x00,
110+
0x00,
111+
0x00,
112+
0xF0,
113+
0x0F,
114+
0x00,
115+
0x00,
116+
0x00,
117+
0x00,
118+
0xF0,
119+
0x0F,
120+
0x00,
121+
0x0F,
122+
0x00,
123+
0x00,
124+
0xFF,
125+
0xFF,
126+
0x00,
127+
0x0F,
128+
0x00,
129+
0x00,
130+
0xF0,
131+
0x00,
132+
0x00,
133+
0x00,
134+
0x00,
135+
0xF0,
136+
0x00,
137+
0x00,
138+
0x0F,
139+
0xF0,
140+
0x00,
141+
0x00,
142+
0xFF,
143+
0x00,
144+
0x00,
145+
0x00,
146+
0x00,
147+
0x0F,
148+
0xFF,
149+
0xFF,
150+
0x00,
151+
0x00,
152+
0x00,
153+
]
154+
)
155+
156+
# remap so your data buffer wraps at the desired segment/pixel
157+
# remapping does not modify the existing ram, instead gives you a window to supply new data
158+
display.write_cmd(0x15) # SET_COL_ADDR
159+
display.write_cmd(0x00) # start pos = 0
160+
display.write_cmd(0x0F) # start pos + half bitmap width (each byte is 2px wide) = 15
161+
display.write_cmd(0x75) # SET_ROW_ADDR
162+
display.write_cmd(0x00) # start pos = 0
163+
display.write_cmd(0x1F) # start + bitmap height = 15
164+
display.write_data(data)
165+
166+
167+
def bitmap(data, x, y, w, h):
168+
display.write_cmd(0x15) # SET_COL_ADDR
169+
display.write_cmd(0x08 + (x // 2))
170+
display.write_cmd(0x08 + (x // 2) + (w // 2))
171+
display.write_cmd(0x75) # SET_ROW_ADDR
172+
display.write_cmd(0x00 + y)
173+
display.write_cmd(y + h)
174+
display.write_data(data)
175+
176+
177+
# draw many smileys
178+
for y in range(8):
179+
for x in range(8):
180+
bitmap(data, x * 16, y * 16, 15, 15)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import ssd1327
2+
from time import sleep
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
13+
# from top left
14+
display.fill(0)
15+
x1 = 0
16+
y1 = 0
17+
y2 = display.height - 1
18+
for x2 in range(0, display.width + 1, 8):
19+
display.framebuf.line(x1, y1, x2, y2, 15)
20+
display.show()
21+
x2 = display.width - 1
22+
for y2 in range(0, display.height + 1, 8):
23+
display.framebuf.line(x1, y1, x2, y2, 15)
24+
display.show()
25+
sleep(1)
26+
27+
# from top right
28+
display.fill(0)
29+
x1 = display.width - 1
30+
y1 = 0
31+
y2 = display.height - 1
32+
for x2 in range(0, display.width + 1, 8):
33+
display.framebuf.line(x1, y1, x2, y2, 15)
34+
display.show()
35+
x2 = 0
36+
for y2 in range(0, display.height + 1, 8):
37+
display.framebuf.line(x1, y1, x2, y2, 15)
38+
display.show()
39+
sleep(1)
40+
41+
# from bottom left
42+
display.fill(0)
43+
x1 = 0
44+
y1 = display.height - 1
45+
y2 = 0
46+
for x2 in range(0, display.width + 1, 8):
47+
display.framebuf.line(x1, y1, x2, y2, 15)
48+
display.show()
49+
x2 = display.width - 1
50+
for y2 in range(0, display.height + 1, 8):
51+
display.framebuf.line(x1, y1, x2, y2, 15)
52+
display.show()
53+
sleep(1)
54+
55+
# from bottom right
56+
display.fill(0)
57+
x1 = display.width - 1
58+
y1 = display.height - 1
59+
y2 = 0
60+
for x2 in range(0, display.width + 1, 8):
61+
display.framebuf.line(x1, y1, x2, y2, 15)
62+
display.show()
63+
x2 = 0
64+
for y2 in range(0, display.height + 1, 8):
65+
display.framebuf.line(x1, y1, x2, y2, 15)
66+
display.show()
67+
sleep(1)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import ssd1327
2+
from time import sleep
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
13+
# corner pixels
14+
display.fill(0)
15+
maxw = display.width - 1
16+
maxh = display.height - 1
17+
display.pixel(0, 0, 15) # TL
18+
display.pixel(0, maxh, 15) # TR
19+
display.pixel(maxw, maxh, 15) # BR
20+
display.pixel(maxw, 0, 15) # BL
21+
display.show()
22+
sleep(1)
23+
24+
25+
# diagonal line pixel by pixel (the slow way)
26+
display.fill(0)
27+
w = display.width
28+
for i in range(w):
29+
display.pixel(i, i, 15)
30+
display.pixel(w - i, i, 15)
31+
display.show()
32+
sleep(1)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ssd1327
2+
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
13+
# rects using framebuf
14+
display.fill(0)
15+
for i in range(15):
16+
j = 8 * i
17+
display.framebuf.fill_rect(j, j, 8, 8, i)
18+
display.framebuf.rect(120 - (j), j, 8, 8, i)
19+
display.show()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ssd1327
2+
from time import sleep
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
13+
# scroll the framebuf down 16px
14+
# note: does not wrap around
15+
display.fill(0)
16+
for i in range(10):
17+
display.text("line {}".format(i), 40, i * 8, 15)
18+
display.show()
19+
sleep(1)
20+
21+
for i in range(2):
22+
display.scroll(0, 16) # framebuf.scroll
23+
display.show()
24+
sleep(1)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import ssd1327
2+
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
13+
# greyscale ascii
14+
display.fill(0)
15+
for i in range(32, 128):
16+
j = i - 32
17+
x = (j % 16) << 3
18+
y = (j // 16) << 3
19+
display.text(chr(i), x, y + 40, 1 + (i % 15))
20+
display.show()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ssd1327
2+
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
13+
display.text("Hello World !", 17, 60, 255)
14+
display.show()

lib/ssd1327/examples/illusion.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ssd1327
2+
3+
from machine import SPI, Pin
4+
5+
# Setup display on SPI bus
6+
spi = SPI(1)
7+
dc = Pin("DATA_COMMAND_DISPLAY")
8+
res = Pin("RST_DISPLAY")
9+
cs = Pin("CS_DISPLAY")
10+
11+
display = ssd1327.WS_OLED_128X128_SPI(spi, dc, res, cs)
12+
# optical illusion - are the lines crooked?
13+
display.fill(15)
14+
sq = 12 # square size
15+
seq = 100 # this magic number gives repititions of sequence 0,1,2,1... repeat
16+
for y in range(0, display.height, sq + 1):
17+
offset = round(((seq & 3) / 3) * sq)
18+
seq >>= 2
19+
if seq == 0:
20+
seq = 100
21+
for x in range(0, display.width, sq * 2):
22+
display.framebuf.fill_rect(x + offset, y, sq, sq, 0)
23+
display.framebuf.hline(0, y + sq, display.width, 6)
24+
display.show()

0 commit comments

Comments
 (0)