ESP32 MicroPython Coding Setup

2 minute read

A short entry to explain how to code using MicroPython on the ESP32.

Background

In my introduction to Micropython, I mentioned how I wrote MicroPython for the ESP32 on a Mac. As I stated, Phillip van Allen has a nice process, however I like my process more. This entry will review how I develop code as it might be helpful to others.

Mac Process

Serial Monitor

I use a paid application called Serial for serial communication with devices. There are free products, however, I found when using Serial, I’m more productive and I’m able to setup custom settings for each device to maximize throughput while taking care of the idiosyncrasies of each device. I’m also able to connect and disconnect Serial from the device easily and quickly, which is why my approach works so well.

File Management

I use ampy for file management of the ESP32. There are several products, ampy, rshell and mpfshell, however, ampy worked from the start, I’ve had no issues so why change?

Process

Start Serial using the standard baud rate of 115200. I do add a line delay of .01 seconds (1 millisecond), which helps ensure my cut and paste doesn’t over-run MicroPython. In the image below, I have

1. Opened Serial
2. Connected to the HUZZAH32
3. Pressed reset to ensure the HUZZAH32 is in a known state
4. Typed Ctrl-E to start a paste operation
5. Typed CMD-V to paste a 99 line file, PinTest.py
6. Typed Ctrl-D to end the paste operation

And now I’m running PinTest.py

Serial Application showing PinTest.py on HUZZAH32

Serial Application showing PinTest.py on HUZZAH32

Once I know my file is working properly, I save it as main.py and use ampy to copy it over. Open a Terminal session, change to my local MicroPython directory and use ampy to show the files on the ESP32 and load main.py. However I must press CMD-D in the Serial program to release the serial driver.

ampy -p /dev/tty.usbserial-01F4D567 ls
/boot.py
ampy -p /dev/tty.usbserial-01F4D567 put main.py
/boot.py
/main.py

Back in Serial, I press CMD-D to reconnect and CTRL-D to soft reset and I’m back to using MicroPython on the HUZZAH32.

Comments powered by Talkyard.