CircuitPython includes DisplayIO a native library for showing text, bitmaps, animations and more. An LED matrix driven by an IS31FL3741 chip, like is found on the Adafruit EyeLights LED Glasses, supports DisplayIO.
The example below demonstrates how to set up the glasses to be a DisplayIO device. The example code scrolls text across the glasses. See the DisplayIO learn guide for more examples of what you can do with DisplayIO.
The following code block is responsible for initializing the display.
displayio.release_displays() i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000) is31 = is31fl3741.IS31FL3741(i2c=i2c) is31_framebuffer = is31fl3741.IS31FL3741_FrameBuffer( is31, 54, 15, glassesmatrix_ledmap, scale=True, gamma=True ) display = framebufferio.FramebufferDisplay(is31_framebuffer)
The IS31FL3741_FrameBuffer
class has a keyword scale
that is worth explanation. Due to the fact the EyeLights are low resolution, when the scale
option is set to True
, the DisplayIO canvas created is 3 times larger then the display's physical size. For the EyeLight Glasses with a physical size of 18 x 5 this means the internal DisplayIO canvas is 54 x 15 pixels. When the display is refreshed on the physical device, the internal canvas is averaged and scaled down to match the physical device size. This allows for the illusion of a higher resolution then actually exists, useful for displaying text.
To use with CircuitPython, you need to first install a few libraries, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file, open the directory IS31FL3741_DisplayIO/scrolling_text/ and then click on the directory that matches the version of CircuitPython you're using and copy the contents of that directory to your CIRCUITPY drive.
Your CIRCUITPY
# SPDX-FileCopyrightText: 2022 Mark Komus # # SPDX-License-Identifier: MIT import random import time import board import busio import displayio import framebufferio import is31fl3741 from adafruit_is31fl3741.led_glasses_map import glassesmatrix_ledmap from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font # List of possible messages to display. MESSAGES = ( "DISPLAYIO AMAZES", "CIRCUITPYTHON RULES", "HELLO WORLD!", ) TEXT_COLOR = (220, 210, 0) # Yellow # Remove any existing displays displayio.release_displays() # Initialize the LED Glasses # # In this example scale is set to True. When True the logical display is # three times the physical display size and scaled down to allow text to # look more natural for small display sizes. Hence the display is created # as 54x15 when the physical display is 18x5. # i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000) is31 = is31fl3741.IS31FL3741(i2c=i2c) is31_framebuffer = is31fl3741.IS31FL3741_FrameBuffer( is31, 54, 15, glassesmatrix_ledmap, scale=True, gamma=True ) display = framebufferio.FramebufferDisplay(is31_framebuffer, auto_refresh=True) # Dim the display. Full brightness is BRIGHT is31_framebuffer.brightness = 0.2 # Load the font to be used - scrolly only has upper case letters font = bitmap_font.load_font("/fonts/scrolly.bdf") # Set up the displayio elements text_area = label.Label(font, text="", color=TEXT_COLOR) text_area.y = 8 group = displayio.Group() group.append(text_area) display.root_group = group # Continue to scroll messages forever while True: # Pick a random message to display text_area.text = random.choice(MESSAGES) # Reset the text to start just off the right side x = display.width text_area.x = x # Determine the width of the message to scroll width = text_area.bounding_box[2] # Scroll the message across the glasses while x != -width: x = x - 1 text_area.x = x time.sleep(0.05) # adjust to change scrolling speed