Install MicroPython on an ESP32 board
Follow this step-by-step installation guide to install and use MicroPython quickly on your ESP32 board.
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
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.
The easiest way to install MicroPython on the ESP32 is through the Thonny IDE interface for beginners.
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.
We obtain a classic text editor with a Python interpreter.
To install MicroPython, simply go to Execute> Select the interpreter
Choose the interpreter “MicroPython (ESP32)” and click on “Install or update the firmware”
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”
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.
The MicroPython interpreter for your ESP32 board should appear in Thonny:
If nothing happens, you can try pressing the STOP button, which restarts the MicroPython interpreter.
For advanced people who do not want to use Thonny IDE, you can directly use the dedicated communication tool for the ESP32: esptool.py .
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 .
Look at the COM number of your ESP32 in the Ports (COM and LPT) tab.
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
There are extensions for MicroPython on VS Code, Pycharm. You can also use tools like RSHELL to upload Python scripts directly from a terminal.
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.