• EUR€
  • £GBP
  • $USD

ESP32 Tutorial: MicroPython support

DFRobot Jul 11 2017 1751

The objective of this micropython tutorial 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 setup.py file there. Assuming that Python is already installed, navigate to the unzipped folder and enter the following command:

1  python setup.py 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.

1 esptool.py --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.

1 esptool.py --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.

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.

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:

1 print ("Hello World From ESP32 MicroPython")

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

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!

NOTE: This article is written by Nuno Santos who is an kindly Electronics and Computers Engineer. live in Lisbon, Portugal. you could check the original article here.
He had written many useful tutorials and projects about ESP32, ESP8266, If you are interested, you could check his blog to know more.

DFRobot supply lots of esp32 arduino tutorials  and esp32 projects for makers to learn.