Libraries, Devices, and Welcome Screen

When the PyGamer's power is turned on, the module first imports all the required libraries. That includes the helper file that we'll review later.

# 2020-01-29 v3.2
# (c) 2020 Jan Goolsbey for Adafruit Industries

import time
import board
import displayio
from simpleio import map_range
from adafruit_display_text.label import Label
from adafruit_bitmap_font import bitmap_font
from adafruit_display_shapes.rect import Rect
import adafruit_amg88xx
from adafruit_pybadger import pybadger as panel
from thermal_cam_converters import celsius_to_fahrenheit, fahrenheit_to_celsius
# Load default alarm and min/max range values list from config file
from thermal_cam_config import ALARM_F, MIN_RANGE_F, MAX_RANGE_F

Next, the code checks to see if the PyGamer's joystick is present and sets the panel.has_joystick flag to True. If not, then the host device is probably a PyBadge or EdgeBadge; this code will work for those devices, interpreting the D-Pad buttons like the joystick.

# Establish panel instance and check for joystick
panel.pixels.brightness = 0.1        # Set NeoPixel brightness
panel.pixels.fill(0)                 # Clear all NeoPixels
if hasattr(board, "JOYSTICK_X"):
    panel.has_joystick = True     # PyGamer
else: panel.has_joystick = False  # Must be PyBadge

The AMG8833 FeatherWing is instantiated on the I2C communications bus, then the OpenSans-9.bdf font file is loaded from the /fonts folder.

# Establish I2C interface for the AMG8833 Thermal Camera
i2c = board.I2C()
amg8833 = adafruit_amg88xx.AMG88XX(i2c)
# Load the text font from the fonts folder
font = bitmap_font.load_font("/fonts/OpenSans-9.bdf")

Finally, the welcome graphics screen, thermal_cam_splash.bmp is displayed followed by a two-tone welcoming beep.

# Display splash graphics and play startup tones
# CircuitPython 6 & 7 compatible
with open("/thermal_cam_splash.bmp", "rb") as bitmap_file:
    bitmap = displayio.OnDiskBitmap(bitmap_file)
    splash = displayio.Group()
                                     pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter())))
    time.sleep(0.1)  # Allow the splash to display

# # CircuitPython 7+ compatible
# splash = displayio.Group()
# bitmap = displayio.OnDiskBitmap("/thermal_cam_splash.bmp")
# splash.append(displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader))
# time.sleep(0.1)  # Allow the splash to display

panel.play_tone(440, 0.1)  # A4
panel.play_tone(880, 0.1)  # A5

This guide was first published on Jan 29, 2020. It was last updated on 2021-05-31 14:57:06 -0400.

This page (Import and Initialize) was last updated on Oct 22, 2021.

Text editor powered by tinymce.