CircuitPython_Projects/E_Ink_Test/code.py

89 lines
2.0 KiB
Python

import time
import board
import displayio
#import fourwire
import adafruit_ssd1680
import busio
import terminalio
from adafruit_display_text import label
BLACK = 0x000000
WHITE = 0xFFFFFF
RED = 0xFF0000
FOREGROUND_COLOR = BLACK
BACKGROUND_COLOR = WHITE
# Create the display object - the third color is red (0xff0000)
DISPLAY_WIDTH = 296
DISPLAY_HEIGHT = 127
# For 8.x.x and 9.x.x. When 8.x.x is discontinued as a stable release, change this.
try:
from fourwire import FourWire
except ImportError:
from displayio import FourWire
displayio.release_displays()
# Pin order defined based on WeAct Header order
edp_busy = board.IO0
epd_reset = board.IO1
epd_dc = board.IO2
epd_cs = board.IO3
edp_clk = board.IO4
edp_mosi = board.IO5
#edp_miso =
spi = busio.SPI(clock=edp_clk, MOSI=edp_mosi)
display_bus = FourWire(
spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
)
time.sleep(1)
display = adafruit_ssd1680.SSD1680(
display_bus,
colstart=1,
width=DISPLAY_WIDTH,
height=DISPLAY_HEIGHT,
busy_pin=edp_busy,
highlight_color=FOREGROUND_COLOR,
rotation=270,
)
# Create a display group for our screen objects
g = displayio.Group()
# Set a background
background_bitmap = displayio.Bitmap(DISPLAY_WIDTH, DISPLAY_HEIGHT, 1)
# Map colors in a palette
palette = displayio.Palette(1)
palette[0] = BACKGROUND_COLOR
# Create a Tilegrid with the background and put in the displayio group
t = displayio.TileGrid(background_bitmap, pixel_shader=palette)
g.append(t)
# Draw simple text using the built-in font into a displayio group
text_group = displayio.Group(scale=3, x=20, y=80)
text = "Hello World2!"
text_area = label.Label(terminalio.FONT, text=text, color=FOREGROUND_COLOR)
text_group.append(text_area) # Add this text to the text group
g.append(text_group)
# Place the display group on the screen
display.root_group = g
# Refresh the display to have everything show on the display
# NOTE: Do not refresh eInk displays more often than 180 seconds!
display.refresh()
time.sleep(120)
while True:
pass