voltergeist

Cable receiver: a Pico 2 W and an MCP4728

This page is firmware/pico/README.md from the repository.

A browser page (web/serial.html) sends voltergeist frames over a USB cable to a Raspberry Pi Pico 2 W (RP2350). The Pico decodes them with c/voltergeist.h, plays them out on its own clock a fixed delay later, and writes four 12 bit codes to an MCP4728 over I2C. Gates from EVENTS go to four GPIOs. No Pi, no network, nothing allocated.

Written and built on 2026-12-06 before the Pico or the board was on the desk: everything below the line "What needs the real Pico" was measured in a container and in headless Chrome, not on hardware.

Files

filewhat
vgrx.h, vgrx.cthe receiver with no platform in it: byte stream in, Multi-Write, gates, PONG, REPORT and status out
main.cthe Pico: TinyUSB CDC, i2c0, the 1 kHz repeating timer, the LED
usb_descriptors.c, tusb_config.hone CDC serial port, 2E8A:0009, named "voltergeist receiver"
CMakeLists.txtpico-sdk 2.x project, PICO_BOARD=pico2_w
host-test.cvgrx.c on Linux with a fake clock, fake I2C, fake serial and fake gate pins
make-vector.mjs, vector.hthe stream the host test feeds, made by the page's own code (web/serial.mjs), and the DAC writes src/mcp4728.mjs makes for it
check-page.mjsweb/serial.html in headless Chrome, with a fake serial port
build.sh, build-inside.shthe container build: host test, sabotage, firmware

vgrx.h includes ../../c/voltergeist.h by a relative path; nothing is copied.

What the firmware does

Concurrency: the main loop runs TinyUSB and feeds bytes; the timer IRQ plays out and writes I2C. A hardware spin lock guards the streams; the I2C write happens outside it.

Where it differs from src/receiver.mjs

The page

web/serial.html (Chrome or Edge on a desktop; it says so elsewhere). Connect asks for the port (filtered to 2E8A:0009; ?any lists every port), drops and raises DTR, then:

It pings the Pico 4 times a second, sends CLOCK every second, and shows the round trip, the Pico's status and its REPORTs (lost, late, late fired, recovered, jitter). Delay (default 40 ms, 80 for a relay) is what the page asks for; the part above the firmware's 20 ms is added to the offset in each CLOCK.

Build (in a container, never on the Mac)

sh firmware/pico/build.sh          # host test, sabotage, firmware
sh firmware/pico/build.sh host     # or one of host, sabotage, pico
node firmware/pico/make-vector.mjs # after changing web/serial.mjs's test source (--check says whether it is stale)
node firmware/pico/check-page.mjs  # the page in headless Chrome (--sabotage must fail)

build.sh runs a throwaway alpine container, installs the toolchain (gcc, cmake, arm-none-eabi-gcc 16.2, newlib, linux-headers for picotool) into a 6 GB RAM disk and runs it there through chroot, so the toolchain never touches a disk. Two reasons: this Mac kills binaries compiled on it, and on 2026-12-06 the OrbStack VM had 148 MB free and the Mac 2 GB, too little for a Debian image with the toolchain installed. The only things written to the repository's disk are the pico-sdk 2.3.1 checkout (shallow, tinyusb and cyw43-driver only) and the picotool build, 90 MB together in firmware/.cache (git-ignored), and the output in firmware/pico/build.

Measured 2026-12-06, OrbStack on an M-series Mac, arm64 container:

