Skip to content

Commit b6d9f85

Browse files
authored
Merge pull request #8 from makermelissa/main
Added tri-color support
2 parents a64fad6 + e7fc529 commit b6d9f85

File tree

4 files changed

+98
-6
lines changed

4 files changed

+98
-6
lines changed

adafruit_uc8151d.py

100644100755
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
**Hardware:**
1818
1919
* `Adafruit Flexible 2.9" Black and White <https://www.adafruit.com/product/4262>`_
20+
* `Adafruit Tri-Color 2.9" <https://www.adafruit.com/product/1028>`_
2021
2122
**Software and Dependencies:**
2223
@@ -33,11 +34,18 @@
3334
_START_SEQUENCE = (
3435
# b"\x01\x05\x03\x00\x2b\x2b\x09" # power setting
3536
# b"\x06\x03\x17\x17\x17" # booster soft start
36-
b"\x04\x80\xc8" # power on and wait 10 ms
37+
b"\x04\x80\xc8" # power on and wait 200 ms
3738
b"\x00\x01\x1f" # panel setting. Further filled in below.
3839
b"\x50\x01\x97" # CDI setting
3940
)
4041

42+
_COLOR_START_SEQUENCE = (
43+
b"\x04\x80\xc8" # power on and wait 200 ms
44+
b"\x00\x02\x0f\x89" # panel setting. Further filled in below.
45+
b"\x61\x03\x80\x01\x28" # Set Display Resolution
46+
b"\x50\x01\x77" # CDI setting
47+
)
48+
4149
_GRAYSCALE_START_SEQUENCE = (
4250
b"\x04\x80\xc8" # Power on
4351
b"\x00\x01\xbf" # Panel setting
@@ -89,7 +97,6 @@
8997
b"\x00\x00\x00\x00\x00\x00"
9098
)
9199

92-
93100
_STOP_SEQUENCE = b"\x50\x01\xf7" b"\x07\x01\xA5" # CDI setting # Deep Sleep
94101
# pylint: disable=too-few-public-methods
95102
class UC8151D(displayio.EPaperDisplay):
@@ -109,8 +116,16 @@ class UC8151D(displayio.EPaperDisplay):
109116
"""
110117

111118
def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
119+
color_bits_inverted = kwargs.pop("color_bits_inverted", False)
120+
write_color_ram_command = 0x10
121+
write_black_ram_command = 0x13
112122
if kwargs.get("grayscale", False):
113123
start_sequence = bytearray(_GRAYSCALE_START_SEQUENCE)
124+
elif kwargs.get("highlight_color", False):
125+
write_color_ram_command = 0x13
126+
write_black_ram_command = 0x10
127+
color_bits_inverted = kwargs.pop("color_bits_inverted", True)
128+
start_sequence = bytearray(_COLOR_START_SEQUENCE)
114129
else:
115130
start_sequence = bytearray(_START_SEQUENCE)
116131
width = kwargs["width"]
@@ -126,7 +141,8 @@ def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
126141
ram_width=128,
127142
ram_height=296,
128143
busy_state=False,
129-
write_black_ram_command=0x13,
130-
write_color_ram_command=0x10,
144+
write_black_ram_command=write_black_ram_command,
145+
write_color_ram_command=write_color_ram_command,
146+
color_bits_inverted=color_bits_inverted,
131147
refresh_display_command=0x12,
132148
)

docs/examples.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
Simple test
22
------------
33

4-
Ensure your device works with this simple test.
4+
Ensure your device works with this simple test. This simple test is for the 2.9" Flexible Monochrome display.
55

66
.. literalinclude:: ../examples/uc8151d_simpletest.py
77
:caption: examples/uc8151d_simpletest.py
88
:linenos:
9+
10+
Device Specific Examples
11+
------------------------
12+
13+
.. literalinclude:: ../examples/uc8151d_1.54_grayscale.py
14+
:caption: examples/uc8151d_1.54_grayscale.py
15+
:linenos:
16+
17+
.. literalinclude:: ../examples/uc8151d_2.9_color.py
18+
:caption: examples/uc8151d_2.9_color.py
19+
:linenos:

examples/uc8151d_grayscale_test.py renamed to examples/uc8151d_1.54_grayscale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Supported products:
88
* 1.54" Grayscale Display (GDEW0154T8D)
9-
"""
9+
"""
1010
# pylint: disable=no-member
1111

1212
import time

examples/uc8151d_2.9_color.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""Simple test script for Adafruit 2.9" 296x128 tri-color display
5+
Supported products:
6+
* Adafruit 2.9" Tri-Color Display Breakout
7+
* https://www.adafruit.com/product/1028
8+
"""
9+
10+
import time
11+
import board
12+
import displayio
13+
import adafruit_uc8151d
14+
15+
# Used to ensure the display is free in CircuitPython
16+
displayio.release_displays()
17+
18+
# Define the pins needed for display use
19+
# This pinout is for a Feather M4 and may be different for other boards
20+
spi = board.SPI() # Uses SCK and MOSI
21+
epd_cs = board.D9
22+
epd_dc = board.D10
23+
epd_reset = board.D5
24+
epd_busy = board.D6
25+
26+
# Create the displayio connection to the display pins
27+
display_bus = displayio.FourWire(
28+
spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
29+
)
30+
time.sleep(1) # Wait a bit
31+
32+
# Create the display object - the third color is red (0xff0000)
33+
display = adafruit_uc8151d.UC8151D(
34+
display_bus,
35+
width=296,
36+
height=128,
37+
rotation=270,
38+
busy_pin=epd_busy,
39+
highlight_color=0xFF0000,
40+
)
41+
42+
# Create a display group for our screen objects
43+
g = displayio.Group()
44+
45+
# Display a ruler graphic from the root directory of the CIRCUITPY drive
46+
with open("/display-ruler.bmp", "rb") as f:
47+
pic = displayio.OnDiskBitmap(f)
48+
# Create a Tilegrid with the bitmap and put in the displayio group
49+
# CircuitPython 6 & 7 compatible
50+
t = displayio.TileGrid(
51+
pic, pixel_shader=getattr(pic, "pixel_shader", displayio.ColorConverter())
52+
)
53+
# CircuitPython 7 compatible only
54+
# t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
55+
g.append(t)
56+
57+
# Place the display group on the screen
58+
display.show(g)
59+
60+
# Refresh the display to have it actually show the image
61+
# NOTE: Do not refresh eInk displays sooner than 180 seconds
62+
display.refresh()
63+
print("refreshed")
64+
65+
time.sleep(180)

0 commit comments

Comments
 (0)