Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2# SPDX-FileCopyrightText: Copyright (c) 2023 Melissa LeBlanc-Williams for Adafruit Industries
3#
4# SPDX-License-Identifier: Unlicense
5"""
6 Simple test script for 2.7" 264x176 Tri-Color display
7 Supported products:
8 * `Adafruit 2.7" Tri-Color eInk / ePaper Display
9 with SRAM <https://www.adafruit.com/product/4098>`_
10
11 This program only requires the adafruit_ek79686 library in /lib
12 for CircuitPython 5.0 and above which has displayio support.
13"""
14
15import time
16import board
17import displayio
18
19# Compatibility with both CircuitPython 8.x.x and 9.x.x.
20# Remove after 8.x.x is no longer a supported release.
21try:
22 from fourwire import FourWire
23except ImportError:
24 from displayio import FourWire
25
26import adafruit_ek79686
27
28# Used to ensure the display is free in CircuitPython
29displayio.release_displays()
30
31# Define the pins needed for display use on the Metro
32spi = board.SPI()
33epd_cs = board.D10
34epd_dc = board.D9
35epd_reset = board.D5
36epd_busy = board.D6
37
38# Create the displayio connection to the display pins
39display_bus = FourWire(
40 spi, command=epd_dc, chip_select=epd_cs, reset=epd_reset, baudrate=1000000
41)
42time.sleep(1) # Wait a bit
43
44# Create the display object - the third color is red (0xff0000)
45display = adafruit_ek79686.EK79686(
46 display_bus,
47 width=264,
48 height=176,
49 busy_pin=epd_busy,
50 highlight_color=0xFF0000,
51 rotation=90,
52)
53
54# Create a display group for our screen objects
55g = displayio.Group()
56
57
58# Display a ruler graphic from the root directory of the CIRCUITPY drive
59with open("/display-ruler.bmp", "rb") as f:
60 pic = displayio.OnDiskBitmap(f)
61 # Create a Tilegrid with the bitmap and put in the displayio group
62 # CircuitPython 6 & 7 compatible
63 t = displayio.TileGrid(
64 pic, pixel_shader=getattr(pic, "pixel_shader", displayio.ColorConverter())
65 )
66 # CircuitPython 7 compatible only
67 # t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
68 g.append(t)
69
70 # Place the display group on the screen (does not refresh)
71 display.root_group = g
72
73 # Show the image on the display
74 display.refresh()
75
76 print("refreshed")
77
78 # Do Not refresh the screen more often than every 180 seconds
79 # for eInk displays! Rapid refreshes will damage the panel.
80 time.sleep(180)