Simple test¶
Ensure your device works with this simple test.
examples/st7789_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"""
8import board
9import terminalio
10import displayio
11from adafruit_display_text import label
12from adafruit_st7789 import ST7789
13
14# Release any resources currently in use for the displays
15displayio.release_displays()
16
17spi = board.SPI()
18tft_cs = board.D5
19tft_dc = board.D6
20
21display_bus = displayio.FourWire(
22 spi, command=tft_dc, chip_select=tft_cs, reset=board.D9
23)
24
25display = ST7789(display_bus, width=240, height=240, rowstart=80)
26
27# Make the display context
28splash = displayio.Group()
29display.show(splash)
30
31color_bitmap = displayio.Bitmap(240, 240, 1)
32color_palette = displayio.Palette(1)
33color_palette[0] = 0x00FF00 # Bright Green
34
35bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
36splash.append(bg_sprite)
37
38# Draw a smaller inner rectangle
39inner_bitmap = displayio.Bitmap(200, 200, 1)
40inner_palette = displayio.Palette(1)
41inner_palette[0] = 0xAA0088 # Purple
42inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
43splash.append(inner_sprite)
44
45# Draw a label
46text_group = displayio.Group(scale=2, x=50, y=120)
47text = "Hello World!"
48text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
49text_group.append(text_area) # Subgroup for text scaling
50splash.append(text_group)
51
52while True:
53 pass
240x135¶
examples/st7789_240x135_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"""
8import board
9import terminalio
10import displayio
11from adafruit_display_text import label
12from adafruit_st7789 import ST7789
13
14# First set some parameters used for shapes and text
15BORDER = 20
16FONTSCALE = 2
17BACKGROUND_COLOR = 0x00FF00 # Bright Green
18FOREGROUND_COLOR = 0xAA0088 # Purple
19TEXT_COLOR = 0xFFFF00
20
21# Release any resources currently in use for the displays
22displayio.release_displays()
23
24spi = board.SPI()
25tft_cs = board.D5
26tft_dc = board.D6
27
28display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
29display = ST7789(
30 display_bus, rotation=270, width=240, height=135, rowstart=40, colstart=53
31)
32
33# Make the display context
34splash = displayio.Group()
35display.show(splash)
36
37color_bitmap = displayio.Bitmap(display.width, display.height, 1)
38color_palette = displayio.Palette(1)
39color_palette[0] = BACKGROUND_COLOR
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(
46 display.width - BORDER * 2, display.height - BORDER * 2, 1
47)
48inner_palette = displayio.Palette(1)
49inner_palette[0] = FOREGROUND_COLOR
50inner_sprite = displayio.TileGrid(
51 inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
52)
53splash.append(inner_sprite)
54
55# Draw a label
56text = "Hello World!"
57text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR)
58text_width = text_area.bounding_box[2] * FONTSCALE
59text_group = displayio.Group(
60 scale=FONTSCALE,
61 x=display.width // 2 - text_width // 2,
62 y=display.height // 2,
63)
64text_group.append(text_area) # Subgroup for text scaling
65splash.append(text_group)
66
67while True:
68 pass
280x240¶
examples/st7789_280x240_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"""
8import board
9import terminalio
10import displayio
11from adafruit_display_text import label
12from adafruit_st7789 import ST7789
13
14# Release any resources currently in use for the displays
15displayio.release_displays()
16
17spi = board.SPI()
18tft_cs = board.D5
19tft_dc = board.D6
20
21display_bus = displayio.FourWire(
22 spi, command=tft_dc, chip_select=tft_cs, reset=board.D9
23)
24
25display = ST7789(display_bus, width=280, height=240, rowstart=20, rotation=90)
26
27# Make the display context
28splash = displayio.Group()
29display.show(splash)
30
31color_bitmap = displayio.Bitmap(280, 240, 1)
32color_palette = displayio.Palette(1)
33color_palette[0] = 0x00FF00 # Bright Green
34
35bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
36splash.append(bg_sprite)
37
38# Draw a smaller inner rectangle
39inner_bitmap = displayio.Bitmap(240, 200, 1)
40inner_palette = displayio.Palette(1)
41inner_palette[0] = 0xAA0088 # Purple
42inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
43splash.append(inner_sprite)
44
45# Draw a label
46text_group = displayio.Group(scale=3, x=37, y=120)
47text = "Hello World!"
48text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
49text_group.append(text_area) # Subgroup for text scaling
50splash.append(text_group)
51
52while True:
53 pass
320x240¶
examples/st7789_320x240_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"""
8import board
9import terminalio
10import displayio
11from adafruit_display_text import label
12from adafruit_st7789 import ST7789
13
14# Release any resources currently in use for the displays
15displayio.release_displays()
16
17spi = board.SPI()
18tft_cs = board.D5
19tft_dc = board.D6
20
21display_bus = displayio.FourWire(
22 spi, command=tft_dc, chip_select=tft_cs, reset=board.D9
23)
24
25display = ST7789(display_bus, width=320, height=240, rotation=90)
26
27# Make the display context
28splash = displayio.Group()
29display.show(splash)
30
31color_bitmap = displayio.Bitmap(320, 240, 1)
32color_palette = displayio.Palette(1)
33color_palette[0] = 0x00FF00 # Bright Green
34
35bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
36splash.append(bg_sprite)
37
38# Draw a smaller inner rectangle
39inner_bitmap = displayio.Bitmap(280, 200, 1)
40inner_palette = displayio.Palette(1)
41inner_palette[0] = 0xAA0088 # Purple
42inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
43splash.append(inner_sprite)
44
45# Draw a label
46text_group = displayio.Group(scale=3, x=57, y=120)
47text = "Hello World!"
48text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
49text_group.append(text_area) # Subgroup for text scaling
50splash.append(text_group)
51
52while True:
53 pass
Product specific examples¶
1.14” Mini PiTFT¶
examples/st7789_240x135_pitft_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
8Pinouts are for the 1.14" Mini PiTFT and should be run in CPython.
9"""
10import board
11import terminalio
12import displayio
13from adafruit_display_text import label
14from adafruit_st7789 import ST7789
15
16# First set some parameters used for shapes and text
17BORDER = 20
18FONTSCALE = 2
19BACKGROUND_COLOR = 0x00FF00 # Bright Green
20FOREGROUND_COLOR = 0xAA0088 # Purple
21TEXT_COLOR = 0xFFFF00
22
23# Release any resources currently in use for the displays
24displayio.release_displays()
25
26spi = board.SPI()
27tft_cs = board.CE0
28tft_dc = board.D25
29
30display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
31display = ST7789(
32 display_bus, rotation=90, width=240, height=135, rowstart=40, colstart=53
33)
34
35# Make the display context
36splash = displayio.Group()
37display.show(splash)
38
39color_bitmap = displayio.Bitmap(display.width, display.height, 1)
40color_palette = displayio.Palette(1)
41color_palette[0] = BACKGROUND_COLOR
42
43bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
44splash.append(bg_sprite)
45
46# Draw a smaller inner rectangle
47inner_bitmap = displayio.Bitmap(
48 display.width - BORDER * 2, display.height - BORDER * 2, 1
49)
50inner_palette = displayio.Palette(1)
51inner_palette[0] = FOREGROUND_COLOR
52inner_sprite = displayio.TileGrid(
53 inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
54)
55splash.append(inner_sprite)
56
57# Draw a label
58text = "Hello World!"
59text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR)
60text_width = text_area.bounding_box[2] * FONTSCALE
61text_group = displayio.Group(
62 scale=FONTSCALE,
63 x=display.width // 2 - text_width // 2,
64 y=display.height // 2,
65)
66text_group.append(text_area) # Subgroup for text scaling
67splash.append(text_group)
68
69while True:
70 pass
1.3” TFT Bonnet¶
examples/st7789_240x240_bonnet_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
8Pinouts are for the 1.3" TFT Bonnet and should be run in CPython.
9"""
10import board
11import terminalio
12import displayio
13from adafruit_display_text import label
14from adafruit_st7789 import ST7789
15
16# Release any resources currently in use for the displays
17displayio.release_displays()
18
19spi = board.SPI()
20tft_cs = board.CE0
21tft_dc = board.D25
22tft_lite = board.D26
23
24display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
25
26display = ST7789(
27 display_bus,
28 width=240,
29 height=240,
30 rowstart=80,
31 rotation=180,
32 backlight_pin=tft_lite,
33)
34
35# Make the display context
36splash = displayio.Group()
37display.show(splash)
38
39color_bitmap = displayio.Bitmap(240, 240, 1)
40color_palette = displayio.Palette(1)
41color_palette[0] = 0x00FF00 # Bright Green
42
43bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
44splash.append(bg_sprite)
45
46# Draw a smaller inner rectangle
47inner_bitmap = displayio.Bitmap(200, 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=2, x=50, 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
1.3” PiTFT¶
examples/st7789_240x240_pitft_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
8Pinouts are for the 1.3" PiTFT and should be run in CPython.
9"""
10import board
11import terminalio
12import displayio
13from adafruit_display_text import label
14from adafruit_st7789 import ST7789
15
16# Release any resources currently in use for the displays
17displayio.release_displays()
18
19spi = board.SPI()
20tft_cs = board.CE0
21tft_dc = board.D25
22
23display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
24
25display = ST7789(display_bus, width=240, height=240, rowstart=80, rotation=180)
26
27# Make the display context
28splash = displayio.Group()
29display.show(splash)
30
31color_bitmap = displayio.Bitmap(240, 240, 1)
32color_palette = displayio.Palette(1)
33color_palette[0] = 0x00FF00 # Bright Green
34
35bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
36splash.append(bg_sprite)
37
38# Draw a smaller inner rectangle
39inner_bitmap = displayio.Bitmap(200, 200, 1)
40inner_palette = displayio.Palette(1)
41inner_palette[0] = 0xAA0088 # Purple
42inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
43splash.append(inner_sprite)
44
45# Draw a label
46text_group = displayio.Group(scale=2, x=50, y=120)
47text = "Hello World!"
48text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
49text_group.append(text_area) # Subgroup for text scaling
50splash.append(text_group)
51
52while True:
53 pass
Gizmo¶
examples/st7789_tft_gizmo_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"""
8import board
9import busio
10import terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7789 import ST7789
14
15# Release any resources currently in use for the displays
16displayio.release_displays()
17
18spi = busio.SPI(board.SCL, MOSI=board.SDA)
19tft_cs = board.RX
20tft_dc = board.TX
21tft_backlight = board.A3
22
23display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
24
25display = ST7789(
26 display_bus,
27 width=240,
28 height=240,
29 rowstart=80,
30 backlight_pin=tft_backlight,
31 rotation=180,
32)
33
34# Make the display context
35splash = displayio.Group()
36display.show(splash)
37
38color_bitmap = displayio.Bitmap(240, 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)
43splash.append(bg_sprite)
44
45# Draw a smaller inner rectangle
46inner_bitmap = displayio.Bitmap(200, 200, 1)
47inner_palette = displayio.Palette(1)
48inner_palette[0] = 0xAA0088 # Purple
49inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
50splash.append(inner_sprite)
51
52# Draw a label
53text_group = displayio.Group(scale=2, x=50, y=120)
54text = "Hello World!"
55text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
56text_group.append(text_area) # Subgroup for text scaling
57splash.append(text_group)
58
59while True:
60 pass
Pimoroni Pico Display Pack¶
examples/st7789_240x135_simpletest_Pimoroni_Pico_Display_Pack.py¶
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import board
5import busio
6import terminalio
7import displayio
8from adafruit_display_text import label
9from adafruit_st7789 import ST7789
10
11# First set some parameters used for shapes and text
12BORDER = 20
13FONTSCALE = 2
14BACKGROUND_COLOR = 0x00FF00 # Bright Green
15FOREGROUND_COLOR = 0xAA0088 # Purple
16TEXT_COLOR = 0xFFFF00
17
18# Release any resources currently in use for the displays
19displayio.release_displays()
20
21tft_cs = board.GP17
22tft_dc = board.GP16
23spi_mosi = board.GP19
24spi_clk = board.GP18
25spi = busio.SPI(spi_clk, spi_mosi)
26
27display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
28display = ST7789(
29 display_bus, rotation=270, width=240, height=135, rowstart=40, colstart=53
30)
31
32# Make the display context
33splash = displayio.Group()
34display.show(splash)
35
36color_bitmap = displayio.Bitmap(display.width, display.height, 1)
37color_palette = displayio.Palette(1)
38color_palette[0] = BACKGROUND_COLOR
39
40bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
41splash.append(bg_sprite)
42
43# Draw a smaller inner rectangle
44inner_bitmap = displayio.Bitmap(
45 display.width - BORDER * 2, display.height - BORDER * 2, 1
46)
47inner_palette = displayio.Palette(1)
48inner_palette[0] = FOREGROUND_COLOR
49inner_sprite = displayio.TileGrid(
50 inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
51)
52splash.append(inner_sprite)
53
54# Draw a label
55text = "Hello World!"
56text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR)
57text_width = text_area.bounding_box[2] * FONTSCALE
58text_group = displayio.Group(
59 scale=FONTSCALE,
60 x=display.width // 2 - text_width // 2,
61 y=display.height // 2,
62)
63text_group.append(text_area) # Subgroup for text scaling
64splash.append(text_group)
65
66while True:
67 pass
Pimoroni Pico Explorer¶
examples/st7789_240x240_simpletest_Pimoroni_Pico_Explorer.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"""
8import board
9import busio
10import terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7789 import ST7789
14
15# Release any resources currently in use for the displays
16displayio.release_displays()
17
18tft_cs = board.GP17
19tft_dc = board.GP16
20spi_mosi = board.GP19
21spi_clk = board.GP18
22spi = busio.SPI(spi_clk, spi_mosi)
23
24display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
25
26display = ST7789(display_bus, width=240, height=240, rowstart=80, rotation=180)
27
28# Make the display context
29splash = displayio.Group()
30display.show(splash)
31
32color_bitmap = displayio.Bitmap(240, 240, 1)
33color_palette = displayio.Palette(1)
34color_palette[0] = 0x00FF00 # Bright Green
35
36bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
37splash.append(bg_sprite)
38
39# Draw a smaller inner rectangle
40inner_bitmap = displayio.Bitmap(200, 200, 1)
41inner_palette = displayio.Palette(1)
42inner_palette[0] = 0xAA0088 # Purple
43inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
44splash.append(inner_sprite)
45
46# Draw a label
47text_group = displayio.Group(scale=2, x=50, y=120)
48text = "Hello World!"
49text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
50text_group.append(text_area) # Subgroup for text scaling
51splash.append(text_group)
52
53while True:
54 pass
Pimoroni Pico Display Pack 2.0¶
examples/st7789_320x240_simpletest_Pimoroni_Pico_Display_2_0.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"""
8import board
9import busio
10import terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7789 import ST7789
14
15# Release any resources currently in use for the displays
16displayio.release_displays()
17
18tft_cs = board.GP17
19tft_dc = board.GP16
20spi_mosi = board.GP19
21spi_clk = board.GP18
22spi = busio.SPI(spi_clk, spi_mosi)
23backlight = board.GP20
24
25display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
26
27display = ST7789(
28 display_bus, rotation=270, width=320, height=240, backlight_pin=backlight
29)
30
31# Make the display context
32splash = displayio.Group()
33display.show(splash)
34
35color_bitmap = displayio.Bitmap(320, 240, 1)
36color_palette = displayio.Palette(1)
37color_palette[0] = 0x00FF00 # Bright Green
38
39bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
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