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"""
5This test will initialize the display using displayio and draw a solid white
6background, a smaller black rectangle, and some white text.
7"""
8
9import board
10import displayio
11import terminalio
12from adafruit_display_text import label
13import adafruit_ssd1325
14
15# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16try:
17 from fourwire import FourWire
18except ImportError:
19 from displayio import FourWire
20
21# Use for I2C
22# try:
23# from i2cdisplaybus import I2CDisplayBus
24# except ImportError:
25# from displayio import I2CDisplayBus
26
27displayio.release_displays()
28
29# Use for SPI
30spi = board.SPI()
31oled_cs = board.D5
32oled_dc = board.D6
33display_bus = FourWire(
34 spi, command=oled_dc, chip_select=oled_cs, baudrate=1000000, reset=board.D9
35)
36
37# Use for I2C
38# i2c = board.I2C() # uses board.SCL and board.SDA
39# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
40# display_bus = I2CDisplayBus(i2c, device_address=0x3c)
41
42WIDTH = 128
43HEIGHT = 64
44BORDER = 8
45FONTSCALE = 1
46
47display = adafruit_ssd1325.SSD1325(display_bus, width=WIDTH, height=HEIGHT)
48
49# Make the display context
50splash = displayio.Group()
51display.root_group = splash
52
53color_bitmap = displayio.Bitmap(display.width, display.height, 1)
54color_palette = displayio.Palette(1)
55color_palette[0] = 0xFFFFFF # White
56
57bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
58splash.append(bg_sprite)
59
60# Draw a smaller inner rectangle
61inner_bitmap = displayio.Bitmap(
62 display.width - BORDER * 2, display.height - BORDER * 2, 1
63)
64inner_palette = displayio.Palette(1)
65inner_palette[0] = 0x000000 # Black
66inner_sprite = displayio.TileGrid(
67 inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
68)
69splash.append(inner_sprite)
70
71# Draw a label
72text = "Hello World!"
73text_area = label.Label(terminalio.FONT, text=text, color=0x888888)
74text_width = text_area.bounding_box[2] * FONTSCALE
75text_group = displayio.Group(
76 scale=FONTSCALE,
77 x=display.width // 2 - text_width // 2,
78 y=display.height // 2,
79)
80text_group.append(text_area) # Subgroup for text scaling
81splash.append(text_group)
82
83while True:
84 pass