From Empty Sketch to Live Telemetry: 14 Prompts That Turn an LLM Into Your Embedded Co-Pilot for Arduino, ESP32 and STM32
Breadboards lie. A sketch that compiles cleanly can still brown-out an ESP32 the moment Wi-Fi kicks in, and a "simple" voltage divider can put 5 V into a 3.3 V ADC pin. Most of the time you don't lose an evening to writing code — you lose it to the gap between what the datasheet says and what your board actually does.
An LLM is genuinely good at exactly that gap: it has read more datasheets, errata sheets and forum threads than any human. Below are 14 prompts I actually keep in a text file, each tied to a concrete engineering task — firmware, schematic review, power budget, MQTT telemetry, log triage. Copy them, fill the placeholders, and keep the reference links handy: the model will sometimes be confidently wrong, and the datasheet is always right.
1. The Board Brief: force the model to state its assumptions
Before any code, make the model declare what it thinks it knows. This kills half of the hallucinated pin numbers.
You are an embedded engineer. Target: ESP32-DevKitC, ESP-IDF v5.x,
Arduino core 3.x available. Before writing code, output a table:
| assumption | value | source | confidence |
covering: supply voltage, ADC reference, GPIO strapping pins,
flash size, available peripherals. Mark anything you are unsure
about as UNKNOWN, do not guess.
Task solved: surfaces wrong assumptions (e.g. ESP32 ADC is not linear near the rails) before they become a debugging session. Cross-check against the ESP32 datasheet and the Arduino ESP32 core docs.
2. Firmware skeleton with a non-blocking loop
Write a MicroPython program for ESP32 that reads a DHT22 on GPIO4
and a push button on GPIO0 (internal pull-up, active LOW) and
publishes every 30 s. Use machine.Timer or asyncio, never time.sleep
in the main loop. Include debounce (50 ms) and a try/except around
the sensor read that logs and continues. Comment every hardware
assumption.
Task solved: beginners write blocking time.sleep(), which starves Wi-Fi and the watchdog. The prompt forces an event-driven structure. Reference: MicroPython asyncio docs.
3. Decode a compiler error properly
Here is the exact error and the surrounding code:
<paste>. Explain the root cause in one sentence, then give the
minimal diff that fixes it. Do not reformat unrelated lines.
If the error is a linker error, explain which symbol is missing
and which library provides it.
Task solved: undefined reference to Wire is a missing #include <Wire.h>, not a broken toolchain. The "minimal diff" constraint stops the model from rewriting your whole file.
4. Schematic sanity check before you solder
I have an ESP32 (3.3 V logic) driving a 5 V relay module and reading
a 12 V battery through a divider. Review the schematic described
below for: voltage-level mismatch, missing flyback diode, ADC input
range, common ground, and current through the divider.
List every risk as: RISK
| why | fix.
Task solved: catches 5 V into a 3.3 V pin, floating grounds, and dividers that waste battery. Always confirm against the ESP32 hardware design guidelines.
5. Power budget calculator
Build a power budget table for an ESP32 in deep sleep, waking every
10 min, sending an MQTT message for 2 s at 20 dBm TX, driving one
LED. Columns: state
| current (mA) | duration | mAh contribution.
Use typical datasheet values and cite them. Then compute battery life
for a 2000 mAh Li-ion with 80% usable capacity.
Task solved: turns "about a month" into a number you can defend. Deep-sleep current for ESP32 is typically in the tens of microamps — check the datasheet, not the model, for the final figure.
6. MQTT telemetry that Home Assistant actually discovers
Generate an Arduino C++ sketch for ESP32 that publishes DHT22
temperature and humidity over MQTT with Home Assistant MQTT
discovery. Use PubSubClient. Publish retained discovery config to
homeassistant/sensor/<node>/<obj>/config with a unique_id, device
block, and unit_of_measurement. Include LWT (availability topic)
and a reconnect backoff.
Task solved: hand-writing discovery JSON is error-prone. Spec: MQTT Discovery.
7. Explain a protocol frame byte by byte
Here is a hex dump from a logic analyzer: <paste>.
Assume it is I2C. Decode start/stop, address, R/W bit, ACK/NACK,
and register/value pairs. If it is not valid I2C, say so and explain
why (e.g. missing ACK).
Task solved: you don't need to re-learn the I2C spec every time a sensor returns 0xFF. Reference: NXP I2C-bus specification (UM10204).
8. Log triage for a crashing board
ESP32 panics with this backtrace:
<paste>. Identify the exception type (e.g. LoadProhibited,
StoreProhibited, InstrFetchProhibited), the likely cause, and the
line to inspect. Suggest one instrumentation change to confirm.
Task solved: Guru Meditation Error: Core 1 panic'ed (LoadProhibited) almost always means a null or freed pointer. Map the exception to a cause instead of guessing. Reference: ESP32 fatal errors guide.
9. State machine from a plain-English spec
Design a finite state machine for a device with states: BOOT,
CONNECTING, ONLINE, DEGRADED, SLEEP. Transitions driven by Wi-Fi
result, MQTT ack, sensor timeout, and a 10-min idle timer.
Output a transition table and a C enum + switch skeleton.
Task solved: tangled if chains become a reviewable table. This is the single biggest maintainability win on small firmware.
10. Port Arduino code to STM32 (or back)
Port this Arduino sketch to STM32 HAL (STM32F4). Preserve timing and
pin functions. Map analogRead to HAL_ADC, digitalWrite to HAL_GPIO.
List every API that has no direct equivalent and propose a substitute.
Task solved: analogRead() and delay() have no 1:1 HAL equivalent; the prompt makes the model name the gap instead of hiding it. Reference: STM32 HAL docs.
11. OTA update checklist
Give a checklist and minimal code for ESP32 OTA over Wi-Fi using
ArduinoOTA, including: partition scheme, rollback safety,
versioning, and what to do if power is lost mid-update.
Task solved: OTA failures brick devices. The prompt forces you to think about partition tables and rollback before shipping.
12. Test bench in Python
Write a pytest suite that mocks machine.Pin and machine.ADC so I can
test the sensor logic on a laptop without hardware. Show fixtures
and one failing-case test (sensor timeout).
Task solved: most firmware is untested because it needs hardware. Mocking machine lets you test logic in CI. Reference: pytest fixtures.
13. Datasheet interrogation
From this datasheet excerpt: <paste>. Extract: supply range, I2C
address options, max sample rate, register map for start/stop, and
any errata mentioned. Output as a table with page references.
Task solved: turns 80 pages into a 10-row table you can paste into your README. The page references make it verifiable.
14. Explain the "why" for a junior
Explain why this code causes brown-out resets on ESP32 when Wi-Fi
connects, in plain language for a junior, with one diagram in ASCII
and one fix.
Task solved: the brown-out on Wi-Fi TX is a classic — the radio draws a current spike the supply can't deliver. Understanding it beats memorizing a capacitor value.
What actually matters
| Prompt family | Engineering task | Failure it prevents |
|---|---|---|
| Board brief | Assumption audit | Wrong pin/voltage |
| Skeleton + FSM | Structure | Blocking loops, spaghetti |
| Error/log triage | Debugging | Random edits |
| Power budget | Battery life | Dead device in the field |
| MQTT discovery | Integration | Manual HA config |
| Datasheet query | Spec reading | Missed errata |
Every prompt here shares one rule: make the model state its assumptions and cite the source, then verify against the datasheet. The model is a fast first draft and a patient reviewer — not an oracle. Keep your prompts in a file, version them, and let the datasheet have the final word.
Comments