> For the complete documentation index, see [llms.txt](https://reacoda.gitbook.io/reacoda/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://reacoda.gitbook.io/reacoda/control-leds-using-nodemcu-and-micropython-part-1.md).

# 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&#x20;

**What will we learn?**

1. Preparing your coding environment -  installing microPython.
2. Flashing microPython on your NodeMCU dev kit using Thonny IDE.&#x20;

### Flashing microPython firmware  on esp8266 using esptool via Thonny ID&#x45;**.**

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

```
pip install esptool 
```

![](https://2671334201-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3OADOGtKzS60vUfrw%2F-MAkuay60MFiwIaI3p4f%2F-MAkumPGG0o3tY-JLBTw%2FmicroPython.PNG?alt=media\&token=dd764f09-987b-48e9-9038-db64d2bb5d9b)

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

![](https://2671334201-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3OADOGtKzS60vUfrw%2F-MAlOP2dMV0OjWN-joP5%2F-MAlYQ4oj3cyfoOnUSsp%2Fmpythonfirmware.PNG?alt=media\&token=5aa42c83-4d64-41c5-816f-ffa78b1497b3)

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&#x20;

**Erasing ESP8266 Flash memory**&#x20;

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&#x20;

```
esptool.py --chip esp8266 erase_flash
```

![](https://2671334201-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3OADOGtKzS60vUfrw%2F-MB65Dn-VvPGtqhrKcgE%2F-MB65razxWGxWNmLWEX8%2FmicroPython\(1\).PNG?alt=media\&token=68e8dd31-54b1-4a1f-b82a-c14e3c802e3e)

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.&#x20;

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:

![](https://2671334201-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3OADOGtKzS60vUfrw%2F-MBEXEvFjVIGOOgTSwDB%2F-MBEkd4fVlevK1bKD605%2FmicroPython\(2\).PNG?alt=media\&token=cd3ea747-436f-4854-b677-3782f17358a2)

At this point, you have successfully flashed the esp8266 firmware on your nodeMCU.&#x20;

**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.&#x20;

&#x20;
