velxio/examples
David Montero Crespo d4d015c25d perf(spi): batch SPI bytes per WS message — ~50× faster TFT in emulator
User reported the ESP32-CAM + ILI9341 live preview at ~1 frame/min.
Profile: 80×60 preview pushes 9600 SPI bytes per drawRGBBitmap, and
each byte was emitting a full {type:'spi_event'} JSON message over
the worker→backend→WS→frontend pipeline. Per-byte overhead ~150-200µs
in Python (json.dumps + sys.stdout.write+flush dominates) plus
asyncio + WS dispatch. Net: 1.5-2 sec/frame minimum, much worse with
GIL contention.

Fix: buffer MOSI bytes in the worker and emit a single base64-encoded
`spi_batch` message when CS goes HIGH (transaction ended) or the
buffer crosses 4 KiB. ~9600 events/frame collapse to ~3 messages.

  backend/app/services/esp32_worker.py:_on_spi_event
    - Add _spi_byte_buf bytearray + threading.Lock
    - On op==0x00 (byte): append; flush early if buf >= 4096
    - On op==0x01 (CS change): flush buffer, then emit the CS event
      via the legacy spi_event channel (ePaper / custom chips that
      observe CS still get it).

  frontend/src/simulation/Esp32Bridge.ts
    - New 'spi_batch' message handler decodes b64 and replays each
      byte through the existing onSpiByte callback. Parts that
      subscribed via simulator.spi.onByte don't notice the protocol
      change. The 'spi_event' branch still handles CS changes plus
      legacy single-byte payloads for backwards compat.

Now that 38 KB/frame is cheap, restore preview to 160×120 + JPEG
quality 0.35 in the gallery example. Real measured speedup: ~50× on
the QVGA preview demo. Real hardware was never affected — it runs
SPI at 80 MHz and pushes the bitmap in ~4 ms either way.

PSRAM emulation is unrelated to this bottleneck and was left untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 00:25:06 -03:00
..
esp32-cam-lcd-preview perf(spi): batch SPI bytes per WS message — ~50× faster TFT in emulator 2026-05-03 00:25:06 -03:00
README.md docs(examples): add ESP32-CAM + ILI9341 live preview example 2026-05-02 22:14:42 -03:00

README.md

Velxio examples

Ready-to-run sketches that exercise specific Velxio features end-to-end. Each subdirectory ships:

  • *.ino — the sketch (paste into Velxio's editor)
  • diagram.json — wiring layout (parts + connections, Wokwi-compatible format)
  • libraries.txt — Arduino libraries to install via Library Manager
  • README.md — wiring picture, run instructions, what to expect

Index

Folder Board Demonstrates
esp32-cam-lcd-preview/ ESP32-CAM + ILI9341 Live webcam preview decoded with jpg2rgb565 and rendered to a 320×240 SPI TFT

Adding a new example

  1. Create a folder named after the demo (e.g. arduino-uno-pong-rgb/).
  2. Drop in the four files above.
  3. Wire diagram.json using the velxio/wokwi part types — see existing examples for naming. Velxio-specific boards use the velxio- prefix (velxio-esp32-cam); generic Wokwi parts use wokwi- (wokwi-ili9341, wokwi-led, etc.).
  4. Add a row to the table above.

If your example needs more than the standard libraries, list every required library in libraries.txt (one per line, # for comments).