Learn how to set up MicroPython on your ESP32 with this guide. Flash firmware with Thonny IDE, write python scripts to interact with the ESP32 microcontroller.

MicroPython on ESP32 and ESP8266 Getting Started

Learn how to set up MicroPython on your ESP32 with this guide. Flash firmware with Thonny IDE, write python scripts to interact with the ESP32 microcontroller.

Getting Started
Last Updated:

Today, we are going to jump straight into getting MicroPython up and running on the ESP32. It lets you write and run Python scripts directly on the microcontroller, so you can prototype without a separate compile-and-flash step for every change. This guide sets up Thonny IDE, flashes the MicroPython firmware onto your board, and runs a first script that controls the built-in LED - and every step here also works on the ESP8266.

15-20 minutes Beginner friendly Works with ESP32 and ESP8266

What you need

Hardware

Any ESP32 or ESP8266 board - MicroPython supports the original ESP32 plus the ESP32-S2, ESP32-S3 and ESP32-C3, as well as ESP8266 boards. Not sure what you have? Find your board among 270+ pages →

A USB data cable - a charge-only cable will not show up as a serial port.

Software

Windows, macOS or Linux - Thonny runs on all three and the steps below are identical.

Thonny IDE - a free, beginner-friendly editor with MicroPython support built in. It drives esptool for you when flashing firmware.

1Install Thonny IDE

Download Thonny from the official Thonny website - grab the installer for your OS straight from the front page.

Thonny download button for Windows, Mac and Linux
Thonny's download button - pick your OS

Windows

Download the installer from the website and follow the on-screen instructions.

macOS

With Homebrew:

brew install --cask thonny

Linux

Use your package manager, for example on Ubuntu:

sudo apt update
sudo apt install thonny

Launch Thonny. On first open it shows a plain script editor with a shell panel underneath:

Thonny IDE on first launch
Thonny on first launch - script editor on top, shell below

2Flash MicroPython to your board

Connect your ESP32 or ESP8266 to your computer with a USB cable. Click the interpreter selector in Thonny's bottom-right corner, then choose Configure interpreter from the list.

Thonny interpreter selector with Configure interpreter highlighted
The interpreter selector, bottom-right corner of the window

In the dialog that opens:

  1. Set the interpreter dropdown to MicroPython (ESP32) (or MicroPython (ESP8266) for that chip). If it is not listed, make sure your board is connected first.
  2. Under Port or WebREPL, select the port that corresponds to your board.
  3. Leave the checkboxes enabled - interrupt the working program on connect, sync the real-time clock, and restart the interpreter before running a script.
  4. Click Install or update MicroPython (esptool).
Thonny configure interpreter dialog for ESP32
Configure interpreter - port, checkboxes, and the install link

A second dialog handles the actual flash:

  1. MicroPython family: pick your chip, for example ESP32 or ESP32-C3.
  2. Variant: pick the entry that matches your board - Espressif's generic variant works for most boards.
  3. Version: pick the latest stable release from the dropdown.

Click Install and wait for it to finish - Thonny erases the flash and writes the firmware over USB.

Thonny install MicroPython dialog with family, variant and version fields
Install MicroPython - family, variant, and version

Which version should I pick? Always pick the latest stable release available in the dropdown rather than chasing a specific version number from a tutorial - firmware and this guide's text can drift apart. The current stable line is listed on micropython.org's ESP32 download page.

Once it finishes, Thonny reconnects to your board and the shell shows a boot banner:

MicroPython boot banner and a Hello World test in Thonny's shell
MicroPython running - typing directly into the shell executes on the board

Type print("Hello World from ESP32") into the shell and press Enter - it runs immediately on the board, before you have written a single script file.

3Run your first script

In the script editor (the top pane), type the following:

blink.py Copy
from machine import Pin

p0 = Pin(10, Pin.OUT)
p0.on()

Pin varies by board. This example uses GPIO10 for the built-in LED, matching the screenshots below, but the actual pin depends on the board you are holding. Check your board's page in the boards database for the correct number.

Click the green Run button in the toolbar (or Run → Run current script):

Running the script that turns on the built-in LED in Thonny
Running the script - the Run button in the toolbar

If your board's LED pin matches, it lights up as the script runs. Because p0 was defined at the top level of the script, it stays alive in the shell afterward, so you can control it directly without re-running anything. Turn the LED off with p0.off():

Turning the LED off from Thonny's shell with p0.off()
p0.off() typed into the shell, right after the script ran

Type p0.on() to turn it back on. Both commands take effect immediately - there is no re-upload step in between.

This is the real advantage of MicroPython over compiled firmware: the shell stays live against whatever the script last defined, so you can poke at hardware, read a sensor value, or flip a pin directly from the console instead of running a full compile-and-flash cycle for every change.

Frequently asked questions

Does MicroPython support ESP8266 as well as ESP32?
Yes. MicroPython officially supports ESP8266 boards alongside every ESP32 variant, though ESP8266 has far less RAM and flash than ESP32, so a handful of larger MicroPython libraries only run on ESP32.
Do I need to install esptool separately to flash MicroPython from Thonny?
No, not normally. Thonny bundles esptool and drives it automatically from the Install or update MicroPython dialog. A freshly installed copy of Thonny may prompt you to install it as a plug-in the first time you use that dialog; if so, allow it and continue.
Why does my board's built-in LED use a different GPIO number than the examples show?
Espressif does not standardize which pin drives the onboard LED, so it differs by board and sometimes by revision of the same board. Check your specific board's page in the boards database for its correct pin number.
Does running a script in Thonny save it onto the board?
Not by itself. Clicking Run sends the script from your computer straight to the board's memory for that session; it does not persist after a reset unless you explicitly save it onto the device as main.py.

Where to next