MicroPython on ESP32
Embedded and IoT
Python
Download Firmware
https://micropython.org/download/
https://micropython.org/download/?port=esp32
ESP32 / WROOM: https://micropython.org/download/ESP32_GENERIC/
Download latest release .bin, e.g.: ESP32_GENERIC-20230426-v1.20.0.bin
Virtual Environment
python3 -m venv esp_venv
cd esp_venv
source bin/activate
pip install esptoolInstallation
Plug in the esp32 board.
Check /dev and confirm device is devttyUSB0. If not, adjust instructions accordingly.
If you are putting MicroPython on your board for the first time then you should first erase the entire flash using:
esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flashFrom then on program the firmware starting at address 0x1000:
esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20190125-v1.10.binPort Error
If you see this when running esptool.py:
A fatal error occurred: Could not open /dev/ttyUSB0, the port doesn't existYou may need to add yourself to the dialout group:
sudo adduser <username> dialoutAnd maybe also this:
sudo chmod a+rw /dev/ttyUSB0Access REPL
Install picocom:
sudo apt install picocomConnect:
picocom /dev/ttyUSB0 -b115200Hit enter a couple of times, and you’ll see the »> prompt.
Test:
>>> import machine
>>> pin = machine.Pin(2, machine.Pin.OUT)
>>> pin.on()
>>> pin.off()