MicroPython on NodeMCU

What is NodeMCU

If you heard about “Internet of Things”, NodeMCU is an opensource IOT platform on which you can build your IOT projects. This is based on eLua firmware as it houses the ESP8266 Wifi module on board made by Espressif. We have separate post explaining the NodeMCU, the link will be added soon. Get one for the best price here.

What is MicroPython

MicroPython is a small and efficient implementation of Python 3 programming language. Though this does not include the whole modules and features of  normal Python, it houses as small subset of Python standard library and is optimized to run on Microcontrollers like NodeMCU.

Pre-requisites for Flashing MicroPython on NodeMCU

As NodeMCU has an in built eLua firmware inside it, we need to flash MicroPython on to NodeMCU. So, when you need to flash we need few things here.

Boards: Any board with ESP8266 is supported with MicroPython. NodeMCU also has an ESP8266 and I have used NodeMCU 12E for this tutorial.
This board also has a built-in USB-Serial converter to make the UART available to your PC.

Memory: Atleast 1Mbyte. Yeah there are 512KB boards, but not recommended as they get flashed but you will face memory problems when programming on it. You cannot even use some features like WebREPL, upip, etc.

Firmware Download: You can see three types of builds in MicroPython downloads page.

Stable firmware builds for 1024kb modules and above.
Daily firmware builds for 1024kb modules and above.
Daily firmware builds for 512kb modules.

The best to go with is Stable frimware builds, until you are a super experienced working with ESP8266. This is the link to Stable firmware.

Note: I prefer you to download “esp8266-20170612-v1.9.1.bin” than the most recent one.

Tools : You will require a flashing tool called “esptool.py” to flash your NodeMCU. Please download it from GitHub. Next, Serial Monitoring tools like Picocom, Minicom.

Installing Tools and Flashing MicroPython

Now time to get hands dirty!!
Install the esptool using the following command:

Versions starting with 1.3 support both Python 2.7 and Python 3.4 (or newer). An older version (at least 1.2.1 is needed) works fine but will require Python 2.7.

Connect the USB cable to the computer and the board. It is recommended to flash your NodeMCU before installing and you can do it with esptool.py. Here is the command:

To check your serial port connections in Linux you can use

Once erased, it is time to flash the MicroPython bin file you have downloaded.

Please check your “port” before you run this and update the relevant for your PC. Also, if you come across any errors, you can reduce the baud rate from 460800 to 115200. And lastly, the filename of firmware should be matched.

If the above commands run without error then MicroPython should be installed on your board!

Accessing MicroPython

As you have installed MicroPython, now it is time to work with it. Remember, I asked you to install Picocom or Minicom tools before?? Now type the following to connect with the board:

Once you are in you need to see “Terminal ready” message at the end and a cursor blinking.

 

 

 

 

Press “Enter/Return” key twice and you should see the MicroPython REPL (Read-Eval-Print Loop) prompt. This is an interactive MicroPython prompt (similar to IDLE for python).

Checking if MicroPython installed correctly

Once you see the REPL prompt (which looks like three greater than symbols  “>>>” ), type in the following:

The last output value is True, Hurray!! then your installation of Firmware is successful. If not, re-flash and install again.

This is the REPL over the serial port, a way of connecting to your MicroPython.Using the REPL is by far the easiest way to test out your code and run commands.

Other way of talking to MicroPython:

You can also connect to MicroPython using a WebREPL. This is a browser based interface. You can connect to this via WiFi connection. More details on this on an other post where I explained connecting of Wifi in detail.

So, here is the detail on how to install MicroPython Firmware on NodeMCU an ESP8266 board. I dont mind your suggestions on improvising this, so feel free to comment below.

 

 

 

 

 

Share it with your friends now!

You may also like

Leave a Reply

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