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