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# Quick test of TFT FeatherWing (ST7789) with Feather M0 or M4
5# This will work even on a device running displayio
6# Will fill the TFT black and put a red pixel in the center, wait 2 seconds,
7# then fill the screen blue (with no pixel), wait 2 seconds, and repeat.
8import time
9import random
10import digitalio
11import board
12
13from adafruit_rgb_display.rgb import color565
14from adafruit_rgb_display import st7789
15
16# Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4):
17cs_pin = digitalio.DigitalInOut(board.D5)
18dc_pin = digitalio.DigitalInOut(board.D6)
19reset_pin = digitalio.DigitalInOut(board.D9)
20
21# Config for display baudrate (default max is 24mhz):
22BAUDRATE = 24000000
23
24# Setup SPI bus using hardware SPI:
25spi = board.SPI()
26
27# Create the ST7789 display:
28display = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)
29
30# Main loop:
31while True:
32 # Fill the screen red, green, blue, then black:
33 for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
34 display.fill(color565(color))
35 # Clear the display
36 display.fill(0)
37 # Draw a red pixel in the center.
38 display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0))
39 # Pause 2 seconds.
40 time.sleep(2)
41 # Clear the screen a random color
42 display.fill(
43 color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
44 )
45 # Pause 2 seconds.
46 time.sleep(2)
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Quick test of TFT FeatherWing (ILI9341) with Feather M0 or M4
5# Will fill the TFT black and put a red pixel in the center, wait 2 seconds,
6# then fill the screen blue (with no pixel), wait 2 seconds, and repeat.
7import time
8import random
9import busio
10import digitalio
11import board
12
13from adafruit_rgb_display.rgb import color565
14from adafruit_rgb_display import ili9341
15
16
17# Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4):
18cs_pin = digitalio.DigitalInOut(board.D9)
19dc_pin = digitalio.DigitalInOut(board.D10)
20
21# Config for display baudrate (default max is 24mhz):
22BAUDRATE = 24000000
23
24# Setup SPI bus using hardware SPI:
25spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
26
27# Create the ILI9341 display:
28display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin, baudrate=BAUDRATE)
29
30# Main loop:
31while True:
32 # Fill the screen red, green, blue, then black:
33 for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
34 display.fill(color565(color))
35 # Clear the display
36 display.fill(0)
37 # Draw a red pixel in the center.
38 display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0))
39 # Pause 2 seconds.
40 time.sleep(2)
41 # Clear the screen a random color
42 display.fill(
43 color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
44 )
45 # Pause 2 seconds.
46 time.sleep(2)