ESP32S3 and MicroPython development environment

Ats
4 min readJun 9, 2024

--

This is the document about how I set up my development environment for the ESP32S3 and MicroPython

Photo by Guillaume de Germain on Unsplash

First of all

  • I used Mac. the command would be different on Linux or Windows.
  • I used the ESP32S3 showing in the following link. The pin map would be different from the others ESP32S3

Background

I usually use Cortex-A SoC like Raspberry Pi and embedded Linux like Yocto for my job and hobbies. However, I needed to use Cortex-M SoC, which is ESP32S3, for my personal project. I had used it before with Arduino IDE and C++ but I didn’t feel much fun with them because I’m used to using Vim as my editor and prefer high-level languages like Ruby and Python to low-level languages like C++. Then I decided to try MicroPython this time.

What I did

First of all, I googled the MicroPython and found the tutorial. Then I decided to follow it.

As following the tutorial, I downloaded the esptool throught pip and firmware for ESP32S3. I downloaded my firmware from the link below.

pip install esptool

When you download the firmware, be careful to download correct one. Depends on the board, the address will be different where the firmware should be downloaded. For example, I used the command for ESP32 as I thought they were same. But the address was different.

# For esp32
esptool.py --chip esp32 --port /dev/your_port write_flash -z 0x1000 firmware.bin
# for esp32s3
esptool.py --chip esp32s3 --port /dev/your_port write_flash -z 0 firmware.bin

I didn’t noticed the difference at glance and I used the command for ESP32 after just changing chip name from esp32 to esp32s3 . Actually, it was success to write flash and I didn’t think I did wrong. But I got an error when I checked the log. I took some time to figure out the reason. So make sure you use the correct command for your board.

Before writing the firmware, I checked the port with the following command. In the case, my port is /dev/tty.usbmodem1111

❯❯❯ ls /dev/tty.*
/dev/tty.Bluetooth-Incoming-Port /dev/tty.usbmodem1111

Then I removed the existing firmware using esptool . It looked like below.

❯❯❯ esptool.py - port /dev/tty.usbmodem1111 erase_flash
esptool.py v4.7.0
Serial port /dev/tty.usbmodem1111
Connecting…
Detecting chip type… ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
Uploading stub…
Running stub…
Stub running…
Erasing flash (this may take a while)…
Chip erase completed successfully in 5.1s
Hard resetting via RTS pin…

Then I uploaded the firmware which I had downloaded in advance. It looked like below.

❯❯❯ esptool.py - port /dev/tty.usbmodem1111 write_flash -z 0 firmware/ESP32_GENERIC_S3–20240602-v1.23.0.bin
esptool.py v4.7.0
Serial port /dev/tty.usbmodem1111
Connecting…
Detecting chip type… ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
Uploading stub…
Running stub…
Stub running…
Configuring flash size…
Compressed 1628144 bytes to 1067824…
Wrote 1628144 bytes (1067824 compressed) at 0 in 10.2 seconds (effective 1281.9 kbit/s)…
Hash of data verified.

Leaving…
Hard resetting via RTS pin…

Then it was ready to run my script. You can check if you make it using screen command. You can check the log from ESP32S3 through UART serial message like below.

screen /dev/tty.usbmodem1111 115200

If you don’t see any errors and can run MicroPython command there, the firmware is successfully uploaded.

Then I chose the rshell to upload my python script.

I made the following code snippet to test the LED blink.

from machine import Pin
import time
led_pin = 21 # Default on-board RGB LED GPIO48 does not work

def blink():
led = Pin(led_pin, Pin.OUT)
for i in range(10):
led.on()
time.sleep_ms(500)
led.off()
time.sleep_ms(500)
print("Blink ", i+1)

if __name__ == "__main__":
blink()

All I had to do was name the snippet to main.pyand upload the script under /pyboard directory. The following descriptions are for pyboard. But there was /pyboard directory when I check using rshell . So they seem true to ESP32S3 as well.

The drive you are looking at is known as /flash by the pyboard, and should contain the following 4 files:

boot.py — the various configuration options for the pyboard.
It is executed when the pyboard boots up.

main.py — the Python program to be run.
It is executed after boot.py.

README.txt — basic information about getting started with the pyboard.
This provides pointers for new users and can be safely deleted.

pybcdc.inf — the Windows driver file to configure the serial USB device.
More about this in the next tutorial.

https://docs.micropython.org/en/latest/pyboard/tutorial/script.html

So these commands are what I did to upload my script.

# Connect your terminal to esp32s3
rshell -p /dev/tty.usbmodem1111
# Update my script to esp32s3
cp main.py /pyboard/main.py

Afterwards, I saw the LED blink.

That’s it!

--

--

Ats
Ats

Written by Ats

I like building something tangible like touch, gesture, and voice. Ruby on Rails / React Native / Yocto / Raspberry Pi / Interaction Design / CIID IDP alumni

No responses yet