Here I describe how the cocktail machine's controller is built.
The firmware runs on an ESP32 and is written in Rust code. It handles two tasks at the same time: it serves the web interface and drives the stepper motors. Each task runs on its own processor core.
This keeps the motors running smoothly, even while someone is loading the web interface.
mutex protects against simultaneous access. The web server reads it for the display.The interface is a single HTML file built into the firmware. It talks to a small HTTP interface, for example:
Positions, times and drinks are stored as JSON in the flash memory of the ESP32 and survive every restart. New values are clamped to safe limits before saving.
A drink is a list of “slot × portions”. From it, the firmware creates a command sequence for both axes:
(if necessary) home Z → home X →
for each ingredient: X to slot → Sync → per portion: Z up, hold, short return stroke (or pump on) → Sync →
at the end: Z down → homing run → (optional dispensing position).
At each Sync-point the axes wait for each other. Nothing is dosed while the carriage is moving.
Rust (Edition 2021) ESP-IDF (std) esp-idf-svc embedded-svc serde / serde_json anyhow HTML / CSS / vanilla JS
| File | Task |
|---|---|
src/main.rs | Start-up, Wi-Fi, web server, pins |
src/servo.rs | Motor control, safety, pump |
src/settings.rs | Settings and recipe → command sequence |
src/config.rs | Limits for travel, speed and recipes |
src/servo-control-migrated.html | The web interface |