Replace MicroPython runtime with Pico C + W5500 firmware.

Ship UDP RGB panel firmware (eight WS2812 strips) and drop the ESP32 Wi-Fi/MicroPython stack.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-01 21:52:52 +12:00
parent 45a38c05b7
commit f7beac2095
66 changed files with 1601 additions and 7376 deletions

113
README.md
View File

@@ -1,52 +1,75 @@
# LED Driver — MicroPython
# Portal panel firmware (Pico + W5500 + WS2812)
MicroPython LED driver for ESP32: presets, patterns, **Wi-Fi** (TCP + UDP discovery) or **ESP-NOW** transport, optional HTTP polling, and dynamic pattern modules under `src/patterns/`.
UDP RGB panel adapter for the [portal](https://git.technical.kiwi/technicalkiwi/portal.git) project.
Host renders patterns; this firmware only receives frames on **UDP 50007**.
## Prerequisites
## Layout
- MicroPython firmware on the ESP32
- USB cable for programming
- Python 3 with pipenv (on the host, for `dev.py` / tests)
## Setup
1. Install dependencies:
```bash
pipenv install
```
2. Deploy to the device:
```bash
pipenv run dev
```
## Project layout
```
led-driver/
├── src/
│ ├── main.py # Entry: Wi-Fi/TCP or ESP-NOW path, process_data(), manifest OTA
│ ├── presets.py # Preset runtime + Presets class
│ ├── preset.py # Single preset helpers
│ ├── settings.py # settings.json
│ ├── hello.py # UDP discovery (port 8766) / hello payloads
│ ├── http_poll.py # Optional HTTP polling helper
│ ├── utils.py # Colour conversion / ordering
│ ├── presets.json # Default preset file (on device)
│ └── patterns/ # Pattern modules (.py), loaded dynamically
├── tests/ # Host-side helpers (e.g. udp_client.py, test_mdns.py)
├── test/ # On-device style pattern tests (all.py, patterns/)
├── dev.py # Deploy / sync to serial device
├── docs/API.md # Wire format (long keys); Pi app docs short keys
├── msg.json # Sample message
├── Pipfile
└── LICENSE
```text
led-driver-8/
├── firmware/ # Pico SDK C + W5500
├── examples/test_strips.py
├── .env.example
└── README.md
```
**Transport:** `settings.json` **`transport_type`** is typically **`wifi`** (TCP to the Pi on port **8765**, discovery on **8766**) or **`espnow`**. ESP-NOW code paths are loaded only when needed so a Wi-Fi-only image stays smaller.
## Hardware
## Further reading
| Signal | GPIO |
|--------|------|
| W5500 CS | GP13 |
| SPI1 SCK | GP10 |
| SPI1 MOSI | GP11 |
| SPI1 MISO | GP12 |
| W5500 RST | GP9 |
| Status LED | GP25 |
| WS2812 strip 07 | GP18, 19, 20, 21, 22, 26, 27, 28 |
- **`docs/API.md`** — JSON message fields as used in examples (`pattern`, `colors`, …). The Pi app may send **short keys** (`p`, `c`, …); behaviour matches once normalised on device.
Eight strips (one PIO SM each). Pixel output uses **DMA → PIO**. Pixel count comes from each UDP frame. `MAX_LEDS` (512) is capacity only.
## Build / flash
```bash
cd firmware
make deploy PANEL_ID=0
make reset && make monitor
```
Network options live in `.env` (see `.env.example`):
```env
PANEL_ID=0
NETWORK=static
IP=10.1.1.10
NETMASK=255.255.255.0
GATEWAY=10.1.1.1
DNS=10.1.1.1
```
| Panel | IP | MAC last byte |
|-------|-----|---------------|
| 0 | 10.1.1.10 | `00` |
| … | … | … |
| 4 | 10.1.1.14 | `04` |
| 255 (bench) | 10.1.1.19 | `FF` |
## Test
Self-contained (stdlib only):
```bash
python3 examples/test_strips.py
python3 examples/test_strips.py --host 10.1.1.10 --leds 64
```
Lights each strip alone with a unique colour, then flashes all strips R/G/B/white.
## UDP protocol (port 50007)
| Payload | Action |
|---------|--------|
| N×3 bytes | Raw RGB → strip 0 |
| 1 + N×3 bytes | `strip_id` + RGB (`0``7`, or `255` = all) |
| 5 bytes `PIN\0` + gpio | Bind strip 0 |
| 8 bytes `PIN\0` + strip + gpio + len_lo + len_hi | Bind strip |
| 4 bytes `SHOW` | Reserved |