Skip to content

uPesy only delivers currently in France.

Contents Menu Expand Light mode Dark mode Auto light/dark mode

Install MicroPython on an ESP32 board

Follow this step-by-step installation guide to install and use MicroPython quickly on your ESP32 board.

What is MicroPython?

MicroPython is a Python interpreter optimized for microcontrollers like ESP32 boards. You can write Python scripts that will be directly executed on an ESP32 board. To do so, all you have to do is flash the ESP32 board with MicroPython on it and use IDE software (for example Thonny IDE ) to code Python scripts and send them to the ESP32.

MicroPython firmware is available on the official website . Remember to take the most recent stable version and take the file with the extension .bin

micropython download page for esp32

The latest version of MicroPython when writing the tutorial is v1.17

Note

To be able to use the additional 4 MB of RAM of the uPesy ESP32 Wrover DevKit board, you will have to go to the download page specially designed for SPIRAM support

I propose 2 ways to install MicroPython on your ESP32 board : one method for beginners with Thonny IDE and another for more advanced people in the terminal.

Install MicroPython on an ESP32 board with Thonny IDE

The easiest way to install MicroPython on the ESP32 is through the Thonny IDE interface for beginners.

install micropython on ESP32 from Thonny IDE

You will use both Thonny to install MicroPython and write all your Python scripts. To install Thonny IDE, simply go to the official website thonny.org , then choose and install the correct executable according to your operating system.

Setting up Thonny is very easy. During the first launch, you can choose the language.

change language in thonny IDE

Language choice when launching Thonny for the first time

We obtain a classic text editor with a Python interpreter.

thonny ide home page

Thonny IDE overview

To install MicroPython, simply go to Execute> Select the interpreter

select the interpreter in thonny ide

Choose the interpreter “MicroPython (ESP32)” and click on “Install or update the firmware”

click on install micropython on esp32 from thonny ide

If your ESP32 board does not appear in the drop-down list, check that it is properly connected and click on “Reload” to refresh the list. Fill in the path to the MicroPython binary file, then click on “Install”

install micropython on ESP32 from Thonny IDE

Here, the ESP32 is recognized by the computer as “Silicon Labs CP210x USB to UART Bridge (COM8)”

flash micropython on ESP32 via Thonny IDE

MicroPython is installed on ESP32.

If all goes well, MicroPython is correctly installed on the ESP32. However, you have to ensure that Thonny uses the ESP32 MicroPython interpreter. You just have to go back to the menu Execute> Select the interpreter and change if necessary.

select the esp32 micropython interpreter

Make sure Thonny IDE is using the correct MicroPython interpreter.

The MicroPython interpreter for your ESP32 board should appear in Thonny:

select the esp32 micropython interpreter

MicroPython interpreter of your ESP32 board

Note

If nothing happens, you can try pressing the STOP button, which restarts the MicroPython interpreter.

Install MicroPython on ESP32 directly with esptool

For advanced people who do not want to use Thonny IDE, you can directly use the dedicated communication tool for the ESP32: esptool.py .

esptool.py uploads the Arduino sketches to the ESP32

The software esptool.py takes care of uploading the sketches of Arduino IDE on the ESP32.

You can install it via terminal with the pip package manager.

pip.exe install esptool     # For Windows
pip install esptool         # For Linux / macOS

Before using it, you must know the COM port of your ESP32 board: plug in your ESP32 and go to Windows Device Manager .

device Manager

Type “device manager” in the Windows search bar

Look at the COM number of your ESP32 in the Ports (COM and LPT) tab.

find COM number in device manager

In this example, the ESP32 board is on the COM8 port.

Then, we enter the command below in the terminal to flash the firmware with esptool , and we press Enter:

esptool.py.exe --chip esp32 --port COM8 --baud 460800 write_flash -z 0x1000 esp32-20210902-v1.17.bin

Note

There are extensions for MicroPython on VS Code, Pycharm. You can also use tools like RSHELL to upload Python scripts directly from a terminal.

Your first MicroPython script on ESP32

Now that all the tools are installed, we can write our first Python script (on Thonny IDE): This is the famous code that makes the LED of your ESP32 board blink (present on the GPIO2 pin).

import time
from machine import Pin

print("Hello World")
p2 = Pin(2,Pin.OUT)

while True:
  p2.on()
  time.sleep_ms(250)
  p2.off()
  time.sleep_ms(250)

To run the script on your ESP32 board, all you have to do is press the green button “Run” . I suggest you change the blinking time of the LEDs to realize how fast loading a new code is.

example of Python script in on Thonny IDE for ESP32 board

Overview of a MicroPython script for ESP32 within Thonny IDE

We use cookies to make your visit to the site as pleasant as possible. Privacy Policy