Using MicroPython with a NodeMCU
Download MicroPython firmware
Download the firmware from http://micropython.org/download#esp8266
Install esptool for flashing the NodeMCU
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
Write the rom to the NodeMCU
- After flashing the NodeMCU with MicroPython, recycle the power on it twice.
Connect to the MicroPython NodeMCU
Connect to the MicroPython NodeMCU using minicom
Verify the MicroPython firmware
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
Startup Scripts
-
There are two startup scripts: boot.py and main.py
- boot.py is executed first
- main.py is executed second
Read the list of files on the filesystem using Python
Read the contents of a file using Python
Write the contents of a file using Python
Configure Wifi
After getting the NodeMCU running MicroPython, the wifi can be configured.