MicroPython Basics Using NodeMCU (ESP8266)

About: I love DIY Electronics

MicroPython is a project that allows you to run a miniature version of python 3 on micro controllers and embedded boards. It has a growing support of microcontroller boards and rather than installing a full Linux distro onto the board it only gives a minimized version of python with respect to the board, with a python shell and you can upload small python files on to the board and run it.

In this instructable I will be showing you how to use MicoPython on a NodeMCU, the NodeMCU is a development board based on esp8266-12.

Step 1: Tools and Components

For this project you will need a,

  • NodeMCU
  • LEDs
  • Servo
  • Breadboard
  • MicroUSB Cable

Step 2: Installing MicroPython

To install micropython on the esp8266, I'm using the esp8266-12 version board. To install micropython you will need esptool you will need to download and install python and pip, to install the esptool.

Run the below command on a terminal or cmd to install esptool

pip install esptool

Next you can visit micropython website and download the latest firmware for the esp8266, after downloading it open up a terminal in the same directory as the firmware file and then run the below command

esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-xxxxx-vxxxx.bin

You will need to change the port based on you PC.

After this you should have successfully installed micropython.

Step 3: Testing Blink

Now that you have successfully installed micopython it is time to try out a few test programs to do this we need to open up the python shell using a serial monitor, I use putty on a windows machine to open up a serial monitor on the com port the esp8266 is assigned to.

This python shell is similar to that of the python 3 shell, run the below script to blink an led connected to the esp8266

import esp

pin = machine.Pin(0)

pin = machine.Pin(0, machine.Pin.OUT)

Then running the below line of python script will turn on the led and the second line would turn it off.


alternatively you could also run these lines to do the same


Step 4: Using WebREPL

Now lets enable the micropython WebREPL which allows us to upload scripts to the esp8266 over WiFi hence eliminating the need of wires.

First we need to enable WebREPL, open up a serial terminal and execute the below line, this setups the webrepl and asks you to set up a password to improve security.

import webrepl_setup

Next you should see a WiFi access point named MicroPython-xxxxxx, connect to it and open up a internet browser and visit the webREPL webpage. Now you should get a web page, hit connect and enter the password you created. Now you can execute scripts on the esp8266 wireless.

Step 5: Going Further

Now that you got micropython up and running you can execute scripts on it, similar to what you do a raspberry pi. There are a lot of modules available for micropython to work with and you can get a good documentation of it in the micro python official website under esp8266 category.



    • Optics Contest

      Optics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • Plastics Contest

      Plastics Contest

    6 Discussions


    10 months ago

    i usually have to use "-fm dio" option to get the firmwire written properly on ESP8266, in just one command

    esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash -fm dio 0x00000 firmwire.bin

    1 reply

    Reply 6 months ago

    I'm lost. Maybe you can help me out here. Where do you enter this line?

    esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash -fm dio 0x00000 firmwire.bin


    Question 6 months ago on Step 2

    I am so lost with this. OK so it says you may need to change --port to whatever port you are using. Like how? --com3 --port3 or what? and exactly where to you put this line? At the command prompt? In the Python shell? I've been trying for 3 days to figure this out before asking but it seem as all the other sites give the same cryptic instructions for a newbie


    7 months ago

    I'm finding still too many steps left out or too many things assumed.
    Following word for word I still have not even been able to get esptool installed, let alone anything flashed to the module.


    10 months ago

    This information is very useful for esp8266 test, Thanks.