# NEÓN + BIOMA: two 1080p firmwares for a US$15 ESP32-P4

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23135766.svg)](https://doi.org/10.5281/zenodo.23135766)

**English** · [Español](#español)

By [Francisco Aldunate](https://franciscoaldunate.cl) · Talca, Chile · September 2026

Two firmwares that push the ESP32-P4 (Wireless-Tag WT9932P4-TINY, chip v1.0) to 1080p with **no GPU**, both connected to the PC by a single USB-C cable. The P4 shows up on the PC as a 1080p UVC webcam and as a network card serving a control page.

| | |
|---|---|
| <img src="docs/neon.jpg" alt="NEÓN neon racing game frame"> | <img src="docs/bioma.jpg" alt="BIOMA Physarum colony"> |
| **NEÓN**: a neon racing game that runs entirely on the chip. The PC is just the "TV" and the controller. *(frame captured from the real P4)* | **BIOMA**: a living wallpaper with 200,000 Physarum agents that evolves by itself. *(frame captured from the real P4)* |

## Measured on the real P4 (not estimated)

| | NEÓN | BIOMA |
|---|---|---|
| Frame rate | **24 fps at 1080p** (12 in v1) | **13–14 fps at 1080p** (7 in v1) |
| CPU core 0 / core 1 | 86 / 92 % | 100 / 98 % |
| JPEG encoder / PPA | 100 % / 92 % | 52 % / 30 % |
| Boot | 3.0 s | 1.7 s (was 40 s) |

**NEÓN** splits the work like a PS2:
- **Core 0** runs physics, laps, the ghost car, the controls WebSocket, USB and the network.
- **Core 1** draws the full 960×540 frame with a per-pixel "shader" in C.
- **The PPA** scales it ×2 to 1920×1080 while the next frame is being drawn.
- **The JPEG encoder** feeds the webcam.
- **The LP core** tints the city with the time of day.

**BIOMA**:
- simulates 200,000 agents;
- picks its own evolution using the size of a JPEG as the judge of "how interesting" a frame is;
- has a day/night palette and a futuristic 12-hour clock.

<p align="center"><img src="docs/bioma_reloj_noche.jpg" alt="BIOMA with the 12-hour clock, captured from the P4 over Wi-Fi" width="49%"> <img src="docs/bioma_evolucion.jpg" alt="BIOMA evolution over time" width="49%"></p>

## What it taught me about the P4 (so you don't repeat it)

- **Never write frames into PSRAM with the CPU.**
  - Write-allocate makes it read every cache line before writing it; the morning estimate was off by 3×.
  - Draw in tiles in internal RAM and copy them with `esp_async_memcpy` (AXI GDMA). NEÓN went from 82 ms to ~40 ms per frame.
- **No `expf`/`sinf` per pixel or per frame.** Use tables: game logic went from 8.4 ms to 0.18 ms.
- **`esp_random()` costs ~65 µs per call.** 600,000 calls meant a 40 s boot; seeding a xorshift once brought it to 1.7 s.
- **Task priorities.** With both cores at 100 %, the task sending video to the browser must sit **above** the simulation: browser video went from 0.85 to 8.5 fps.
- **BIOMA's agent step is compute-bound** (~200 cycles per agent). Two optimizations that failed, measured: 6-byte agents (−2 %) and sorting agents by row (0 %).
- **Test the logic in plain C on the PC first.** Each firmware has a `host_test/` that builds with gcc. It caught ghost lines from seeding with `% N`, a colony collapse and a stuck autopilot before touching the chip.

## Contents

| Folder | What it is |
|---|---|
| `neon-fw/` | NEÓN firmware (ESP-IDF v6.1) + `host_test/` with a version you can play on the PC (`play_pc.py`) |
| `bioma-fw/` | BIOMA firmware + `host_test/` with the evolution experiments |
| `proto/` | Python prototypes of both (`neon_pc.py`, `bioma_pc.py`) |
| `tools/` | `cambiar_firmware.py` (switch firmware over OTA through the USB network without risking the previous one), `grabar_log.py` (read the log without a serial port), `probar_controles.py` |

Each firmware has its own detailed README (in Spanish) with the measurements and how to build it. Precompiled binaries are in the [releases](../../releases).

## Author

**Francisco Aldunate Rodríguez** · ESP32 firmware (P4, S3, C3) · [franciscoaldunate.cl](https://franciscoaldunate.cl) · [@franciscoaldun](https://github.com/franciscoaldun)

Related: [Cerebro P4](https://github.com/franciscoaldun/cerebro-p4) (AI webcam) · [Tierra Viva P4](https://github.com/franciscoaldun/tierra-viva-p4) (hardware stress test) · [ESP32-C3 in Logisim](https://github.com/franciscoaldun/esp32c3-logisim)

---

## Español

Dos firmwares que llevan el ESP32-P4 (WT9932P4-TINY, chip v1.0) a 1080p **sin GPU**, conectados al PC por un solo cable USB-C. El P4 aparece en el PC como webcam UVC 1080p y como tarjeta de red con una página de control.

- **NEÓN**: un juego de carreras de neón que corre entero en el chip. Va a **24 fps a 1080p** y usa la CPU 86/92 %, el JPEG al 100 % y el PPA al 92 %. El PC es solo la «tele» y el control (teclado o joystick por WebSocket en `http://192.168.7.1`).
- **BIOMA**: un fondo de pantalla vivo de 200.000 agentes Physarum que evoluciona solo, con el tamaño de un JPEG como juez. Va a **13-14 fps a 1080p**, con paleta día/noche y reloj de 12 h.

Lo aprendido, medido:
- No escribir cuadros en la PSRAM con la CPU; usar baldosas en RAM interna + `esp_async_memcpy`.
- Tablas en vez de `expf`/`sinf`.
- `esp_random()` tarda ~65 µs por llamada: sembrar un xorshift.
- El video para la web va con prioridad mayor que la simulación.
- Probar la lógica en C puro en el PC (`host_test/`) antes de flashear.

Cada carpeta tiene su README con las mediciones y cómo compilar. Los binarios probados están en los [releases](../../releases).

**Francisco Aldunate Rodríguez** · [franciscoaldunate.cl](https://franciscoaldunate.cl) · Licencia [MIT](LICENSE).
