From Blink to MQTT: 12 AI Prompts That Streamline Embedded, Arduino, and IoT Development in 2026
Embedded development is a unique beast. You're juggling datasheets, timing constraints, and obscure compiler flags, often without a safety net. Whether you're prototyping an Arduino sensor node or deploying a fleet of STM32-based devices, the friction between idea and working firmware can be brutal. AI won't replace your oscilloscope, but it can dramatically cut the time spent on boilerplate, debugging, and documentation.
This collection isn't about generic 'write my code' prompts. Each prompt is designed for a specific embedded task — from generating register-level configuration to decoding a cryptic I2C error. We've tested them against real toolchains (PlatformIO, STM32CubeIDE, ESP-IDF) and included concrete examples. Use them as a starting point, but always verify against official references like the manufacturer's reference manual and protocol specifications.
1. Generate Peripheral Initialization Code from a Datasheet Snippet
Task: Quickly scaffold initialization for a microcontroller peripheral (GPIO, ADC, UART) based on register descriptions.
Prompt:
You are an embedded C expert. Based on the following register description from the [MCU name] reference manual, generate a bare-metal C function to initialize [peripheral] with these settings: [list settings]. Use direct register access, include required bit masks, and add comments explaining each step. Assume the system clock is already configured.
Register snippet:
[Paste relevant register table or description]
Example: For an STM32F4 ADC1 to read from channel 5, single conversion, software trigger. The AI returns code with ADC1->CR2 |= ADC_CR2_ADON; and proper sequence. Verify against RM0090.
2. Debug I2C Communication Failures
Task: Diagnose common I2C issues (NACK, bus lockup, clock stretching) from error logs.
Prompt:
I'm using [MCU] with [I2C library, e.g., STM32 HAL]. My I2C transaction to [device] fails with error code [code]. Here's the initialization and transfer code: [paste code]. The logic analyzer shows [describe signals]. What are the likely causes and how to fix them? Provide step-by-step debugging and corrected code.
Example: A BME280 sensor returns HAL_ERROR. The AI suggests checking pull-up resistors, verifying the slave address (0x76 vs 0x77), and adding a bus recovery sequence.
3. Optimize Firmware for Size or Speed
Task: Reduce flash usage or improve execution speed of a function.
Prompt:
Analyze this embedded C function for [ARM Cortex-M4]. Suggest optimizations to reduce code size (using -Os) or increase speed (using -O3), without changing behavior. Consider loop unrolling, fixed-point math, and compiler intrinsics. Provide the optimized code and explain trade-offs.
Original code: [paste function]
Example: A PID controller using floats can be converted to fixed-point Q15, saving cycles and flash. The AI provides the Q15 implementation and notes precision loss.
4. Generate a Sensor Driver from a Datasheet
Task: Create a minimal driver for a new sensor.
Prompt:
Write a C driver for [sensor] using [I2C/SPI]. Include functions: init(), read_temperature(), read_humidity(). Use the register map from the datasheet. Assume a generic I2C read/write function is available. Add error handling and a sample usage in main().
Datasheet excerpt: [paste key registers]
Example: For SHT31, the AI generates correct commands (0x2C06 for high repeatability) and CRC check.
5. Decode a UART Protocol from a Logic Analyzer Capture
Task: Reverse-engineer a proprietary UART protocol.
Prompt:
I captured UART data at [baud] from [device]. Here's the hex dump: [paste bytes]. The device sends packets with a header, payload, and checksum. Identify the packet structure, checksum algorithm, and write a Python parser to decode it.
Example: A GPS module outputs NMEA-like sentences; the AI identifies the checksum as XOR and writes a parser.
6. Generate SPI Configuration for a Display
Task: Set up SPI for an LCD/OLED.
Prompt:
Configure SPI for [MCU] to drive [display] at [clock speed]. Provide initialization code for SPI peripheral, GPIO for CS/DC/RST, and a function to send a command/data. Use [HAL/LL] library. Include timing delays as per datasheet.
Display datasheet: [paste key timing]
Example: For ST7735, the AI sets SPI mode 0, MSB first, and correct delays after reset.
7. Write a State Machine for an Embedded Application
Task: Implement a robust state machine.
Prompt:
Design a state machine in C for [application, e.g., a vending machine]. States: [list]. Events: [list]. Use a switch-case or table-driven approach. Include transition actions and entry/exit actions. Generate code with comments.
Example: A traffic light controller with timed transitions.
8. Create a Makefile or PlatformIO Configuration
Task: Set up build system for a project.
Prompt:
Generate a Makefile for an STM32 project using arm-none-eabi-gcc. Include flags for [optimization], linker script, and OpenOCD flashing. Or provide a platformio.ini for [board] with [framework].
Example: PlatformIO config for ESP32 with Arduino framework and MQTT library.
9. Implement MQTT Communication on an ESP32
Task: Connect a device to an MQTT broker.
Prompt:
Write Arduino code for ESP32 to connect to MQTT broker [address] and publish sensor data every [interval]. Use PubSubClient. Include WiFi setup, reconnect logic, and JSON payload. Add deep sleep between publishes for battery saving.
Example: Publishes temperature to home/sensor1/temp.
10. Debug a Hard Fault on ARM Cortex-M
Task: Diagnose a crash.
Prompt:
My STM32 enters HardFault. The fault status registers are: CFSR=0x[value], HFSR=0x[value]. The stack frame shows PC=0x[address]. Explain the likely cause and how to fix it. Provide code to decode the fault.
Example: CFSR indicates unaligned access; fix by adjusting pointer casting.
11. Generate Documentation from Code
Task: Create doxygen comments or a README.
Prompt:
Add Doxygen comments to this embedded C code and generate a README.md with build instructions, pinout, and usage. Code: [paste]
Example: For a custom Arduino library, the AI produces a clear README and API docs.
12. Simulate a Circuit with Wokwi or SPICE
Task: Validate a design before hardware.
Prompt:
Generate a Wokwi diagram.json for an Arduino Uno with [components] and the corresponding sketch to [function]. Also suggest a SPICE model for the analog front-end.
Example: Simulate a temperature-controlled fan with a thermistor and relay.
These prompts are a starting point. Always cross-check with official documentation and test on real hardware. For deeper learning, consider structured courses on embedded systems and IoT, like those on asibiont.com, which combine AI-driven practice with expert-vetted material. Stay curious, keep your soldering iron handy, and let AI handle the repetitive parts.
Comments