Claude forgets that my ESP32 isn't a full computer. Here are my 4 fixes

Most of the vibe coding projects I encounter are written in high-level languages like C, C++, or Python.However, Claude can also write decent MicroPython—you just need to be a little careful.Claude tends to write MicroPython like regular Python, which means the code it produces is often too memory-intensive for many microcontrollers, which only have a few hundred kilobytes of RAM.

I've also found that it doesn't always account for the factors that matter when you're trying to build something with a microcontroller.A blinking LED is cool; a blinking LED that prevents you from pushing buttons is really aggravating.These are a few things I've found that guide Claude towards writing more useful MicroPython for ESP32 boards.

Do two things at once without freezing Ditch time.sleep() so you can push buttons Close If you've ever written the basic blinking LED project, you probably used time.sleep().Claude will usually use it when you vibe code it, and in most common tutorials you'll find use it too.It is fine if you're learning to write code for the first time, but a total pain otherwise.

Sleep() tells the board to stop for a specified duration.If you push a different button in that time, it is totally ignored.It quickly becomes a problem in real-world projects.

Instead, remind Claude that tick_ms() and ticks_diff() can handle a blinking LED tying up your board.Asyncio is another good one to point Claude towards.Even if you don't specify those commands specifically, be sure to that you need to be able to take an input at any time.

One button push should only fire once Debouncing is essential When you write a simple script that reads a button press, you'll often find that one push actually registers as multiple hits.That isn't a software bug precisely, it occurs because metal contacts bounce slightly when they make contact, which registers as multiple presses.In order to fix that, Claude will often simply add a sleep after the first press to ensure subsequent presses don't register.

However, that can also be a problem if you have multiple buttons you want to press.Make sure to tell Claude to account for debouncing sleeping so that you don't get any weird pauses.Get reading from your ESP32 to your phone MQTT publishing that reconnects by itself Message Queuing Telemetry Transport (MQTT) is the best way to get information from an ESP32 board into something like Home Assistant.

It is lightweight and is easy to deploy.However, I've found that Claude tends to ignore an important part: reconnecting.Some of my devices run for months without me touching them, and in that time, the router will restart, I'll have a power outage, or something else that interrupts the connection.

Some simple scripts you get out of Claude (especially Opus 5, for some reason) don't have a reconnection provision, so once they go offline, they'll stay offline until you intervene.Make sure you prompt Claude to include a retry function that gets your device back online so that you don't have to fiddle with the sensor you stuffed in your attic.Umqtt.robust is a good place to start.

Change settings without re-flashing the board Config.json saves you the trouble of reflashing the board If you provide Claude with your Wi-Fi credentials, there is every chance it'll hard code them into whatever script it is writing for your ESP32 board.If the network name or password changes, you have to change the code and then re-flash the board.Absolutely no one wants to do that.

Instead, tell Claude that you want your settings to be read from a file stored in the board's flash memory.Config.json is a popular option, but realistically any plain text format will work.The script loads the file when the board boots, which means you only need to tweak your config file if you want to update a password.

Related 4 full operating systems to install on your ESP32 this weekend (Jun 12-14 Real operating systems on a tiny microcontroller.Posts By  Tim Brookes It also means you can share your code on the internet without providing the world with your Wi-Fi password.Warning: Never hard-code important credentials into your code and then publish it.

If you use a separate config file to store credentials, make sure you don't publish that either.This happens way too much with vibe-coded programs.Run for weeks on a battery Learn to use deep sleep well ESP32 projects often need to run for prolonged periods on a battery.

If the ESP32 board stays on for the entire time, even a modestly sized battery will be dead in a few days.If you're planning on running your ESP32 project off of a battery, make sure you tell Claude how long you want it to run, what kind of battery you're using, and whether the battery will have any input power (like from a small PV cell).Claude can change how the firmware functions so that the board goes into a deeper sleep and only consumes a few microamps while idle, and only draws a significant amount of power when it briefly powers on to collect sensor data.

Note: Some dev-boards have onboard LEDs and USB chips that draw a significant amount of power, which decreases how long a board can run.If you need to maximize your run time, get a bare board.Claude can write great MicroPython, it just needs to be reminded Claude is perfectly capable of writing MicroPython for an ESP32.

It just tends to do so right out of the gate.My experiments with it have consistently found that it seems to approach writing code for microcontrollers the same way that it does code for a regular Linux PC.That can cause problems.

If you have a specific use in mind, make sure you include that information in your project or prompt.If you're building for a specific board or family of boards, provide that information to Claude.And, as always, remind it that you're working with a tiny amount of RAM—it may neglect that consideration otherwise.

Read More
Related Posts