Simple test

Ensure your device works with this simple test.

examples/ssd1331_simpletest.py
 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 green
 6background, a smaller purple rectangle, and some yellow text.
 7"""
 8
 9import board
10import terminalio
11import displayio
12
13# Starting in CircuitPython 9.x fourwire will be a seperate internal library
14# rather than a component of the displayio library
15try:
16    from fourwire import FourWire
17except ImportError:
18    from displayio import FourWire
19from adafruit_display_text import label
20from adafruit_ssd1331 import SSD1331
21
22# Release any resources currently in use for the displays
23displayio.release_displays()
24
25spi = board.SPI()
26tft_cs = board.D5
27tft_dc = board.D6
28
29display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
30
31display = SSD1331(display_bus, width=96, height=64)
32
33# Make the display context
34splash = displayio.Group()
35display.root_group = splash
36
37color_bitmap = displayio.Bitmap(96, 64, 1)
38color_palette = displayio.Palette(1)
39color_palette[0] = 0x00FF00  # Bright Green
40
41bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
42splash.append(bg_sprite)
43
44# Draw a smaller inner rectangle
45inner_bitmap = displayio.Bitmap(86, 54, 1)
46inner_palette = displayio.Palette(1)
47inner_palette[0] = 0xAA0088  # Purple
48inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
49splash.append(inner_sprite)
50
51# Draw a label
52text = "Hello World!"
53text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=12, y=32)
54splash.append(text_area)
55
56while True:
57    pass