result
firmwarebuild/voltergeist-rx.uf2, 600,064 bytes (1,172 UF2 blocks, family RP2350 ARM-S plus the SDK's E10 workaround block); text 303,808 bytes (most of it the CYW43 firmware the LED needs), bss 135,628 bytes of the 520 KB RAM
compiler warnings0, with -Wall -Wextra on the target
host test30 of 30
sabotage5 of 5 caught
page check24 of 24; with --sabotage 2 fail as they must

The host test

host-test.c feeds vector.h through vgrx_feed in random chunks of 1 to 64 bytes, ticks every 1 ms, and checks:

build.sh sabotage breaks one thing at a time in a copy of vgrx.c and requires the test to fail: the Multi-Write command byte (2 checks fail), half the delay (5), PONG's t0 and t1 swapped (2), late samples not counted (1), the DAC staying on a stream that went quiet (1).

The page check

check-page.mjs serves the repository with web/serve.mjs, opens web/serial.html in headless Chrome (muted, temp profile, both removed at the end) and checks: no exception; the page's own code makes the 11,678 bytes of vector.h exactly; without Web Serial it says what is needed and Connect is off; with a fake port and a fake Pico answering PONG, REPORT and status: DTR dropped and raised, both MAPs before the first SAMPLES, SAMPLES at 99.9 frames a second with no seq gap, gates, PINGs, a CLOCK within 0.05 ms of the fake Pico's offset + 20 ms, the status and REPORT shown, a clean disconnect; in relay mode through the local relay, send.html's frames forwarded with a per-stream CLOCK of both legs (0.25 ms from the expected value) and none for stream 0.

What needs the real Pico and board

Nothing below has run yet:

Flashing

  1. Hold BOOTSEL on the Pico 2 W and plug it into USB; it appears as a drive called RP2350.
  2. Copy firmware/pico/build/voltergeist-rx.uf2 onto it. The Pico reboots into the firmware and the drive goes away.
  3. The LED gives a short blink once a second: it is waiting for frames.

Wiring the Electrokit board (EKM016) to the Pico

Pico 2 W pinsignalboard pin
36, 3V3 OUT3.3 V supply, and the full scale with the VDD referenceVCC
38 (or any GND)groundGND
6, GP4I2C0 SDASDA
7, GP5I2C0 SCLSCL
21, 22, 24, 25: GP16 to GP19gates for EVENTS channels 0 to 3, 3.3 V logic(not on the board)

LDAC and RDY stay unconnected (UDAC 0, no EEPROM writes). Stay on 3V3: on 5 V the board's pull-ups would put 5 V on the Pico's pins. The outputs give 0 to 3.3 V; Eurorack levels need an op-amp stage (hardware/README.md).

In the browser

  1. Chrome or Edge on a desktop. Serve the repository (node web/serve.mjs) and open http://127.0.0.1:8091/web/serial.html.
  2. Press Connect Pico and pick "voltergeist receiver". The Pico panel shows I2C idle within a second.
  3. Leave Source on test signal and press Start. Within a second the round trip shows, the Pico panel shows I2C ok and DAC writes climbing, the Reports table shows a row with lost 0 and late 0, and the LED stays on. I2C error means the board is not answering at 0x60: check the four wires.
  4. For a stream from elsewhere, pick relay room, give the relay and room the sender uses, press Start, and start send.html (or tools/send.mjs) into that room.
  5. Keep the tab in front: a background tab's timers slow to about once a second and every frame arrives late.

Measured on a real Pico 2 W (2026-12-06)

Plugged into the Raspberry Pi 4 (positron's board) by USB, no MCP4728 attached yet. The stock program it held answered a 1200 baud open by rebooting into BOOTSEL (stty -F /dev/ttyACM0 1200), so it was flashed with no button: mount the RP2350 drive, copy voltergeist-rx.uf2. It enumerated as 2e8a:0009 voltergeist voltergeist receiver on /dev/ttyACM0. node firmware/pico/pi-test.mjs on the Pi, 15 s of the 4-channel test signal at 1 kHz plus a gate:

samples sent14,992
lost, late (its REPORT)0, 0
jitter (its REPORT)0.4 ms
round trip over USB serial, 29 pings0.34 ms min, 0.51 ms median
frames handled, rejected, skipped, stale5,276, 0, 0, 0
i2cerror on every write: no board yet, as expected

The firmware now also reboots into BOOTSEL on a 1200 baud open (tud_cdc_line_coding_cb), so after this build is on the Pico it can be reflashed from the host with no button. Done and checked the same day: one BOOTSEL press put this build on, then stty -F /dev/ttyACM0 1200 dropped it into BOOTSEL and it was reflashed over ssh with nobody touching it; the test above read the same again (0 lost, 0.33 ms min round trip).

Measured from Chrome on the studio Mac (2026-12-06)

The Pico on the M1 through a USB hub, https://voltergeist.positron.studio/tools/serial in Chrome, test signal: ThreatLocker on that Mac let Chrome open the port (2e8a:9). 887 frames out, 166 kB; round trip 0.59 ms; the Pico handled 947 frames, 0 rejected, skipped, stale or oversize; its REPORTs on both streams 0 lost, 0 late, jitter 1.67 ms (samples) and 1.23 ms (gate); i2c=error, no board yet. The page's "Pico clock offset" cell shows the raw offset between the browser's epoch clock and the Pico's boot clock (about -1.8e9 s), which is right but unreadable.