The objective of this post is to explain how to use MicroPython on the ESP8266.
The objective of this post is to explain how to use MicroPython on the ESP8266. MicroPython is an implementation of Python that includes a small subset of the Python standard library and is optimized to run on microcontrollers. Fortunately, one of the supported microcontrollers is the ESP8266, allowing us to run MicroPython in boards such as the NodeMCU.
The installation of MicroPython on the ESP8266 is very straightforward and well explained here, so I’m not covering in detail how to do it.
But to sum up, we will first need to get the firmware from here. After the download, we will have the binary to upload to the ESP8266. Note that the best option is using the stable releases.
Also, take in consideration that there are some limitations for ESP8266 boards that only have 512 KB of flash, which need a special, more limited, version of the firmware. You can get the information of your board’s flash as can be seen here.
To upload the binary file to the ESP8266, we will need esptool, which allows to communicate with the ROM bootloader of the ESP8266. As indicated in the getting started page, the easiest way to get the esptool is by having a Python installation on the computer with pip (a Python package installer), and running the following command:
1 pip install esptool
After the installation, you can check here the commands needed to upload the MicroPython firmware to the board.
On the mentioned commands, please note the the /dev/ttyUSB0 works for Linux (and you still need to change the USB0 to the USB port where the ESP8266 is). On Windows, we should just use COMX, where X is the port of our ESP8266. If we have a previous Arduino IDE installation with ESP8266 support, it will be easy to check in which port is our ESP8266.
Also, when uploading the firmware, don’t forget to put the whole path for the binary file in the esptool command, if you are not executing the command in the same directory of the bin file.
After uploading the firmware, the easiest way to interact with the ESP8266 is by using Tera Term. Tera Term is a Windows terminal program  that will allow us to connect to the ESP8266 via Serial and interact with the MicroPython prompt. You can download it here.
After installing Tera Term, open it and select the COM port of the ESP8266, as indicated in figure 1. Note that my ESP8266 is on COM25.
Figure 1 – Connection to the ESP8266 via Tera Term.
After that, you will get some garbage on the terminal window since, by default, Tera Term has a baud rate of 9600 and the MicroPython prompt uses 115200 . To change this configuration on Tera Term, click Setup -> Serial Port… and change the baud rate to 115200, as indicated in figure 2.
Figure 2 – Changing the baud rate of Tera Term.
Now, if you write something and hit enter, you should get a Python error message, but now in a readable format, as shown in figure 3.
Figure 3 – Tera Term with readable characters.
Now, to finish this tutorial, let’s run some Python code. To do so, just write the following command and hit enter.
1 print ("Hello World")
You should get an “Hello World” message, as shown in figure 4.
Figure 4 – MicroPython ESP8266 “Hello World”.
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.