Skip to content

Commit f403d91

Browse files
authored
Merge pull request #55 from makermelissa/main
Added UC8151D support
2 parents befef95 + d738c77 commit f403d91

File tree

6 files changed

+196
-12
lines changed

6 files changed

+196
-12
lines changed

adafruit_epd/uc8151d.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`adafruit_epd.uc8151d` - Adafruit UC8151D - ePaper display driver
7+
====================================================================================
8+
CircuitPython driver for Adafruit UC8151D display breakouts
9+
* Author(s): Dean Miller
10+
"""
11+
12+
import time
13+
from micropython import const
14+
import adafruit_framebuf
15+
from adafruit_epd.epd import Adafruit_EPD
16+
17+
__version__ = "0.0.0-auto.0"
18+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_EPD.git"
19+
20+
_UC8151D_PANEL_SETTING = const(0x00)
21+
_UC8151D_POWER_SETTING = const(0x01)
22+
_UC8151D_POWER_OFF = const(0x02)
23+
_UC8151D_POWER_OFF_SEQUENCE = const(0x03)
24+
_UC8151D_POWER_ON = const(0x04)
25+
_UC8151D_POWER_ON_MEASURE = const(0x05)
26+
_UC8151D_BOOSTER_SOFT_START = const(0x06)
27+
_UC8151D_DEEP_SLEEP = const(0x07)
28+
_UC8151D_DTM1 = const(0x10)
29+
_UC8151D_DATA_STOP = const(0x11)
30+
_UC8151D_DISPLAY_REFRESH = const(0x12)
31+
_UC8151D_DTM2 = const(0x13)
32+
_UC8151D_AUTO = const(0x17)
33+
_UC8151D_LUTOPT = const(0x2A)
34+
_UC8151D_PLL = const(0x30)
35+
_UC8151D_TSC = const(0x40)
36+
_UC8151D_TSE = const(0x41)
37+
_UC8151D_TSW = const(0x42)
38+
_UC8151D_TSR = const(0x43)
39+
_UC8151D_PBC = const(0x44)
40+
_UC8151D_CDI = const(0x50)
41+
_UC8151D_LPD = const(0x51)
42+
_UC8151D_TRES = const(0x65)
43+
_UC8151D_GSST = const(0x70)
44+
_UC8151D_REV = const(0x70)
45+
_UC8151D_FLG = const(0x71)
46+
_UC8151D_AMV = const(0x80)
47+
_UC8151D_VV = const(0x81)
48+
_UC8151D_VCM_DC_SETTING = const(0x82)
49+
_UC8151D_PTL = const(0x90)
50+
_UC8151D_PTIN = const(0x91)
51+
_UC8151D_PTOUT = const(0x92)
52+
_UC8151D_PGM = const(0xA0)
53+
_UC8151D_APG = const(0xA1)
54+
_UC8151D_ROTP = const(0xA2)
55+
_UC8151D_CCSET = const(0xE0)
56+
_UC8151D_PWS = const(0xE3)
57+
_UC8151D_LVSEL = const(0xE4)
58+
_UC8151D_TSSET = const(0xE5)
59+
60+
61+
class Adafruit_UC8151D(Adafruit_EPD):
62+
"""driver class for Adafruit UC8151D ePaper display breakouts"""
63+
64+
# pylint: disable=too-many-arguments
65+
def __init__(
66+
self, width, height, spi, *, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
67+
):
68+
super().__init__(
69+
width, height, spi, cs_pin, dc_pin, sramcs_pin, rst_pin, busy_pin
70+
)
71+
72+
self._buffer1_size = int(width * height / 8)
73+
self._buffer2_size = int(width * height / 8)
74+
75+
if sramcs_pin:
76+
self._buffer1 = self.sram.get_view(0)
77+
self._buffer2 = self.sram.get_view(self._buffer1_size)
78+
else:
79+
self._buffer1 = bytearray((width * height) // 8)
80+
self._buffer2 = bytearray((width * height) // 8)
81+
# since we have *two* framebuffers - one for red and one for black
82+
# we dont subclass but manage manually
83+
self._framebuf1 = adafruit_framebuf.FrameBuffer(
84+
self._buffer1, width, height, buf_format=adafruit_framebuf.MHMSB
85+
)
86+
self._framebuf2 = adafruit_framebuf.FrameBuffer(
87+
self._buffer2, width, height, buf_format=adafruit_framebuf.MHMSB
88+
)
89+
self.set_black_buffer(0, True)
90+
self.set_color_buffer(1, True)
91+
# pylint: enable=too-many-arguments
92+
93+
def begin(self, reset=True):
94+
"""Begin communication with the display and set basic settings"""
95+
if reset:
96+
self.hardware_reset()
97+
self.power_down()
98+
99+
def busy_wait(self):
100+
"""Wait for display to be done with current task, either by polling the
101+
busy pin, or pausing"""
102+
if self._busy:
103+
while not self._busy.value:
104+
time.sleep(0.01)
105+
else:
106+
time.sleep(0.5)
107+
108+
def power_up(self):
109+
"""Power up the display in preparation for writing RAM and updating"""
110+
self.hardware_reset()
111+
self.busy_wait()
112+
113+
self.command(_UC8151D_POWER_ON)
114+
115+
self.busy_wait()
116+
time.sleep(0.01)
117+
118+
self.command(_UC8151D_PANEL_SETTING, bytearray([0x1F]))
119+
self.command(_UC8151D_CDI, bytearray([0x97]))
120+
time.sleep(0.05)
121+
122+
def power_down(self):
123+
"""Power down the display - required when not actively displaying!"""
124+
self.command(_UC8151D_CDI, bytearray([0xF7]))
125+
self.command(_UC8151D_POWER_OFF)
126+
self.busy_wait()
127+
self.command(_UC8151D_DEEP_SLEEP, bytearray([0xA5]))
128+
129+
def update(self):
130+
"""Update the display from internal memory"""
131+
self.command(_UC8151D_DISPLAY_REFRESH)
132+
time.sleep(0.1)
133+
self.busy_wait()
134+
if not self._busy:
135+
time.sleep(15) # wait 15 seconds
136+
137+
def write_ram(self, index):
138+
"""Send the one byte command for starting the RAM write process. Returns
139+
the byte read at the same time over SPI. index is the RAM buffer, can be
140+
0 or 1 for tri-color displays."""
141+
if index == 0:
142+
return self.command(_UC8151D_DTM1, end=False)
143+
if index == 1:
144+
return self.command(_UC8151D_DTM2, end=False)
145+
raise RuntimeError("RAM index must be 0 or 1")
146+
147+
def set_ram_address(self, x, y): # pylint: disable=unused-argument, no-self-use
148+
"""Set the RAM address location, not used on this chipset but required by
149+
the superclass"""
150+
return # on this chip it does nothing

examples/epd_bitmap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import
1313
from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import
1414
from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import
15+
from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import
1516

1617

1718
# create the spi device and pins we will need
@@ -30,6 +31,7 @@
3031
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
3132
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
3233
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
34+
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
3335
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
3436
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
3537
display = Adafruit_IL0373(
@@ -43,10 +45,14 @@
4345
busy_pin=busy,
4446
)
4547

46-
# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines!
48+
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
4749
# display.set_black_buffer(1, False)
4850
# display.set_color_buffer(1, False)
4951

52+
# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines!
53+
# display.set_black_buffer(1, True)
54+
# display.set_color_buffer(1, True)
55+
5056
display.rotation = 0
5157

5258
FILENAME = "blinka.bmp"

examples/epd_blinka.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from adafruit_epd.ssd1675b import Adafruit_SSD1675B # pylint: disable=unused-import
1818
from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import
1919
from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import
20+
from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import
2021

2122
# create the spi device and pins we will need
2223
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
@@ -32,15 +33,16 @@
3233

3334
# give them all to our driver
3435
print("Creating display")
35-
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
36+
# display = Adafruit_SSD1608(200, 200, # 1.54" HD mono display
3637
# display = Adafruit_SSD1680(122, 250, # 2.13" HD Tri-color display
37-
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
38-
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
39-
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
40-
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
41-
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
42-
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
43-
# display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display
38+
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
39+
# display = Adafruit_SSD1675(122, 250, # 2.13" HD mono display
40+
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
41+
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
42+
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
43+
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
44+
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
45+
# display = Adafruit_IL0373(104, 212, # 2.13" Tri-color display
4446
display = Adafruit_SSD1675B(
4547
122,
4648
250,
@@ -52,6 +54,14 @@
5254
busy_pin=busy,
5355
)
5456

57+
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
58+
# display.set_black_buffer(1, False)
59+
# display.set_color_buffer(1, False)
60+
61+
# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines!
62+
# display.set_black_buffer(1, True)
63+
# display.set_color_buffer(1, True)
64+
5565
display.rotation = 3
5666
# Create blank image for drawing.
5767
# Make sure to create image with mode '1' for 1-bit color.

examples/epd_pillow_demo.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import
1818
from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import
1919
from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import
20+
from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import
2021

2122
# First define some color constants
2223
WHITE = (0xFF, 0xFF, 0xFF)
@@ -45,6 +46,7 @@
4546
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
4647
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
4748
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
49+
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
4850
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
4951
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
5052
display = Adafruit_IL0373(
@@ -58,10 +60,14 @@
5860
busy_pin=busy,
5961
)
6062

61-
# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines!
63+
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
6264
# display.set_black_buffer(1, False)
6365
# display.set_color_buffer(1, False)
6466

67+
# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines!
68+
# display.set_black_buffer(1, True)
69+
# display.set_color_buffer(1, True)
70+
6571
display.rotation = 1
6672

6773
image = Image.new("RGB", (display.width, display.height))

examples/epd_pillow_image.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import
2020
from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import
2121
from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import
22+
from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import
2223

2324

2425
# create the spi device and pins we will need
@@ -36,6 +37,7 @@
3637
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
3738
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
3839
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
40+
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
3941
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
4042
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
4143
display = Adafruit_IL0373(
@@ -49,10 +51,14 @@
4951
busy_pin=busy,
5052
)
5153

52-
# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines!
54+
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
5355
# display.set_black_buffer(1, False)
5456
# display.set_color_buffer(1, False)
5557

58+
# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines!
59+
# display.set_black_buffer(1, True)
60+
# display.set_color_buffer(1, True)
61+
5662
display.rotation = 1
5763

5864
image = Image.open("blinka.png")

examples/epd_simpletest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from adafruit_epd.ssd1675 import Adafruit_SSD1675 # pylint: disable=unused-import
1313
from adafruit_epd.ssd1680 import Adafruit_SSD1680 # pylint: disable=unused-import
1414
from adafruit_epd.ssd1681 import Adafruit_SSD1681 # pylint: disable=unused-import
15+
from adafruit_epd.uc8151d import Adafruit_UC8151D # pylint: disable=unused-import
1516

1617
# create the spi device and pins we will need
1718
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
@@ -29,6 +30,7 @@
2930
# display = Adafruit_SSD1681(200, 200, # 1.54" HD Tri-color display
3031
# display = Adafruit_IL91874(176, 264, # 2.7" Tri-color display
3132
# display = Adafruit_IL0373(152, 152, # 1.54" Tri-color display
33+
# display = Adafruit_UC8151D(128, 296, # 2.9" mono flexible display
3234
# display = Adafruit_IL0373(128, 296, # 2.9" Tri-color display
3335
# display = Adafruit_IL0398(400, 300, # 4.2" Tri-color display
3436
display = Adafruit_IL0373(
@@ -42,10 +44,14 @@
4244
busy_pin=busy,
4345
)
4446

45-
# IF YOU HAVE A FLEXIBLE DISPLAY (2.13" or 2.9") uncomment these lines!
47+
# IF YOU HAVE A 2.13" FLEXIBLE DISPLAY uncomment these lines!
4648
# display.set_black_buffer(1, False)
4749
# display.set_color_buffer(1, False)
4850

51+
# IF YOU HAVE A 2.9" FLEXIBLE DISPLAY uncomment these lines!
52+
# display.set_black_buffer(1, True)
53+
# display.set_color_buffer(1, True)
54+
4955
display.rotation = 1
5056

5157
# clear the buffer

0 commit comments

Comments
 (0)