How to get started with Micropython and ESP32-S3
Accelerate your embedded programming with Micropython. This is a how-to guide to start programming an ESP32S3 microcontroller in Mycropython.
What you need
This tutorial runs under a Windows machine and a microcontroller connected through a USB port. The hardware board is an AnthC, a multipurpose IoT board. You can find here more information about the board. The board these characteristics:
- Extended range temperature
- Input power: 7V — 28V. The board can be powered by just powering 5V area.
- 4 Digital inputs
- 6 Open collector outputs
- 4 Analog inputs (16 bit ADC) or 4–20mA inputs switchable (multiplexed)
- RS485 communication
- Real time clock
- Rechargeable LiPo battery
- I2C and SPI communication
- USB-C port
For today’s tutorial, we will need one of these boards and an USB-C cable.
Getting ready
If it is the first time you program in Python, you need to install some Software.
- Python
- PIP is a package manager for Python. It makes the installation of packages very straightforward. To install, open a Powershell console and type
- esptool
- VScode (Optional)
- Putty
Identifying the Serial Port
Once you connect the board to your computer through the USB cable and hear the famous Windows sound of “New device detected”, open the device manager and go under Ports (COM & LPT).
In my case, it is the COM7. In the commands shown in this tutorial, replace the port COM7 by the one you have identified.
Downloading Micropython
The first thing is to download the Micropython binary file from the website. It is important to select the one that corresponds to our microcontroller, in this case, the ESP32-S3.
Download the the last version, in bin format, which today is the v1.23.0 (2024–06–02).bin. This file contains the firmware for the microcontroller. It is the program that will translate the Python code into embedded C.
Flashing the firmware
To avoid potential problems, the first thing is to erase the flash memory. To do that, open a Powershell terminal and type:
esptool.exe --port COM7 erase_flash
After a few seconds, the flash memory will be erased.
Now it is the moment of installing Micropython. In the PowerShell terminal, type:
esptool.exe --port COM7 --baud 460800 --before default_reset --after hard_reset --chip esp32s3 write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 ESP32_GENERIC_S3-20240602-v1.23.0.bin
Remember to replace COM7 by the corresponding port of your computer and the binary file name by the one you downloaded.
And then you are ready to start programming your board with Micropython!
If you want to keep pushing the limits of your electronic knowledge, join the Newsletter.