Control LEDs using NodeMCU and microPython - Part 1

This is an introductory guide to using microPython on NodeMCU dev kit board to control LEDs.

Introduction

What will we learn?

  1. Preparing your coding environment - installing microPython.

  2. Flashing microPython on your NodeMCU dev kit using Thonny IDE.

Flashing microPython firmware on esp8266 using esptool via Thonny IDE.

On a Windows computer, open the terminal (CMD) and run the following command:

pip install esptool 

Download the latest version of the microPython firmware for esp8266. You need to download the latest esp8266.bin file

It is very important to know on which port is your NodeMCU board is connected via the USB cable. The simplest way to do this is to use the Arduino IDE. The first you will need to do is connect your NodeMCU to your computer via the USB cable. Open the Arduino IDE software and click on Tools > Port > see port number

Erasing ESP8266 Flash memory

Before you can flash the esp8266 firmware on the NodeMCU, it is important to erase the memory. Hold down the Boot/Flash button on the NodeMCU, while holding it down run the following command

esptool.py --chip esp8266 erase_flash

When the Erasing process start, you can release the Boot/Flash button.

Flashing microPython firmware on esp8266 using esptool.py

To flash the esp8266 firmware you need the port name on which your NodeMCU is connected.

Run the following command:

esptool.py --chip esp8266 --port <serial_port> write_flash --flash_mode dio --flash_size detect 0x0 <esp8266-X.bin>

In our case, this is the command we will run:

esptool.py --chip esp8266 --port COM11 write_flash --flash_mode dio --flash_size detect 0x0 esp8266-20191220-v1.12.bin

This is what you will see after running the command:

At this point, you have successfully flashed the esp8266 firmware on your nodeMCU.

N.B. If you get an error while trying to flash the firmware, run the command again while holding the FLASH/BOOT button on the nodeMCU board.

Last updated