Import and Initialize

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.

Download: file
# 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
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.

Download: file
# Establish panel instance and check for joystick
panel = PyBadger(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.

Download: file
# Establish I2C interface for the AMG8833 Thermal Camera
i2c = board.I2C()
amg8833 = adafruit_amg88xx.AMG88XX(i2c)
Download: file
# 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.

Download: file
# Display spash graphics and play startup tones
with open("/thermal_cam_splash.bmp", "rb") as bitmap_file:
    bitmap = displayio.OnDiskBitmap(bitmap_file)
    splash = displayio.Group()
    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 Jan 29, 2020.
This page (Import and Initialize) was last updated on Jul 30, 2020.