ESP32: MicroPython support

The objective of this post is to explain how to flash the MicroPython firmware to the ESP32 and test it with a simple “Hello World” program.


The objective of this post is to explain how to flash the MicroPython firmware to the ESP32 and test it with a simple “Hello World” program.

MicroPython is a implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimized to run on microcontrollers [1]. Fortunately, as there was a port of MicroPython for the ESP8266, there is also one for the ESP32, as can be seen here.

Although we can build the project ourselves (instructions here), the easiest way to start playing with MicroPython is downloading the pre-built firmware and upload it to the board. This will be the approach followed on this tutorial.

This tutorial was made on Windows. The ESP32 board used was this one.

Software needed

In order to follow this tutorial, we need an installation of Python on our machine. This tutorial was created using Python 2.7, but it should work for higher versions.

We will also need a software called esptool to flash our ESP32 with the MicroPython binary. At the time of writing, the stable version of the tool is in 1.x, which doesn’t support the ESP32 yet [2]. So, we can’t install it via pip or other Python package managers, and we will need to do it manually.

So, we will have to download the latest esptool release from here. The version used in this tutorial was v2.0beta2.

After downloading the esptool source code, unzip it to a folder. You should have a file there. Assuming that Python is already installed, navigate to the unzipped folder and enter the following command:

python install

This should install the esptool on your system. If you prefer, you can check the manual installation instructions from the repository of the tool.

Finally, we will needed the binary file with the MicroPython software. You can get it from here. Download it and save it on a folder, since we will need it latter.


The procedure

First, we will need to erase the flash of the ESP32. To do so, just give the command bellow on the command line. You will need to change the “COM5” by the serial port where your ESP32 is connected. --port COM5 erase_flash

After this, we will need to upload the binary to the ESP32 with the command bellow. Again, you will need to change COM5 with your ESP32 COM port. Also, you will need to change the pathToYourFile/BinaryFile with the path where your binary is and the name of the file. On windows, an easy trick is dragging and dropping the file on the command line. --port COM5 --baud 460800 write_flash --flash_size=detect 0 pathToYourFile/binaryFile

After this, you should have MicroPython enabled on the ESP32 board. We will confirm it in a minute.

Testing the installation

To test the installation, we will need an additional tool to interact with the Python prompt. Although we can use other software that allows to establish serial connections, we will use Putty for this tutorial. You can download it here.

So, after downloading the .exe file from the previous link, just open it and the Putty GUI should popup. There, on the connection type, choose “Serial”, on the Serial line put the serial port of the ESP32 (in my case, COM5) and put a speed of 115200. Check figure 1 where these configurations are highlighted.

Putty connect to ESP32

Figure 1 – Connecting to the ESP32 MicroPython prompt with Putty.

After specifying all the configurations, hit open. If everything was correctly configured, you should now get a window like the one in figure 2, with the MicroPython prompt available.

ESP32 MicroPython prompt

Figure 2 – ESP32 MicroPython prompt.

Hello World program

To finish this tutorial, we will print a simple “Hello World” message. So, write the following command and hit enter:

print ("Hello World From ESP32 MicroPython")

You should get something similar to figure 3. In that example, I’ve sent the command twice.

ESP32 MicroPython Hello World

Figure 3 – ESP32 MicroPython “Hello World”.

You can now start playing with Python on the ESP32.

Final notes

I would like to leave a special thanks to the team behind the ESP32 MicroPython port, which promptly made the binaries available after a request I’ve made on the Github page. Also, thanks for making this awesome tool available for everyone!




This entry was posted in ESP32 and tagged , , . Bookmark the permalink.

22 Responses to ESP32: MicroPython support

  1. rui says:

    Porque é que usas o putty em vez do bash de ubuntu dentro do windows 10 (Linux Subsystem for Windows)? Agora é uma feature nativa!

    Liked by 1 person

  2. .pQd says:

    thanks for the tutorial!

    do you know how to enable webrepl on esp32 with micropython installed this way?

    when i try to run “import webrepl_setup” via the com terminal i’m getting “”no module named ‘webrepl_setup'”

    Liked by 1 person

    • antepher says:

      You’re welcome, I’m glad you found it useful 🙂

      I haven’t yet played with webrepl on the ESP32, if I manage to make it work I will do a post about it.

      Best regards,
      Nuno Santos

      Liked by 1 person

  3. Pingback: ESP32 MicroPython: Parsing JSON | techtutorialsx

  4. Pingback: ESP32 MicroPython: Encoding JSON | techtutorialsx

  5. Pingback: ESP32 MicroPython: Connecting to a WiFi Network | techtutorialsx

  6. Pingback: ESP32 / ESP8266 MicroPython: Running scripts from a computer | techtutorialsx

  7. Pingback: ESP32 / ESP8266 MicroPython: Uploading files to the file system | techtutorialsx

  8. Pingback: ESP32 / ESP8266 MicroPython: Running a script from the file system | techtutorialsx

  9. Pingback: ESP32: DFRobot ESP-WROOM-32 Module | techtutorialsx

  10. Pingback: DFRobot’s FireBeetle ESP32 board | techtutorialsx

  11. Pingback: ESP32 / ESP8266 MicroPython: HTTP GET Requests | techtutorialsx

  12. Sean Groper says:

    I followed the link to download the firmware binary files, but the ESP32 section does not have any files listed.

    Liked by 1 person

  13. Pingback: ESP32 MicroPython: Getting started with the uPyCraft IDE | techtutorialsx

  14. Quick comment if anyone runs into the following error.

    After flashing the binary file as described above, I got the following error repeating into infinity on PuTTy:
    rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    flash read err, 1000
    Falling back to built-in command interpreter.

    It appeared to be resolved by changing the flashing command to: –port COM5 –baud 460800 write_flash –flash_size=detect 0x1000 pathToYourFile/binaryFile

    Liked by 1 person

  15. Wessix says:

    Danie Conradie (@MongooseCurious)
    your hint is very important!

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s