Simple Test

Ensure your device works with this simple test.

examples/st7735r_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 displayio
11import terminalio
12from adafruit_display_text import label
13from fourwire import FourWire
14
15from adafruit_st7735r import ST7735R
16
17# Release any resources currently in use for the displays
18displayio.release_displays()
19
20spi = board.SPI()
21tft_cs = board.D5
22tft_dc = board.D6
23
24display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
25
26display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=3)
27
28# Make the display context
29splash = displayio.Group()
30display.root_group = splash
31
32color_bitmap = displayio.Bitmap(128, 128, 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(108, 108, 1)
41inner_palette = displayio.Palette(1)
42inner_palette[0] = 0xAA0088  # Purple
43inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=10, y=10)
44splash.append(inner_sprite)
45
46# Draw a label
47text = "Hello World!"
48text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=30, y=64)
49splash.append(text_area)
50
51while True:
52    pass

128x160 Tests

Examples for the 128x160

examples/st7735r_128x160_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 displayio
11import terminalio
12from adafruit_display_text import label
13from fourwire import FourWire
14
15from adafruit_st7735r import ST7735R
16
17# Release any resources currently in use for the displays
18displayio.release_displays()
19
20spi = board.SPI()
21tft_cs = board.D5
22tft_dc = board.D6
23
24display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
25
26display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)
27
28# Make the display context
29splash = displayio.Group()
30display.root_group = splash
31
32color_bitmap = displayio.Bitmap(160, 128, 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(150, 118, 1)
41inner_palette = displayio.Palette(1)
42inner_palette[0] = 0xAA0088  # Purple
43inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
44splash.append(inner_sprite)
45
46# Draw a label
47text_group = displayio.Group(scale=2, x=11, y=64)
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
examples/st7735r_128x160_colored_labels.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 8 colored
 6labels. Useful for testing the color settings on an unknown display.
 7"""
 8
 9import board
10import displayio
11import terminalio
12from adafruit_display_text import label
13from fourwire import FourWire
14
15from adafruit_st7735r import ST7735R
16
17# Release any resources currently in use for the displays
18displayio.release_displays()
19
20spi = board.SPI()
21tft_cs = board.D5
22tft_dc = board.D6
23
24display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
25
26display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=False)
27
28# Make the display context
29splash = displayio.Group()
30display.root_group = splash
31
32color_bitmap = displayio.Bitmap(160, 80, 1)
33color_palette = displayio.Palette(1)
34# write some text in each font color, rgb, cmyk
35color_palette[0] = 0x111111  # light grey
36
37text_group_left = displayio.Group(scale=1, x=0, y=6)
38text_area_red = label.Label(terminalio.FONT, text="RED", color=0xFF0000)
39text_area_green = label.Label(terminalio.FONT, text="\nGREEN", color=0x00FF00)
40text_area_blue = label.Label(terminalio.FONT, text="\n\nBLUE", color=0x0000FF)
41text_area_white = label.Label(terminalio.FONT, text="\n\n\nWHITE", color=0xFFFFFF)
42text_group_left.append(text_area_red)
43text_group_left.append(text_area_green)
44text_group_left.append(text_area_blue)
45text_group_left.append(text_area_white)
46splash.append(text_group_left)
47
48text_group_right = displayio.Group(scale=1, x=80, y=6)
49text_area_cyan = label.Label(terminalio.FONT, text="CYAN", color=0x00FFFF)
50text_group_right.append(text_area_cyan)
51text_area_magenta = label.Label(terminalio.FONT, text="\nMAGENTA", color=0xFF00FF)
52text_group_right.append(text_area_magenta)
53text_area_yellow = label.Label(terminalio.FONT, text="\n\nYELLOW", color=0xFFFF00)
54text_group_right.append(text_area_yellow)
55text_area_black = label.Label(terminalio.FONT, text="\n\n\nBLACK", color=0x000000)
56text_group_right.append(text_area_black)
57splash.append(text_group_right)
58
59while True:
60    pass

Minitft FeatherWing Test

Simple example for the minitft featherwing

examples/st7735r_minitft_featherwing_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 displayio
11import terminalio
12from adafruit_display_text import label
13from adafruit_seesaw.seesaw import Seesaw
14from fourwire import FourWire
15
16from adafruit_st7735r import ST7735R
17
18# Release any resources currently in use for the displays
19displayio.release_displays()
20
21reset_pin = 8
22i2c = board.I2C()  # uses board.SCL and board.SDA
23# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
24ss = Seesaw(i2c, 0x5E)
25ss.pin_mode(reset_pin, ss.OUTPUT)
26
27spi = board.SPI()
28tft_cs = board.D5
29tft_dc = board.D6
30
31display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs)
32
33ss.digital_write(reset_pin, True)
34display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True)
35
36# Make the display context
37splash = displayio.Group()
38display.root_group = splash
39
40color_bitmap = displayio.Bitmap(160, 80, 1)
41color_palette = displayio.Palette(1)
42color_palette[0] = 0x00FF00  # Bright Green
43
44bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
45splash.append(bg_sprite)
46
47# Draw a smaller inner rectangle
48inner_bitmap = displayio.Bitmap(150, 70, 1)
49inner_palette = displayio.Palette(1)
50inner_palette[0] = 0xAA0088  # Purple
51inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
52splash.append(inner_sprite)
53
54# Draw a label
55text_group = displayio.Group(scale=2, x=11, y=40)
56text = "Hello World!"
57text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
58text_group.append(text_area)  # Subgroup for text scaling
59splash.append(text_group)
60
61while True:
62    pass

MiniTFT Test

Simple example for the minitft (newer Revision B)

examples/st7735r_minitft_revb_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 displayio
11import terminalio
12from adafruit_display_text import label
13from fourwire import FourWire
14
15from adafruit_st7735r import ST7735R
16
17# Release any resources currently in use for the displays
18displayio.release_displays()
19
20spi = board.SPI()
21tft_cs = board.D5
22tft_dc = board.D6
23
24display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
25
26display = ST7735R(
27    display_bus,
28    width=160,
29    height=80,
30    rowstart=1,
31    colstart=26,
32    rotation=270,
33    invert=True,
34)
35
36# Make the display context
37splash = displayio.Group()
38display.root_group = splash
39
40color_bitmap = displayio.Bitmap(160, 80, 1)
41color_palette = displayio.Palette(1)
42color_palette[0] = 0x00FF00  # Bright Green
43
44bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
45splash.append(bg_sprite)
46
47# Draw a smaller inner rectangle
48inner_bitmap = displayio.Bitmap(150, 70, 1)
49inner_palette = displayio.Palette(1)
50inner_palette[0] = 0xAA0088  # Purple
51inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
52splash.append(inner_sprite)
53
54# Draw a label
55text_group = displayio.Group(scale=2, x=11, y=40)
56text = "Hello World!"
57text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
58text_group.append(text_area)  # Subgroup for text scaling
59splash.append(text_group)
60
61while True:
62    pass

Simple example for the minitft (older Revision A)

examples/st7735r_minitft_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 displayio
11import terminalio
12from adafruit_display_text import label
13from fourwire import FourWire
14
15from adafruit_st7735r import ST7735R
16
17# Release any resources currently in use for the displays
18displayio.release_displays()
19
20spi = board.SPI()
21tft_cs = board.D5
22tft_dc = board.D6
23
24display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
25
26display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True)
27
28# Make the display context
29splash = displayio.Group()
30display.root_group = splash
31
32color_bitmap = displayio.Bitmap(160, 80, 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(150, 70, 1)
41inner_palette = displayio.Palette(1)
42inner_palette[0] = 0xAA0088  # Purple
43inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
44splash.append(inner_sprite)
45
46# Draw a label
47text_group = displayio.Group(scale=2, x=11, y=40)
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

Shield Buttons

Example for the shield buttons

examples/st7735r_18tftshield_buttons.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5This example will test out the display on the 1.8" TFT Shield
 6"""
 7
 8import time
 9
10import board
11import displayio
12from adafruit_seesaw.tftshield18 import TFTShield18
13from fourwire import FourWire
14
15from adafruit_st7735r import ST7735R
16
17# Release any resources currently in use for the displays
18displayio.release_displays()
19
20ss = TFTShield18()
21
22spi = board.SPI()
23tft_cs = board.D10
24tft_dc = board.D8
25
26display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs)
27
28ss.tft_reset()
29display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)
30
31ss.set_backlight(True)
32
33while True:
34    buttons = ss.buttons
35
36    if buttons.right:
37        print("Button RIGHT!")
38
39    if buttons.down:
40        print("Button DOWN!")
41
42    if buttons.left:
43        print("Button LEFT!")
44
45    if buttons.up:
46        print("Button UP!")
47
48    if buttons.select:
49        print("Button SELECT!")
50
51    if buttons.a:
52        print("Button A!")
53
54    if buttons.b:
55        print("Button B!")
56
57    if buttons.c:
58        print("Button C!")
59
60    time.sleep(0.001)