Install MicroPython on ESP32 - Featured Image

Posted on

by

in

How to install MicroPython on ESP32 and download firmware

Introduction

This post will discuss installing MicroPython in an ESP32 MicroController Unit (MCU) and the steps to download the appropriate firmware. The steps outlined here are applicable as well in ESP8266 devices.

If you want to see the steps in a video format then please take a look below or watch it on my YouTube channel.

Prerequisite

I am using the following components and tools in this post.

I am using Windows PC for my personal setup.

Steps in flashing the MicroPython firmware in your ESP32

Plugin your ESP32 module into your laptop or workstation. If your laptop or workstation was able to detect the device then it means that the USB driver was installed already. If not then proceed to download the USB driver for it in the next section.

Note: If you are using Windows PC then you can check the Device Manager and the Ports list and verify the COM port assignment of your ESP32.

COM Port

What COM Port is my ESP32 MicroController using? Using the image above then it is COM3. We will be using this in a later step so take note of it.

Download the USB Driver for your ESP32

Most ESP32 MCU USB driver is powered by the CP210x from Silicon Labs. You can go to this link and download the latest driver for your Operating System.

Silicon Lab USB Driver Download

Download Python

We need to install Python on our laptops or workstation to download certain packages. Go to this link and select the Python distribution that is appropriate for your OS.

Python Download

Related Content:
How to install Python on Windows

Download the MicroPython firmware for ESP32

Download the ESP32 MicroPython firmware from https://micropython.org/download/esp32/. Choose the stable latest build. At the time of this post, I downloaded the following.

ESP32 MicroPython Download Firmware

Install MicroPython firmware

The official steps from the MicroPython team on how to download the firmware to your ESP32 can be found in this link.

Open a command prompt in Windows or a terminal in Mac/Linux

  1. Locate a folder where we could install the firmware. I used ‘C:\micropython
C:\Users\DONSKY>cd c:\micropython
c:\micropython>
  1. Create a Python virtual environment where we would install the required tooling for the firmware installation. This is so that we will not be touching our base Python package installations.

Creating Python virtual environment is a good step to avoid version collision of the packages that you are installing. Say you need to work on an older version of a package then virtual environment will separate that older version from overriding the version that is in the default Python packages installation.

donsky

Note: If you don’t want to create the virtual environment and just would like to install all packages in your default Python packages directory then go directly to Step 4 and skip steps 2 and 3.

Execute the below code and wait for it to finish. The .venv is the name of our virtual environment.

py -m venv .venv

or if you are in Linux/Mac. If you have multiple Python installations (like Python 2) then replaced python with python3

python -m venv .venv
  1. Activate the virtual environment.
c:\micropython>.venv\Scripts\activate

or if you are using Linux or Max

source .venv/bin/activate

You would see your command prompt looking like this which means that you are now in a Python virtual environment.

Python Virtual Environment Activated
  1. Install the esptool needed for the firmware installation. Wait for it to finish.
pip install esptool

At this point, your folder should contain the esp32 firmware bin file and the .venv virtual environment.

MicroPython Directory
  1. Erase the flash memory of your ESP32
esptool.py --chip esp32 --port COM3 erase_flash

or when in Linux/mac

esptool.py --port /dev/ttyUSB0 erase_flash

If an error has occurred, retry the command and click the boot button momentarily on your ESP32 for it to be in Boot Mode.

You should see the following message in your command prompt or terminal

(.venv) c:\micropython>esptool.py --chip esp32 --port COM3 erase_flash
esptool.py v4.3
Serial port COM3
Connecting..................................
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 24:62:ab:fe:d6:94
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 6.8s
Hard resetting via RTS pin...
  1. Install the MicroPython firmware for your MCU.
esptool.py --chip esp32 --port COM3 --baud 460800 write_flash -z 0x1000 esp32-20220618-v1.19.1.bin

or when in Linux or Mac

esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20220618-v1.19.1.bin

You should be able to see the following message displayed in your command prompt or terminal.

If an error has occurred, retry the command and click the boot button momentarily on your ESP32 for it to be in Boot Mode.

