Hi Readers,

This post is intended to introduce the Micropython development in ESP8266. This enables rapid development in the ESP core, which will make us more productive.

What is Micropython?

MicroPython is a lean and efficient implementation of the Python 3 programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments.

This post will be split into 3 categories.

1) Setting up the development environment

2) Installing Micropython interpreter in the ESP based Chipset

3) Running/Uploading Micropython scripts

Setting up the development environment:

Install Esptool using the following command(Following commands will work in Linux users. Windows users- please grow up :) )

sudo pip install esptool

Install ampy uploader for uploading the micropython scripts

sudo pip install adafruit-ampy

Download ESPlorer as IDE

Installing Micropython interpreter in the ESP based Chipset

For using Micropython in the ESP chip, there should be an interpreter firmware that is to be flashed to the ESP. Appropriate firmware for your ESP chip can be downloaded from the following link

https://micropython.org/download#esp8266

Use the following command to flash the firmware

esptool.py --port /dev/ttyUSB0 erase_flash

esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20180511-v1.9.4.bin

Note: You may need to change the serial port to reflect your phisical connection with the ESP chip.

Check whether everything is successful by opening a serial terminal with 115200 Baudrate and 8-N-1 configuration and reset the board. You should get the Micropython terminal ready to consume your commands!!

Running/Uploading Micropython scripts

Create a file named test.py and add your code in this file. This file can be uploaded and run using ampy command.

ampy -p /dev/ttyUSB0 put test.py

ampy -p /dev/ttyUSB0 run test.py

To run the file at the start up(ie. when power cycling) just rename the test.py to main.py and upload using the above command.

Bonus Information!!

Download ESplorer IDE from https://esp8266.ru/esplorer/.

You will get a zip file. Extract the zip file and run the following command. (Assuming you have java installed in your system)

cd <path to ESPlorer>/

java -jar ESPlorer.jar

References:

Mcropython ESP website: https://micropython.org/

Documentation: https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/index.html