|
1
|
1 MicroPython OLED
|
|
|
2 ================
|
|
|
3
|
|
|
4 This is a collection of drivers for handling monochrome OLED displays. There
|
|
|
5 are many versions of such drivers, and there is even a driver for the SSD1306
|
|
|
6 included in MicroPython's repository, but I decided to make my own, because I
|
|
|
7 needed something a little bit more optimized.
|
|
|
8
|
|
|
9 To conserve memory, each version of each driver is in a separate self-contained
|
|
|
10 file that you need to copy to your board. There is no inheritance and no
|
|
|
11 multiple imports -- I'm only using the build-in `framebuf` module. Of course
|
|
|
12 that means there is some repetition between the different drivers, but that's a
|
|
|
13 price I'm willing to pay. There are also no constants that would need to be
|
|
|
14 converted to bytes before sending -- I'm using raw byte strings everywhere.
|
|
|
15
|
|
|
16 To make it fast, I'm calling MicroPython's built-in functions directly, without
|
|
|
17 wrapping them into convenience functions. I'm also only allocating any memory
|
|
|
18 once, at the beginning, and then re-using those buffers for everything.
|
|
|
19
|
|
|
20 Finally, I have added some convenience functions for flipping and mirroring the
|
|
|
21 display, reversing its colors, hardware scrolling, setting contrast and
|
|
|
22 switching it off and on.
|
|
|
23
|
|
|
24 There are no drawing functions on the display object itself, they are available
|
|
|
25 on the frame buffer object, available as the `fb` attribute.
|
|
|
26
|
0
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
27 Examples
|
|
1
|
28 ========
|
0
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
29
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
30 SH1106 I2C Example
|
|
1
|
31 ------------------
|
0
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
32
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
33 ```python
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
34 import sh1106_i2c
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
35 from machine import I2C, Pin
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
36
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
37 i2c = I2C(-1, sda=Pin(4), scl=Pin(5), freq=400000)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
38 d = sh1106_i2c.Display(i2c)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
39 d.fb.fill(1)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
40 d.fb.pixel(64, 32, 0)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
41 d.update()
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
42 ```
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
43
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
44 SH1106 SPI Example
|
|
1
|
45 ------------------
|
0
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
46
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
47 ```python
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
48 import sh1106_spi
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
49 from machine import SPI, Pin
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
50
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
51 spi = SPI(1, baudrate=20000000)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
52 dc = Pin(12, Pin.OUT)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
53 cs = Pin(15, Pin.OUT)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
54 d = sh1106_spi.Display(spi, dc, cs)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
55 d.fb.fill(1)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
56 d.fb.pixel(64, 32, 0)
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
57 d.update()
|
Radomir Dopieralski <sheep-devel@sheep.art.pl>
parents:
diff
changeset
|
58 ```
|