Simple test

Ensure your device works with this simple test.

examples/gizmo_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5from random import randrange
 6import displayio
 7from adafruit_gizmo import tft_gizmo
 8
 9# Create the TFT Gizmo display
10display = tft_gizmo.TFT_Gizmo()
11
12# You can now use the display to do whatever you want
13# Here we show how to draw random pixels
14
15# Create a bitmap with two colors
16bitmap = displayio.Bitmap(display.width, display.height, 2)
17
18# Create a two color palette
19palette = displayio.Palette(2)
20palette[0] = 0x000000
21palette[1] = 0xFFFFFF
22
23# Create a TileGrid using the Bitmap and Palette
24tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette)
25
26# Create a Group
27group = displayio.Group()
28
29# Add the TileGrid to the Group
30group.append(tile_grid)
31
32# Add the Group to the Display
33display.show(group)
34
35# Draw pixels
36while True:
37    for _ in range(200):
38        x = randrange(0, display.width)
39        y = randrange(0, display.height)
40        bitmap[x, y] = 1
41        time.sleep(0.1)
42    for i in range(display.width * display.height):
43        bitmap[i] = 0

Other examples

examples/gizmo_tft_demo.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 displayio
 9import terminalio
10from adafruit_display_text import label
11from adafruit_gizmo import tft_gizmo
12
13# Create the TFT Gizmo display
14display = tft_gizmo.TFT_Gizmo()
15
16# Make the display context
17splash = displayio.Group()
18display.show(splash)
19
20color_bitmap = displayio.Bitmap(240, 240, 1)
21color_palette = displayio.Palette(1)
22color_palette[0] = 0x00FF00  # Bright Green
23
24bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
25splash.append(bg_sprite)
26
27# Draw a smaller inner rectangle
28inner_bitmap = displayio.Bitmap(200, 200, 1)
29inner_palette = displayio.Palette(1)
30inner_palette[0] = 0xAA0088  # Purple
31inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
32splash.append(inner_sprite)
33
34# Draw a label
35text_group = displayio.Group(scale=2, x=50, y=120)
36text = "Hello World!"
37text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
38text_group.append(text_area)  # Subgroup for text scaling
39splash.append(text_group)
40
41while True:
42    pass
examples/gizmo_tft_thermometer.py
  1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
  2# SPDX-License-Identifier: MIT
  3
  4"""
  5This example will initialize the display using displayio and draw a bmp image
  6background, and overlay text containing the value read from the on-board temperature sensor.
  7User may press the A button to switch between celsius and fahrenheit units.
  8
  9Required libraries:
 10* Adafruit_CircuitPython_Gizmo
 11* Adafruit_CircuitPython_ST7789
 12* Adafruit_CircuitPython_Display_Text
 13* Adafruit_CircuitPython_CircuitPlayground
 14"""
 15import time
 16from adafruit_circuitplayground import cp
 17import displayio
 18import terminalio
 19from adafruit_display_text import label
 20from adafruit_gizmo import tft_gizmo
 21
 22display = tft_gizmo.TFT_Gizmo()
 23
 24
 25# text scaling factor
 26TEXT_SCALE = 2
 27
 28# previous iteration button value
 29old_a_val = cp.button_a
 30
 31# boolean for current unit type
 32show_c_units = True
 33
 34
 35# function to convert celsius degrees to fahrenheit
 36def c_to_f(c_val):
 37    return (c_val * 9 / 5) + 32
 38
 39
 40# Open the background image file
 41with open("/thermometer_background.bmp", "rb") as bitmap_file:
 42
 43    # Setup the file as the bitmap data source
 44    bitmap = displayio.OnDiskBitmap(bitmap_file)
 45
 46    # Create a TileGrid to hold the bitmap
 47    # CircuitPython 6 & 7 compatible
 48    tile_grid = displayio.TileGrid(
 49        bitmap,
 50        pixel_shader=getattr(bitmap, "pixel_shader", displayio.ColorConverter()),
 51    )
 52    # CircuitPython 7 compatible only
 53    # tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
 54
 55    # Create a Group to hold the TileGrid
 56    group = displayio.Group()
 57
 58    # Add the TileGrid to the Group
 59    group.append(tile_grid)
 60
 61    # variable with initial text value, temperature rounded to 2 places
 62    text = "%.2f C" % (round(cp.temperature, 2))
 63
 64    # Create a Group for the text so we can scale it
 65    text_group = displayio.Group(scale=TEXT_SCALE, x=0, y=0)
 66
 67    # Create a Label to show the initial temperature value
 68    text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF)
 69
 70    # Set the anchor_point for center,top
 71    text_area.anchor_point = (0.5, 0.0)
 72
 73    # Set the location to center of display, accounting for text_scale
 74    text_area.anchored_position = (240 / (2 * TEXT_SCALE), 240 / (2 * TEXT_SCALE))
 75
 76    # Subgroup for text scaling
 77    text_group.append(text_area)
 78
 79    # Add the text_group to main Group
 80    group.append(text_group)
 81
 82    # Add the main Group to the Display
 83    display.show(group)
 84
 85    # Loop forever
 86    while True:
 87        # set current button state to variable
 88        cur_a_val = cp.button_a
 89        if cur_a_val and not old_a_val:  # if the button was released
 90            print("Just released")
 91            # flip the units boolean to the opposite value
 92            show_c_units = not show_c_units
 93
 94        if show_c_units:
 95            # Update the text
 96            text_area.text = "%.2f C" % (round(cp.temperature, 2))
 97        else:  # show f units
 98            # Update the text
 99            text_area.text = "%.2f F" % (round(c_to_f(cp.temperature), 2))
100
101        # set previous button value for next time
102        old_a_val = cur_a_val
103        # Wait a little bit
104        time.sleep(0.2)
examples/gizmo_eink_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import displayio
 6from adafruit_gizmo import eink_gizmo
 7
 8display = eink_gizmo.EInk_Gizmo()
 9# Use the below line instead for the 200x200 E-Ink Gizmo
10# display = eink_gizmo.EInk_HD_Gizmo()
11
12# Create a display group for our screen objects
13display_group = displayio.Group()
14
15# Display a ruler graphic from the root directory of the CIRCUITPY drive
16with open("/display-ruler.bmp", "rb") as file:
17    picture = displayio.OnDiskBitmap(file)
18    # Create a Tilegrid with the bitmap and put in the displayio group
19    # CircuitPython 6 & 7 compatible
20    sprite = displayio.TileGrid(
21        picture,
22        pixel_shader=getattr(picture, "pixel_shader", displayio.ColorConverter()),
23    )
24    # CircuitPython 7 compatible only
25    # sprite = displayio.TileGrid(picture, pixel_shader=bitmap.pixel_shader)
26    display_group.append(sprite)
27
28    # Place the display group on the screen
29    display.show(display_group)
30
31    # Refresh the display to have it actually show the image
32    # NOTE: Do not refresh eInk displays sooner than 180 seconds
33    display.refresh()
34    print("refreshed")
35
36    time.sleep(180)