Skip to content

Added tri-color support #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions adafruit_uc8151d.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
**Hardware:**

* `Adafruit Flexible 2.9" Black and White <https://www.adafruit.com/product/4262>`_
* `Adafruit Tri-Color 2.9" <https://www.adafruit.com/product/1028>`_

**Software and Dependencies:**

Expand All @@ -33,11 +34,18 @@
_START_SEQUENCE = (
# b"\x01\x05\x03\x00\x2b\x2b\x09" # power setting
# b"\x06\x03\x17\x17\x17" # booster soft start
b"\x04\x80\xc8" # power on and wait 10 ms
b"\x04\x80\xc8" # power on and wait 200 ms
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makermelissa is it OK to wait 200ms for both the b/w and the tri-color LCD?

Copy link
Collaborator Author

@makermelissa makermelissa Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been this way for quite a while. I really only updated the comment to match the actual value. The additional delay is probably because CP is a little slower than Arduino. Either way it works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the values are the same between the color and b/w displays in Arduino (10ms in that case).

b"\x00\x01\x1f" # panel setting. Further filled in below.
b"\x50\x01\x97" # CDI setting
)

_COLOR_START_SEQUENCE = (
b"\x04\x80\xc8" # power on and wait 200 ms
b"\x00\x02\x0f\x89" # panel setting. Further filled in below.
b"\x61\x03\x80\x01\x28" # Set Display Resolution
b"\x50\x01\x77" # CDI setting
)

_GRAYSCALE_START_SEQUENCE = (
b"\x04\x80\xc8" # Power on
b"\x00\x01\xbf" # Panel setting
Expand Down Expand Up @@ -89,7 +97,6 @@
b"\x00\x00\x00\x00\x00\x00"
)


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

def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
color_bits_inverted = kwargs.pop("color_bits_inverted", False)
write_color_ram_command = 0x10
write_black_ram_command = 0x13
if kwargs.get("grayscale", False):
start_sequence = bytearray(_GRAYSCALE_START_SEQUENCE)
elif kwargs.get("highlight_color", False):
write_color_ram_command = 0x13
write_black_ram_command = 0x10
color_bits_inverted = kwargs.pop("color_bits_inverted", True)
start_sequence = bytearray(_COLOR_START_SEQUENCE)
else:
start_sequence = bytearray(_START_SEQUENCE)
width = kwargs["width"]
Expand All @@ -126,7 +141,8 @@ def __init__(self, bus: displayio.FourWire, **kwargs) -> None:
ram_width=128,
ram_height=296,
busy_state=False,
write_black_ram_command=0x13,
write_color_ram_command=0x10,
write_black_ram_command=write_black_ram_command,
write_color_ram_command=write_color_ram_command,
color_bits_inverted=color_bits_inverted,
refresh_display_command=0x12,
)
13 changes: 12 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
Simple test
------------

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

.. literalinclude:: ../examples/uc8151d_simpletest.py
:caption: examples/uc8151d_simpletest.py
:linenos:

Device Specific Examples
------------------------

.. literalinclude:: ../examples/uc8151d_1.54_grayscale.py
:caption: examples/uc8151d_1.54_grayscale.py
:linenos:

.. literalinclude:: ../examples/uc8151d_2.9_color.py
:caption: examples/uc8151d_2.9_color.py
:linenos:
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Supported products:
* 1.54" Grayscale Display (GDEW0154T8D)
"""
"""
# pylint: disable=no-member

import time
Expand Down
65 changes: 65 additions & 0 deletions examples/uc8151d_2.9_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""Simple test script for Adafruit 2.9" 296x128 tri-color display
Supported products:
* Adafruit 2.9" Tri-Color Display Breakout
* https://www.adafruit.com/product/1028
"""

import time
import board
import displayio
import adafruit_uc8151d

# Used to ensure the display is free in CircuitPython
displayio.release_displays()

# Define the pins needed for display use
# This pinout is for a Feather M4 and may be different for other boards
spi = board.SPI() # Uses SCK and MOSI
epd_cs = board.D9
epd_dc = board.D10
epd_reset = board.D5
epd_busy = board.D6

# Create the displayio connection to the display pins
display_bus = displayio.FourWire(
spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
)
time.sleep(1) # Wait a bit

# Create the display object - the third color is red (0xff0000)
display = adafruit_uc8151d.UC8151D(
display_bus,
width=296,
height=128,
rotation=270,
busy_pin=epd_busy,
highlight_color=0xFF0000,
)

# Create a display group for our screen objects
g = displayio.Group()

# Display a ruler graphic from the root directory of the CIRCUITPY drive
with open("/display-ruler.bmp", "rb") as f:
pic = displayio.OnDiskBitmap(f)
# Create a Tilegrid with the bitmap and put in the displayio group
# CircuitPython 6 & 7 compatible
t = displayio.TileGrid(
pic, pixel_shader=getattr(pic, "pixel_shader", displayio.ColorConverter())
)
# CircuitPython 7 compatible only
# t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
g.append(t)

# Place the display group on the screen
display.show(g)

# Refresh the display to have it actually show the image
# NOTE: Do not refresh eInk displays sooner than 180 seconds
display.refresh()
print("refreshed")

time.sleep(180)