For an index to all my stories click this text.
As you might know by now I am a fan of MicroPython. The language is mature,loads of libraries are available, and it is easy to use. Installing MicroPython on a Raspberry Pi Pico is a piece of cake and well-documented. However installing MicroPython on an ESP32 while your computer runs Linux is in a different ballpark.
You will need to download the right version of MicroPython for your ESP32 and to install it you need to use a tool called ESPtool.
I am going to show you how it is done.
Get MicroPython
First step is of course to download the language.
With your web-browser visit the MicroPython website at: micropython.org
At the top of the page click the download button which brings you to a webpage where you can choose your microcontroller from a list of vendors or by type.
The ESP32 is made by Espressif so click on that name in the vendor list.
On this page you can choose your model. My most frequent used model is the ESP32 Doit Devkit. This version has the ESP32-Wroom processor on it.
This is the board I am talking about.
This is the actual microcontroller and on the top you can clearly see the type ESP-WROOM-32
So click on this model.
This brings you to the download page.
Unless you need a previous version for a special reason, always choose the latest release.
At the time of this writing that's version V1.25.0
Clicking on this line starts the download which you can (after a very short time) find in your download folder on your harddisk.
When the file is downloaded I transfer it to a new folder on my computer.
For demonstration purposes I made an ESP32 folder in my home directory. You may of course use any folder you like as long as you adjust the path names in this tutorial.
So now I have a folder that contains a file with the name ESP32_GENERIC-20250415-v1.25.0.bin. Well that is not really workable. So I altered the name of the file in ESP32-V125.bin.
The path to this file is therefore : ~/ESP32/ESP32-V125.binWrong installation instructions.
To install MicroPython on an ESP32 you need something that is called ESPtool. And you need to install that first on your computer.
Installation instructions I found for Linux were:
sudo apt install esptool
Well that did not work. Oh it installed allright but when I tried to use it sputtered that the file stub_flasher_32.json was missing. I did a lot of searching but to no avail.
Next option is to use pip
pip3 install esptool
Again to no avail. Another error message appeared. This one told me that esptool was not a non-Debian-packaged Python package. And it would not install. Now what ??
The right way.
To install esptool start we need a virtual environment.
Please send me an email if you have no clue on what a virtual environment is and what it is about.
First build your virtual environment.
Open the console and point to your newly created directory. Mine is home/luc/ESP32.
As my new folder is in my home folder I only have to do : cd ESP32
Now in this folder we are going to create a virtual environment. And we are going to give it the name esptoolenv.
The command we use is: python3 -m venv esptoolenv
Make sure to type python3 because the older versions of Python (Python 2) is not installed on recent versions of Linux.
If you open your file explorer you can see that in your ESP32 folder a new folder is created with the name esptoolenv.
The virtual environment is there. Now we need to activate it with :
source esptoolenv/bin/activate
Now we can install esptool with: pip install esptool
This takes just a few seconds.
If you want to deactivate the virtual environment just use: deactivate.
But do not do that now as we need the virtual environment to run esptool.
Install MicroPython.
Now we can install MicroPython.
Before we can install MicroPython we need to know to which USB port the ESP32 is connected. Start with the ESP32 unplugged.
With the ESP32 not plugged in type :
ls /dev/ttyUSB* /dev/ttyACM* 2>/dev/null
As you can see nothing happens. That is because I have no devices attached to my USB ports. Now plug in the ESP32.
And there it is. The ESP32 is plugged in on ttyUSB0
Now we have everything in place.
Let's start with an empty flash.
esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash
This command erases the ESP's flash memory totally.
And now we can flash MicroPython with the command:
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 ~/ESP32/ESP32-V125.bin
A quick look at the details:
esptool.py calls the program
--chip esp32 tells which chip we are flashing
--port /dev/ttyUSB0 the usb port we are using
--baud 460800 The speed we are writing with
write_flash -z 0x1000 the starting memory location
~/ESP32/ESP32-V125.bin the file we are flashing
Looks quite complicated, but don't worry you will soon get the hang of it.
And there we are.
MicroPython up and running in Thonny.
Till next time
have fun
Luc Volders