ESP32 and MicroPython - bapowell/bapowell.github.io GitHub Wiki
https://www.rototron.info/raspberry-pi-esp32-micropython-tutorial
https://boneskull.com/micropython-on-esp32-part-1
LoBo's MicroPython for ESP32 with psRAM support
-
Ensure venv is installed:
$ sudo apt-get install python3-venv -
Create a python virtual env for esp32-related work:
$ python3 -m venv pyvenv_esp32 -
Active the venv:
$ source pyvenv_esp32/bin/activate
Note: To deactivate it later, type deactivate<enter> at the command prompt. -
Ensure using latest version of pip:
$ python -m pip install pip --upgrade -
Install ESPTool:
$ python -m pip install esptool -
Install rshell:
$ python -m pip install rshell
-
Determine serial port:
$ dmesg --follow
Watch the dmesg output as you plug in the USB cable. You should see a new device attached, e.g. ttyUSB0. -
Ensure board is working, using the ESPTool flash_id command:
$ esptool.py --port /dev/ttyUSB0 flash_id
If get a "Permission denied" error on the port (e.g. /dev/ttyUSB0), then may need to add your user to the group that the device is using.
$ ls -l /dev/ttyUSB0
For example, it might show /dev/ttyUSB0 assigned to the "dialout" group.
Show the groups your user belongs to:
$ groups userName
If "dialout" isn't in the list, then add it:
$ sudo usermod -a -G dialout userName
Log out and log back in (might actually need to reboot) to see the new group added.
-
First erase the flash:
$ esptool.py --chip esp32 --port /dev/ttyUSB0 erase_flash -
Get the firmware from LoBo's repo.
- Extract the firmware zip file to a "firmware" folder, which will contain, among other files, the flash.sh utility as well as a subfolder with a MicroPython.bin file (and other bin files).
- Change your working directory to the folder with the MicroPython.bin file. The flash.sh script should be in its parent folder.
-
Flash the firmware, using the flash.sh utility:
$ ../flash.sh -p <comm_port> -b <baud_rate>
Note that the -p and -b options are optional. The default port is /dev/ttyUSB0. The default baud rate is 460800.- Might need to hard reset the device after flashing.
-
Start rshell
$ rshell --port /dev/ttyUSB0 -
Show the connected boards
> boards -
Enter the python REPL
> repl- Once in the repl, type help() to show intro help for MicroPython.
- Exit the REPL with Ctrl-X