It's easy to use the 5x5 NeoPixel Grid BFF with CircuitPython and the Adafruit_CircuitPython_NeoPixel module. This module allows you to easily write Python code that lets you control NeoPixels.

CircuitPython Microcontroller Wiring

Plug a 5x5 NeoPixel Grid BFF into your QT Py or Xiao form factor board exactly as shown below. Here's an example of connecting a QT Py RP2040 to the BFF.

Connect the QT Py RP2040 with plug headers into the 5x5 NeoPixel Grid BFF with socket headers. They should be plugged in with the backs of the boards facing each other.

For more information on soldering socket headers, check out this Learn Guide.

CircuitPython Usage

To use with CircuitPython, you need to first install the NeoPixel library, and its dependencies, 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, and copy the entire lib folder, the tom-thumb.pcf font file, and the code.py file to your CIRCUITPY drive.

Your CIRCUITPY/lib folder should contain the following folders and files:

  • /adafruit_bitmap_font
  • /adafruit_display_text
  • adafruit_pixelbuf.mpy
  • neopixel.mpy

Additionally, a font file, tom-thumb.pcf, is included. This font will be utilized in both examples.

CIRCUITPY

Basic Scrolling Text Example

# SPDX-FileCopyrightText: Copyright (c) 2022 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import neopixel
from adafruit_display_text.bitmap_label import Label
from adafruit_bitmap_font import bitmap_font
from displayio import Bitmap
from rainbowio import colorwheel

font = bitmap_font.load_font("tom-thumb.pcf", Bitmap)
label = Label(text="Hello World!!  Adafruit QT Py RP2040 + NeoPixel BFF  ", font=font)
bitmap = label.bitmap

pixels = neopixel.NeoPixel(board.A3, 5*5, brightness=.07, auto_write=False)
pixels.fill(0)
pixels.show()
colors = [0, 0]
hue = 0
while True:
    for i in range(bitmap.width):
        # Use a rainbow of colors, shifting each column of pixels
        hue = hue + 7
        if hue >= 256:
            hue = hue - 256

        colors[1] = colorwheel(hue)
        # Scoot the old text left by 1 pixel
        pixels[0:20] = pixels[5:25]

        # Draw in the next line of text
        for y in range(5):
            # Select black or color depending on the bitmap pixel
            pixels[20+y] = colors[bitmap[i,y]]
        pixels.show()
        time.sleep(.1)

Once everything is saved to the CIRCUITPY drive, you'll see your 5x5 NeoPixel grid scroll the text "Hello World!! Adafruit QT Py RP2040 + NeoPixel BFF" in rainbow colors.

You can edit the scrolling text by updating the text property of label.

label = Label(text="Hello World!!  Adafruit QT Py RP2040 + NeoPixel BFF  ", font=font)

The code begins by instantiating the label text object and the pixels NeoPixel object. In the loop, the text scrolls continuously across the grid. The text is scrolled by moving the y coordinate of the text by 1.

Fancy Scrolling Text Example

# SPDX-FileCopyrightText: Copyright (c) 2022 Jeff Epler for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import board
import neopixel
import fontio
from adafruit_display_text.bitmap_label import Label
from adafruit_bitmap_font import bitmap_font
from displayio import Bitmap
from rainbowio import colorwheel

tom_thumb = bitmap_font.load_font("tom-thumb.pcf", Bitmap)

_glyph_keys = ['bitmap', 'tile_index', 'width', 'height', 'dx', 'dy', 'shift_x', 'shift_y']
def patch_glyph(base, **kw):
    d = {}
    for k in _glyph_keys:
        d[k] = kw.get(k, getattr(base, k))
    return fontio.Glyph(**d)

class PatchedFont:
    def __init__(self, base_font, patches):
        self.base_font = base_font
        self.patches = patches

    def get_glyph(self, glyph):
        g = self.base_font.get_glyph(glyph)
        patch = self.patches.get(glyph)
        if patch is not None:
            print("patching", repr(chr(glyph)), g)
            g = patch_glyph(g, **patch)
            print("patched", g)
        return g

    def get_bounding_box(self):
        return self.base_font.get_bounding_box()

font = PatchedFont(tom_thumb,
    {
        32: {'shift_x': 1, 'dx': 0},
        105: {'dx': 0, 'shift_x': 2},
        33: {'dx': 0, 'shift_x': 2},
    })

label = Label(text=" adafruit!    ", font=font)
bitmap = label.bitmap

heart_bitmap = [
    0,1,1,0,0,
    1,1,1,1,0,
    0,1,1,1,1,
    1,1,1,1,0,
    0,1,1,0,0,
]

pixels = neopixel.NeoPixel(board.A3, 5*5, brightness=.06, auto_write=False)

while True:
    for hue in range(0, 255, 3):
        color = colorwheel(hue)
        pixels[:] = [pixel * color for pixel in heart_bitmap]
        pixels.show()
        time.sleep(.01)

    hue = 0
    for i in range(bitmap.width):
        # Use a rainbow of colors, shifting each column of pixels
        hue = hue + 7
        if hue >= 256:
            hue = hue - 256

        color = colorwheel(hue)

        # Scoot the old text left by 1 pixel
        pixels[:20] = pixels[5:]

        # Draw in the next line of text
        for y in range(5):
            # Select black or color depending on the bitmap pixel
            pixels[20+y] = color * bitmap[i,y]
        pixels.show()
        time.sleep(.1)

Once everything is saved to the CIRCUITPY drive, you'll see your 5x5 NeoPixel grid scroll a heart shape followed by the text "adafruit!".

The code begins by adjusting the tom-thumb font file with PatchedFont. The "i" and "!" characters and space are made narrower is so it looks a little better.

Then, the text and heart sprite shape are instantiated, followed by the pixels NeoPixel object.

In the loop, the heart sprite cycles through a colorwheel rainbow color cycle and then the text scrolls on the grid. The text is scrolled by moving the y coordinate of the text by 1.

This guide was first published on Nov 29, 2022. It was last updated on Nov 29, 2022.

This page (CircuitPython) was last updated on Mar 31, 2023.

Text editor powered by tinymce.