Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""
5 Simple test script for 2.7" 264x176 Tri-Color display shield
6 Supported products:
7 * Adafruit 2.7" Tri-Color ePaper Display Shield
8 https://www.adafruit.com/product/4229
9
10 This program only requires the adafruit_il91874 library in /lib
11 for CircuitPython 5.0 and above which has displayio support.
12"""
13
14import time
15import board
16import displayio
17
18# Compatibility with both CircuitPython 8.x.x and 9.x.x.
19# Remove after 8.x.x is no longer a supported release.
20try:
21 from fourwire import FourWire
22except ImportError:
23 # pylint: disable=ungrouped-imports
24 from displayio import FourWire
25
26import adafruit_il91874
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_il91874.IL91874(
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# Display a ruler graphic from the root directory of the CIRCUITPY drive
58with open("/display-ruler.bmp", "rb") as f:
59 pic = displayio.OnDiskBitmap(f)
60 # Create a Tilegrid with the bitmap and put in the displayio group
61 # CircuitPython 6 & 7 compatible
62 t = displayio.TileGrid(
63 pic, pixel_shader=getattr(pic, "pixel_shader", displayio.ColorConverter())
64 )
65 # CircuitPython 7 compatible only
66 # t = displayio.TileGrid(pic, pixel_shader=pic.pixel_shader)
67 g.append(t)
68
69 # Place the display group on the screen (does not refresh)
70 display.root_group = g
71
72 # Show the image on the display
73 display.refresh()
74
75 print("refreshed")
76
77 # Do Not refresh the screen more often than every 180 seconds
78 # for eInk displays! Rapid refreshes will damage the panel.
79 time.sleep(180)