Simple test

Ensure your device works with this simple test.

examples/ili9341_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. All drawing is done
 7using native displayio modules.
 8
 9Pinouts are for the 2.4" TFT FeatherWing or Breakout with a Feather M4 or M0.
10"""
11import board
12import terminalio
13import displayio
14from adafruit_display_text import label
15import adafruit_ili9341
16
17# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
18try:
19    from fourwire import FourWire
20except ImportError:
21    from displayio import FourWire
22
23# Release any resources currently in use for the displays
24displayio.release_displays()
25
26spi = board.SPI()
27tft_cs = board.D9
28tft_dc = board.D10
29
30display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D6)
31display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
32
33# Make the display context
34splash = displayio.Group()
35display.root_group = splash
36
37# Draw a green background
38color_bitmap = displayio.Bitmap(320, 240, 1)
39color_palette = displayio.Palette(1)
40color_palette[0] = 0x00FF00  # Bright Green
41
42bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
43
44splash.append(bg_sprite)
45
46# Draw a smaller inner rectangle
47inner_bitmap = displayio.Bitmap(280, 200, 1)
48inner_palette = displayio.Palette(1)
49inner_palette[0] = 0xAA0088  # Purple
50inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
51splash.append(inner_sprite)
52
53# Draw a label
54text_group = displayio.Group(scale=3, x=57, y=120)
55text = "Hello World!"
56text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
57text_group.append(text_area)  # Subgroup for text scaling
58splash.append(text_group)
59
60while True:
61    pass