New pico-cp/ — a CircuitPython port of the PM_K-1 firmware so the Pico mounts as a
CIRCUITPY drive carrying its code + tracks (the MicroPython pico/main.py stays the
simple fallback):
- pico-cp/code.py: displayio BusDisplay driving ST7796 via a custom init_sequence;
smooth anti-aliased text via displayio Bitmap+Palette (reuses the baked font blobs);
vectorio rects for dots/buttons; DIY GT911 touch (16-bit regs, edge-detected);
pwmio buzzer, analogio joystick, digitalio buttons, optional neopixel RGB; the
polymeter engine on a time.monotonic_ns scheduler. Reads /programs.json (falls back
to baked defaults); CircuitPython auto-reloads on file change.
- pico-cp/programs.json: the 23 default grooves. pico-cp/README.md: flash + calibrate.
- build.sh/deploy.sh: bundle + serve /pm_k1_circuitpy.zip. info-kit.html: experimental
'CircuitPython edition — USB drive' section.
Verified in CPython (stubbed displayio): init sequence well-formed, parser handles the
grooves incl. (3,8) euclid + @-4 gain, and code.py's actual make_text renders identical
smooth AA text. Hardware bits (panel/touch/MIDI) await on-board testing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
2.9 KiB
Markdown
55 lines
2.9 KiB
Markdown
# PM_K‑1 "Kit" — CircuitPython edition (USB drive + editor)
|
||
|
||
The **CircuitPython** firmware for the 52Pi EP‑0172 Pico kit. Unlike the MicroPython version
|
||
(`../pico/main.py`), this makes the Pico mount as a **USB drive (`CIRCUITPY`)** that carries the
|
||
firmware and your tracks — so you can edit on the web and reprogram it without Thonny. It runs the
|
||
same program‑string language as <https://metronome.varasys.io>.
|
||
|
||
> **Status: experimental, phase 1.** This drives the screen/touch/joystick/buzzer and reads your
|
||
> grooves from `programs.json`. The editor's one‑click "Save to device" and USB‑MIDI audio‑to‑computer
|
||
> are landing in later phases. The simpler **MicroPython** firmware (`../pico/main.py`) remains the
|
||
> rock‑solid fallback — and the Pico can't be bricked (BOOTSEL → drag a MicroPython `.uf2` back).
|
||
|
||
## Install
|
||
|
||
1. **Flash CircuitPython:** hold **BOOTSEL**, plug in, and drop the CircuitPython `.uf2` for your board
|
||
onto the `RPI‑RP2` 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` (drag‑and‑drop — it's a normal drive now):
|
||
- `code.py` (this firmware — runs on boot)
|
||
- `programs.json` (your grooves)
|
||
3. It starts immediately. Editing `programs.json` (or re‑saving it from the editor) makes CircuitPython
|
||
**auto‑reload** with the new tracks.
|
||
|
||
## Controls (same as the MicroPython build)
|
||
|
||
- **Touch:** on‑screen `◀◀ / ▶ / ▶▶` (prev · play/stop · next) and `− / TAP / +`.
|
||
- **Joystick:** up/down = tempo, left/right = previous/next groove.
|
||
- **Button A (GP15)** play/stop · **Button B (GP14)** tap tempo.
|
||
- **RGB LED** flashes each beat; **buzzer** clicks (accent/normal/ghost).
|
||
|
||
## programs.json
|
||
|
||
```json
|
||
{ "title": "PolyMeter",
|
||
"programs": [ { "name": "Four on the floor", "prog": "t120;kick:4;snare:4=.x.x;hatClosed:4/2" } ] }
|
||
```
|
||
|
||
Each `prog` is a program string from the web editor. Add/replace entries and save — the device reloads.
|
||
|
||
## Calibration (flip flags at the top of `code.py`)
|
||
|
||
- **Red/blue swapped:** change `MADCTL = 0x40` to `0x48`.
|
||
- **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`.
|
||
- **Joystick reversed:** toggle `JOY_INVERT_X` / `JOY_INVERT_Y`.
|
||
- **Screen blank / garbled:** the panel lot may differ; drop `SPI_BAUD`, and if it's a 240×320 ILI9341
|
||
instead of the 320×480 ST7796, the init/size need changing (this targets the 320×480 you have).
|
||
- **No RGB LED:** the WS2812 needs the `neopixel` library on `CIRCUITPY/lib` (`circup install neopixel`)
|
||
— everything else works without it.
|
||
|
||
If `code.py` ever errors, CircuitPython prints the traceback **on the screen and over USB serial** —
|
||
copy that to me and I'll fix it.
|
||
|
||
The fonts are the same baked anti‑aliased blobs as the MicroPython build (see `../pico/gen_font.py`).
|