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# Release any resources currently in use for the displays
18displayio.release_displays()
19
20spi = board.SPI()
21tft_cs = board.D9
22tft_dc = board.D10
23
24display_bus = displayio.FourWire(
25    spi, command=tft_dc, chip_select=tft_cs, reset=board.D6
26)
27display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
28
29# Make the display context
30splash = displayio.Group()
31display.show(splash)
32
33# Draw a green background
34color_bitmap = displayio.Bitmap(320, 240, 1)
35color_palette = displayio.Palette(1)
36color_palette[0] = 0x00FF00  # Bright Green
37
38bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
39
40splash.append(bg_sprite)
41
42# Draw a smaller inner rectangle
43inner_bitmap = displayio.Bitmap(280, 200, 1)
44inner_palette = displayio.Palette(1)
45inner_palette[0] = 0xAA0088  # Purple
46inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
47splash.append(inner_sprite)
48
49# Draw a label
50text_group = displayio.Group(scale=3, x=57, y=120)
51text = "Hello World!"
52text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
53text_group.append(text_area)  # Subgroup for text scaling
54splash.append(text_group)
55
56while True:
57    pass