MicroPython is not flashed onto the ESP32 or ESP8266 boards by default. The first thing you need to do to start programming your boards with MicroPython is upload the firmware.
-
Go to the ESP32 MicroPython Downloads page: https://micropython.org/download/esp32/
-
Scroll your mouse to the very bottom of the web then you should see
Firmware (Compiled with IDF 3.x)
. -
Select the lastest release to download
.bin
files. -
The firmware (.bin) should be downloaded.
Before you connect the Micro USB to your computer, you should install the USB Driver first, otherwise Thonny might not find your USB port.
The driver is different depending on the chip on the ESP32. But the most ESP32 use CP210x USB to UART Bridge VCP Drivers. Click here to nevigate to the download page.
For Windows, select CP210x Windows Drivers
, then the driver should start downloading.
For Mac OSX, the driver should be built in with the OS, so there is no need to download it.
After downloading the CP210x Driver, complete the installation by running the installer.
- Connect the Micro USB to the ESP32.
- Open Thonny IDE.
- Click the
Run
menu on the top of the window. - Then in the dropdown menu click
Select Interpreter
- In the option window,change the The same interpreter which run Thonny (Default Interpreter) to
MicroPython ESP32
. - Then select your computer port for your ESP32 port.
- After the port is selected, click
Install or update firmware
on the right bottom. - In the port entry, select your ESP32 port.
- Then in the firmware entry, browse to your firmware file (.bin).
- After that, press and hold the
Boot
button on the ESP32, then clickInstall
and wait until done. - Close the option window and go back to Thonny IDE.
- The Shell should prompt
MicroPython v<version> on <last update>
andESP32 module with ESP32
.Then the left-buttom menu will showboot.py
inside theMicroPython Device
window. (If you do not see the MicroPython Device window, click theview
menu on the top, then on the dropdown select theFile
menu. The window should appear.)
- Click the
New
menu on the top (or Ctrl+N) to create a new file, then save it asmain.py
- After that, in the editor coppy the following code.
from machine import Pin
print('Hello World!')
- Save the new file by click
save
(Ctrl+S) toThis computer
andRun
(F5). - In the Shell will display
Hello Wolrd
.
When you finish the code and want to save it on the ESP32.
- Right click the
main.py
inThis computer
window. - Select
upload to
and wait until the upload is complete. - The upload file will show in
MicroPython Device
window. (If you do not rename it tomain.py
, it will not work.) - Press the
EN
button on the board then the ESP32 should be reboot.
To use an external or custom library, you need to upload the library file to the MicroPython device before running or deploying your code.
The process is the same as uploading main.py
to a MicroPython device.
- Right click the library file in
This computer
window. - Select
upload to
and wait until the upload is complete. - The upload file will show in
MicroPython Device
window.