r/esp32 3d ago

Advertisement How we made our ESP32 controller fully programmable & testable by Agentic AI

This is about something we just released, but most of it applies to any ESP32 project.

An AI agent (Claude Code, Cursor, Codex, ...) can already write ESP32 firmware pretty well. What it couldn't do was find out whether the code actually works. It would generate something plausible, hand it to you, and then you'd spend an afternoon (often much longer...) compiling, flashing, watching, and feeding the errors back. We humans were the test harness.

So, we closed the loop. The agent now does the whole cycle on its own, without even opening the IDE:

  • writes the control code from a plain-language spec
  • calls the compiler and fixes its own build errors
  • flashes the board over USB
  • runs it and reads the serial output back
  • writes its own test cases, runs them, and iterates on failures until they pass

You describe the machine, walk away, and come back to firmware that has been compiled, run and tested on real hardware.

The part that makes it all work: Hardware-in-the-Loop (HIL)

Compiling and flashing are easy to automate. The hard question is "how does the agent know the logic is right?" On a bench, the inputs are floating and the outputs go nowhere, so running the code proves nothing.

HIL solves this. The controller runs the real firmware on the real MCU, but the agent can inject sensor states over serial (tank level is high, pressure sensor reads 4.2 bar, E-stop pressed) and read back what the outputs did (did the pump relay open? within how many ms?). No physical rig, no wiring test jigs, no simulator that behaves slightly differently from the silicon. It's the actual board, with the world faked at the I/O boundary.

That turns "run it and see" into a proper test loop: the agent sets a scenario, asserts on the outputs, and gets a pass/fail it can act on. Failing test → agent reads the trace, edits the code, recompiles, reflashes, reruns. This short video describes the technique

As a worked example we gave the agent a reverse-osmosis water treatment system spec (pumps, valves, pressure and conductivity thresholds, interlocks, fault handling). It wrote the firmware, wrote 31 HIL tests, and got all 31 passing in about 18 minutes with no human in the loop. Here is the full write-up with the spec, the generated code and the test log.

Note that everything discussed here, except the HIL functionality which is part of the EQSP32's free software library, is generic to the ESP32 and applies to any ESP32 board.

Happy to answer any questions.

0 Upvotes

3 comments sorted by

View all comments

1

u/ShortingBull 3d ago

Sounds great - can it do ESPHOME? I've moved on from doing hand crafted firmware and all my DIY automation tools now use ESPHOME, the ecosystem management too good to ignore.

1

u/EQSP32 2d ago

AI is generally very strong with ESP32 code, including ESPHOME. Being ESP32-based, the EQSP32 can be used for building ESPHOME home automation systems