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 terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7735r import ST7735R
14
15# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16try:
17    from fourwire import FourWire
18except ImportError:
19    from displayio import FourWire
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 = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1)
31
32# Make the display context
33splash = displayio.Group()
34display.root_group = splash
35
36color_bitmap = displayio.Bitmap(128, 128, 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(108, 108, 1)
45inner_palette = displayio.Palette(1)
46inner_palette[0] = 0xAA0088  # Purple
47inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=10, y=10)
48splash.append(inner_sprite)
49
50# Draw a label
51text = "Hello World!"
52text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=30, y=64)
53splash.append(text_area)
54
55while True:
56    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 terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7735r import ST7735R
14
15# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16try:
17    from fourwire import FourWire
18except ImportError:
19    from displayio import FourWire
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 = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)
31
32# Make the display context
33splash = displayio.Group()
34display.root_group = splash
35
36color_bitmap = displayio.Bitmap(160, 128, 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(150, 118, 1)
45inner_palette = displayio.Palette(1)
46inner_palette[0] = 0xAA0088  # Purple
47inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
48splash.append(inner_sprite)
49
50# Draw a label
51text_group = displayio.Group(scale=2, x=11, y=64)
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
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 terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7735r import ST7735R
14
15try:
16    from fourwire import FourWire
17except ImportError:
18    from displayio import FourWire
19
20# Release any resources currently in use for the displays
21displayio.release_displays()
22
23spi = board.SPI()
24tft_cs = board.D5
25tft_dc = board.D6
26
27display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
28
29display = ST7735R(
30    display_bus, width=160, height=80, colstart=24, rotation=270, bgr=False
31)
32
33# Make the display context
34splash = displayio.Group()
35display.root_group = splash
36
37color_bitmap = displayio.Bitmap(160, 80, 1)
38color_palette = displayio.Palette(1)
39# write some text in each font color, rgb, cmyk
40color_palette[0] = 0x111111  # light grey
41
42text_group_left = displayio.Group(scale=1, x=0, y=6)
43text_area_red = label.Label(terminalio.FONT, text="RED", color=0xFF0000)
44text_area_green = label.Label(terminalio.FONT, text="\nGREEN", color=0x00FF00)
45text_area_blue = label.Label(terminalio.FONT, text="\n\nBLUE", color=0x0000FF)
46text_area_white = label.Label(terminalio.FONT, text="\n\n\nWHITE", color=0xFFFFFF)
47text_group_left.append(text_area_red)
48text_group_left.append(text_area_green)
49text_group_left.append(text_area_blue)
50text_group_left.append(text_area_white)
51splash.append(text_group_left)
52
53text_group_right = displayio.Group(scale=1, x=80, y=6)
54text_area_cyan = label.Label(terminalio.FONT, text="CYAN", color=0x00FFFF)
55text_group_right.append(text_area_cyan)
56text_area_magenta = label.Label(terminalio.FONT, text="\nMAGENTA", color=0xFF00FF)
57text_group_right.append(text_area_magenta)
58text_area_yellow = label.Label(terminalio.FONT, text="\n\nYELLOW", color=0xFFFF00)
59text_group_right.append(text_area_yellow)
60text_area_black = label.Label(terminalio.FONT, text="\n\n\nBLACK", color=0x000000)
61text_group_right.append(text_area_black)
62splash.append(text_group_right)
63
64while True:
65    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 terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_seesaw.seesaw import Seesaw
14from adafruit_st7735r import ST7735R
15
16# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
17try:
18    from fourwire import FourWire
19except ImportError:
20    from displayio import FourWire
21
22# Release any resources currently in use for the displays
23displayio.release_displays()
24
25reset_pin = 8
26i2c = board.I2C()  # uses board.SCL and board.SDA
27# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
28ss = Seesaw(i2c, 0x5E)
29ss.pin_mode(reset_pin, ss.OUTPUT)
30
31spi = board.SPI()
32tft_cs = board.D5
33tft_dc = board.D6
34
35display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs)
36
37ss.digital_write(reset_pin, True)
38display = ST7735R(
39    display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True
40)
41
42# Make the display context
43splash = displayio.Group()
44display.root_group = splash
45
46color_bitmap = displayio.Bitmap(160, 80, 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(150, 70, 1)
55inner_palette = displayio.Palette(1)
56inner_palette[0] = 0xAA0088  # Purple
57inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
58splash.append(inner_sprite)
59
60# Draw a label
61text_group = displayio.Group(scale=2, x=11, y=40)
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

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 terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7735r import ST7735R
14
15# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16try:
17    from fourwire import FourWire
18except ImportError:
19    from displayio import FourWire
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 = ST7735R(
31    display_bus,
32    width=160,
33    height=80,
34    rowstart=1,
35    colstart=26,
36    rotation=270,
37    invert=True,
38)
39
40# Make the display context
41splash = displayio.Group()
42display.root_group = splash
43
44color_bitmap = displayio.Bitmap(160, 80, 1)
45color_palette = displayio.Palette(1)
46color_palette[0] = 0x00FF00  # Bright Green
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(150, 70, 1)
53inner_palette = displayio.Palette(1)
54inner_palette[0] = 0xAA0088  # Purple
55inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
56splash.append(inner_sprite)
57
58# Draw a label
59text_group = displayio.Group(scale=2, x=11, y=40)
60text = "Hello World!"
61text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
62text_group.append(text_area)  # Subgroup for text scaling
63splash.append(text_group)
64
65while True:
66    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 terminalio
11import displayio
12from adafruit_display_text import label
13from adafruit_st7735r import ST7735R
14
15# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
16try:
17    from fourwire import FourWire
18except ImportError:
19    from displayio import FourWire
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 = ST7735R(
31    display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True
32)
33
34# Make the display context
35splash = displayio.Group()
36display.root_group = splash
37
38color_bitmap = displayio.Bitmap(160, 80, 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(150, 70, 1)
47inner_palette = displayio.Palette(1)
48inner_palette[0] = 0xAA0088  # Purple
49inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=5, y=5)
50splash.append(inner_sprite)
51
52# Draw a label
53text_group = displayio.Group(scale=2, x=11, y=40)
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

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"""
 7import time
 8import board
 9import displayio
10from adafruit_seesaw.tftshield18 import TFTShield18
11from adafruit_st7735r import ST7735R
12
13# Support both 8.x.x and 9.x.x. Change when 8.x.x is discontinued as a stable release.
14try:
15    from fourwire import FourWire
16except ImportError:
17    from displayio import FourWire
18
19# Release any resources currently in use for the displays
20displayio.release_displays()
21
22ss = TFTShield18()
23
24spi = board.SPI()
25tft_cs = board.D10
26tft_dc = board.D8
27
28display_bus = FourWire(spi, command=tft_dc, chip_select=tft_cs)
29
30ss.tft_reset()
31display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)
32
33ss.set_backlight(True)
34
35while True:
36    buttons = ss.buttons
37
38    if buttons.right:
39        print("Button RIGHT!")
40
41    if buttons.down:
42        print("Button DOWN!")
43
44    if buttons.left:
45        print("Button LEFT!")
46
47    if buttons.up:
48        print("Button UP!")
49
50    if buttons.select:
51        print("Button SELECT!")
52
53    if buttons.a:
54        print("Button A!")
55
56    if buttons.b:
57        print("Button B!")
58
59    if buttons.c:
60        print("Button C!")
61
62    time.sleep(0.001)