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