How to Flash MicroPython onto an ESP32

MicroPython lets you program an ESP32 in Python instead of C, which shortens the path from idea to working code. Flashing the firmware is a one-time setup, and once you understand the steps it takes only a few minutes. If you would rather start with a board and accessories that are already confirmed to work together, Compoden's AI build assistant can ship a matched kit, but this guide covers the process itself.

What you need before you start

You need an ESP32 board, a good USB data cable, and a computer with Python installed. Avoid charge-only cables, because they carry no data and are a common reason a board fails to connect. You will install one small tool called esptool, which talks to the chip, and you will download a MicroPython firmware file for the ESP32.

Install esptool and find the port

Install esptool with pip using pip install esptool. Plug in the board and identify its serial port. On Windows it appears as a COM port in Device Manager, and on Linux or macOS it usually shows up as a device under /dev. If the port does not appear at all, the cause is often the cable or a missing USB-to-serial driver for the board's bridge chip.

Erase the existing flash

Always erase the chip before writing new firmware, because leftover data can cause strange boot behaviour. Run esptool.py --port YOUR_PORT erase_flash, replacing YOUR_PORT with the one you found. Some boards need you to hold the BOOT button while the connection starts so the chip enters its download mode. A clean erase gives MicroPython a fresh start.

Write the MicroPython firmware

Download the latest stable ESP32 build from the official MicroPython downloads page. Flash it with a command of the form esptool.py --port YOUR_PORT write_flash -z 0x1000 firmware.bin, where firmware.bin is the file you downloaded. Note that the starting address can differ between chip variants, so follow the address given on the download page for your specific board.

Connect to the REPL

After flashing, open a serial terminal such as the one built into Thonny, or use a tool like screen or PuTTY at 115200 baud. You should see the MicroPython prompt, three greater-than signs. Type a quick test like print("hello") to confirm it responds. From here you can write code directly or save files to the board.

Build it with Compoden's AI

Describe your build to Compoden's AI build assistant, for example "an ESP32 sensor node that sends readings over Wi-Fi." It checks live stock, recommends a suitable board and sensors, provides wiring and MicroPython-ready starter code, and ships the matched kit across India. You get a board, a known-good cable, and parts that fit together, which removes the most common flashing headaches before they start.

Want a clean starting point? Tell Compoden's AI build assistant your idea and receive a matched kit plus code. Explore boards and accessories at our full collection.

FAQ

Why won't my ESP32 show up as a serial port? The usual causes are a charge-only USB cable or a missing USB-to-serial driver for the board's bridge chip. Swap to a known data cable and install the driver, then check again.

Do I have to erase the flash first? It is strongly recommended. Erasing removes leftover data that can cause boot loops or odd behaviour after you write the new firmware.

What baud rate do I use for the REPL? Connect your serial terminal at 115200 baud, which is the standard speed for the MicroPython prompt on the ESP32.

Back to blog