Simple test

Ensure your device works with this simple test.

examples/hx8357_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
12from adafruit_display_text import label
13from adafruit_hx8357 import HX8357
14
15# Release any resources currently in use for the displays
16displayio.release_displays()
17
18spi = board.SPI()
19tft_cs = board.D9
20tft_dc = board.D10
21
22display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
23
24display = HX8357(display_bus, width=480, height=320)
25
26# Make the display context
27splash = displayio.Group()
28display.root_group = splash
29
30color_bitmap = displayio.Bitmap(480, 320, 1)
31color_palette = displayio.Palette(1)
32color_palette[0] = 0x00FF00  # Bright Green
33
34bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
35splash.append(bg_sprite)
36
37# Draw a smaller inner rectangle
38inner_bitmap = displayio.Bitmap(440, 280, 1)
39inner_palette = displayio.Palette(1)
40inner_palette[0] = 0xAA0088  # Purple
41inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
42splash.append(inner_sprite)
43
44# Draw a label
45text_group = displayio.Group(scale=3, x=137, y=160)
46text = "Hello World!"
47text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
48text_group.append(text_area)  # Subgroup for text scaling
49splash.append(text_group)
50
51while True:
52    pass