Skip to content

Flashing the ESP32 Firmware

Dilf edited this page Feb 17, 2026 · 1 revision

The ESP32 firmware is written in C++ using the Arduino framework and managed with PlatformIO. Flashing is done from your development machine — the Raspberry Pi connects to the ESP32 only as a serial client and is not involved in the flash process.

Prerequisites

  • PlatformIO installed on your development machine (VS Code extension or CLI)
  • USB-C cable connected from your development machine to the ESP32 (data cable — not charge-only)
  • The repo cloned on your development machine

How It Works

The firmware lives in firmware/src/. PlatformIO uses platformio.ini to know the board type, upload speed, and which libraries to include. When you run pio run --target upload, PlatformIO compiles the project and flashes the binary directly to the ESP32 over USB.

After a flash, the ESP32 resets automatically. The Pi daemon detects the reset (serial connection drops briefly), closes the port, and reopens it once the ESP32 finishes booting — no manual reconnection or daemon restart needed.


Firmware Source Files

File Purpose
firmware/src/main.cpp Main program loop, PID controller, serial command parser, safety logic
firmware/src/pinControl.cpp / .h HeaterControl and ExhaustFanControl hardware driver classes
firmware/src/tachometer.cpp / .h RPM measurement from the exhaust fan tachometer pin
firmware/platformio.ini Board config, upload baud rate, library dependencies

Updating Only the Firmware (no hardware changes)

If you're just tuning PID gains or adjusting limits without touching anything else, the quickest workflow is:

# 1. Edit the constants in main.cpp
nano firmware/src/main.cpp

2. Unplug ESP32 from Pi, plug into dev machine, flash

cd firmware && pio run --target upload

3. Verify via Serial Monitor, then reconnect to Pi

pio device monitor --baud 115200

send PING, GET STATUS, Ctrl+C when done

4. Reconnect to Pi and confirm daemon picks it up

ssh pi@octopi.local "sudo journalctl -u enclosure-daemon -n 10 --no-pager"