Using MicroPython with a NodeMCU

Download MicroPython firmware

Download the firmware from


Install esptool for flashing the NodeMCU

pip install esptool

Flash the MicroPython firmware to the NodeMCU

Start the NodeMCU in ROM Flash Mode

  • Connect the power to the NodeMCU while holding down the Flash button.
  • The flash button will startup the NodeMCU in ROM flash mode.

Connect the NodeMCU using a USB Hub or external power supply

  • The NodeMCU will draw 5.5v of power.
  • If you are programming the NodeMCU using a Raspberry Pi, you will find that the power draw will be too large and your Raspberry Pi will shutdown.
  • I find it easiest to connect to the NodeMCU through a powered USB hub.

Erase the NodeMCU --port /dev/ttyUSB0 erase_flash

Write the rom to the NodeMCU \
  --port /dev/ttyUSB0 \
  --baud 115200 write_flash \
  --flash_size=detect 0 \

  • After flashing the NodeMCU with MicroPython, recycle the power on it twice.

Connect to the MicroPython NodeMCU

Connect to the MicroPython NodeMCU using minicom

minicom --baudrate 115200 --device /dev/ttyUSB0

Verify the MicroPython firmware

import esp

The Internal Filesystem

  • When the NodeMCU boots the MicroPython framework for the first time, a FAT filesystem will be setup in the firmware.

  • The filesystem can be accessed over (Web)REPL using the appropriate client.

List files via REPL

import os

Startup Scripts

  • There are two startup scripts: and

  • is executed first
  • is executed second

Read the list of files on the filesystem using Python

import os

Read the contents of a file using Python

with open("", "r") as f:

with open("", "r") as f:

Write the contents of a file using Python

with open("myfile.txt", "w") as f:
  f.write("Hello world!")

Configure Wifi

After getting the NodeMCU running MicroPython, the wifi can be configured.

categories: micropython | esp8266 | nodemcu |