(.venv) c:\micropython>esptool.py --chip esp32 --port COM3 --baud 460800 write_flash -z 0x1000 esp32-20220618-v1.19.1.bin
esptool.py v4.3
Serial port COM3
Connecting.........
Chip is ESP32-D0WDQ6 (revision v1.0)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 24:62:ab:fe:d6:94
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x0017efff...
Compressed 1560976 bytes to 1029132...
Wrote 1560976 bytes (1029132 compressed) at 0x00001000 in 24.2 seconds (effective 515.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

If you see the following messages displayed then you have successfully installed MicroPython firmware on your ESP32 device.

  1. Deactivate your virtual environment and closed your command prompt or terminal.
deactivate

How to test our MicroPython firmware installation?

In order to test our ESP32 MicroPython installation and verify the firmware version that we have downloaded then we can do the following steps.

  1. Download Putty.
  2. Set the following options and click Open
ESP32 MicroPython Putty Connection

Then we should be able to access the Python interpreter or what they call the REPL(Read-Evaluate-Print-Loop).

ESP32 MicroPython Putty REPL

Issues:

A fatal error occurred: Could not open /dev/ttyUSB0, the port doesn’t exist

Check to see if you have connected your ESP32 USB connection properly or if it is assigned to that port correctly.

Wrap up

We have installed MicroPython on our ESP32 MCU by downloading the appropriate firmware for it in this post. I have shown you my personal steps on how I am installing Python packages by creating a virtual environment to avoid version collision of different package versions.

I hope you learned something! Happy Exploring!

Related Content:
Arduino officially supports MicroPython

If you like my post then please consider sharing this. Thanks!

16 responses to “How to install MicroPython on ESP32 and download firmware”

  1. MicroPython using VSCode PyMakr on ESP32/ESP8266

    […] Related Content: How to install MicroPython on ESP32 and download firmware […]

  2. MicroPython – How to Blink an LED and More – donskytech.com

    […] Related Content: How to install MicroPython on ESP32 and download firmware […]

  3. MicroPython Development Using Thonny IDE – donskytech.com

    […] Related Content: How to install MicroPython on ESP32 and download firmware […]

  4. Develop MicroPython Application using MicroDot – donskytech.com

    […] Content: How to install MicroPython on ESP32 and download firmwareMicroPython Development Using Thonny […]

  5. How to create a MicroPython Web Server the easy way!

    […] Content: How to install MicroPython on ESP32 and download firmwareMicroPython Development Using Thonny […]

  6. How to interface DHT11 with MicroPython? – donskytech.com

    […] Read: How to install MicroPython on ESP32 and download firmwareMicroPython Development Using Thonny […]

  7. Building a MicroPython Wifi Robot Car – donskytech.com

    […] Related Content: How to install MicroPython on ESP32 and download firmware […]

  8. Control DS18B20 using MicroPython with a Weather Station Project

    […] Content: How to install MicroPython on ESP32 and download firmwareMicroPython Development Using Thonny […]

  9. MicroPython: Interfacing with SSD1306 OLED display

    […] Content: How to install MicroPython on ESP32 and download firmwareMicroPython Development Using Thonny […]

  10. MicroPython – MQTT Publish/Subscribe using ESP32/ESP8266

    […] Content: How to install MicroPython on ESP32 and download firmwareMicroPython Development Using Thonny […]

  11. MicroPython MQTT tutorial using umqtt.simple library

    […] Related Content: How to Install MicroPython firmware on Raspberry Pi Pico?How to install MicroPython on ESP32 and download firmware […]

  12. Control RGB LED using MicroPython – donskytech.com

    […] Related Content: How to Install MicroPython firmware on Raspberry Pi Pico?How to install MicroPython on ESP32 and download firmware […]

  13. MicroDot/MicroPython – Handling dynamic content

    […] Related Content: How to Install MicroPython firmware on Raspberry Pi Pico?How to install MicroPython on ESP32 and download firmware […]

  14. MicroPython – Read LDR or Photoresistor – donskytech.com

    […] Related Content: How to Install MicroPython firmware on Raspberry Pi Pico?How to install MicroPython on ESP32 and download firmware […]

  15. Using WebSocket in MicroPython – A Practical Example

    […] Related Content: How to Install MicroPython firmware on Raspberry Pi Pico?How to install MicroPython on ESP32 and download firmware […]

  16. Exploring ESP-NOW in MicroPython: A Learner's Guide – donskytech.com

    […] If you are not familiar with these then take a look at my two posts MicroPython Development Using Thonny IDE and How to install MicroPython on ESP32 and download firmware […]

Leave a Reply

Your email address will not be published. Required fields are marked *