PM_K-1 CircuitPython: fix MemoryError + red/blue swap (from on-board test)

On hardware the app rendered, beeped and took input, then died with MemoryError at
the text Bitmap alloc — the two ~37KB base64 font strings stayed pinned in RAM. Move
the fonts to small binary files read at boot (font_m.bin / font_l.bin), drop the
base64 + binascii, and gc.collect() before each text bitmap. code.py 56KB -> 20KB and
RAM use drops ~37KB+. Also: cyan rendered as yellow (R/B swapped) -> MADCTL 0x40 -> 0x48.
Bundle + README updated to include the font blobs. (LED still needs the neopixel lib.)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Me Here 2026-05-28 21:30:03 -05:00
parent 2c40baec58
commit 111da49b5a
6 changed files with 15 additions and 14 deletions

View file

@ -39,7 +39,7 @@ pathlib.Path("dist/pico-main.py").write_text(pathlib.Path("pico/main.py").read_t
print("copied pico-main.py")
import zipfile # PM_K-1 CircuitPython drive bundle (download → unzip onto CIRCUITPY)
with zipfile.ZipFile("dist/pm_k1_circuitpy.zip", "w", zipfile.ZIP_DEFLATED) as z:
for f in ("code.py", "programs.json", "README.md"):
for f in ("code.py", "programs.json", "font_m.bin", "font_l.bin", "README.md"):
z.write("pico-cp/" + f, f)
print("zipped pm_k1_circuitpy.zip")
PY

View file

@ -15,9 +15,10 @@ same programstring language as <https://metronome.varasys.io>.
1. **Flash CircuitPython:** hold **BOOTSEL**, plug in, and drop the CircuitPython `.uf2` for your board
onto the `RPIRP2` drive (<https://circuitpython.org/board/raspberry_pi_pico/> — or the Pico 2 / W
build). It reboots and a **`CIRCUITPY`** drive appears.
2. **Copy the files** onto `CIRCUITPY` (draganddrop — it's a normal drive now):
2. **Copy everything from the bundle** onto `CIRCUITPY` (draganddrop — it's a normal drive now):
- `code.py` (this firmware — runs on boot)
- `programs.json` (your grooves)
- `font_m.bin`, `font_l.bin` (the antialiased fonts — kept as files to save RAM)
3. It starts immediately. Editing `programs.json` (or resaving it from the editor) makes CircuitPython
**autoreload** with the new tracks.
@ -39,7 +40,7 @@ Each `prog` is a program string from the web editor. Add/replace entries and sav
## Calibration (flip flags at the top of `code.py`)
- **Red/blue swapped:** change `MADCTL = 0x40` to `0x48`.
- **Red/blue swapped:** flip `MADCTL` between `0x48` (default) and `0x40`.
- **Colours look negative:** toggle `INVERT_COLORS`.
- **Taps land wrong:** set `TOUCH_DEBUG = True`, watch the serial output, then set
`TOUCH_SWAP_XY` / `TOUCH_INVERT_X` / `TOUCH_INVERT_Y`.

File diff suppressed because one or more lines are too long

BIN
pico-cp/font_l.bin Normal file

Binary file not shown.

BIN
pico-cp/font_m.bin Normal file

Binary file not shown.