This example requires CircuitPython 7.2.0-alpha.1 or later.

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.

Use the “Download Project Bundle” button below to get this CircuitPython code and all required libraries.

# 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.show(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

This guide was first published on Oct 12, 2021. It was last updated on 2022-02-14 16:45:58 -0500.

This page (DisplayIO Message Scroller) was last updated on May 24, 2022.

Text editor powered by tinymce.