Once you've finished setting up your QT Py RP2040 with CircuitPython, you can access the code, audio files and necessary libraries by downloading the Project Bundle.

To do this, click on the Download Project Bundle button in the window below. It will download to your computer as a zipped folder.

# SPDX-FileCopyrightText: Copyright (c) 2023 Erin St. Blaine for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
from random import randint
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},
                    })

# List of text strings
text_strings = ["     love bun     ", "     dear me     ", "     my bear     ",
                "     my my     ", "     you are babe     "]
# Create a label object
label = Label(text="text", 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.A1, 5*5, brightness=.08, 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(.05)
    hue = 0
    string_index = randint(0, 4)
    label.text = text_strings[string_index]
    bitmap = label.bitmap
    print(string_index)
    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(.2)

Upload the Code and Libraries to the QT Py RP2040

After downloading the Project Bundle, plug your QT Py RP2040 into the computer USB port. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called CIRCUITPY. Unzip the folder and copy the following items to the QT Py RP2040's CIRCUITPY drive. 

  • lib folder
  • code.py
  • tom-thumb.pcf

Your QT Py RP2040 CIRCUITPY drive should look like this after copying the lib folder and code.py file.

CircuitPY

Customizing the Code

This code will show a bitmap of a heart, and then scroll some text chosen randomly from a list of text strings. The messages I've chosen were written by an early AI when it was asked to create sayings for candy valentine hearts. They're pretty wonderful. 

To add your own text strings, look for this section of code:

# List of text strings
text_strings = ["     love bun     ", "     dear me     ", "     my bear     ",
                "     my my     ", "     you are babe     "]

Change them to whatever you'd like, or add more. You can adjust the spaces to change the amount of time between messages.

The heart bitmap is cleverly drawn with 1s and 0s. If you want to tweak it, you can make your own bitmap in ASCII style by turning pixels "on" or "off" in the 5x5 grid. A 1 means the pixel is on, and a 0 means it's off. 

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

Troubleshooting

1. The drive doesn't appear when you plug your QT Py RP2040 into your computer.

This is normal but a little weird because it works differently from the other QT Py boards. You have to hold down the BOOT button while plugging it in, with this board. Start with the board un-powered (i.e. no battery plugged in) and hold down BOOT while you attach the cable. Keep holding it until the drive appears.

2. The code appears to be working but no images or text are appearing

This code assumes we're using pin A1. The board defaults to pin A3 -- we changed this using a solder bridge during assembly. If your assembly method is different, and you soldered headers to the whole board, try changing the code to pin A3 to see if that fixes the problem.

3. Be sure the code you downloaded matches the version of CircuitPython you're running. This is a fast-changing world and new releases are coming out all the time. If you installed CircuitPython 8, be sure you've got the correct code bundle for version 8.

This guide was first published on Feb 07, 2023. It was last updated on Apr 18, 2024.

This page (Software) was last updated on Apr 18, 2024.

Text editor powered by tinymce.