A little instruction on how to flash NodeMCU on your ESP-01 module. Then you can run LUA code on your ESP8266.
- ESP-01 module
- FTDI UM232R as USB-to-serial adapter (or a compatible adapter)
- Python 2
- Hterm (or any software to view serial communication)
Connection of the module
Pin definition and mapping to the signal names:
The following mapping works for me:
VCC -> 3V3 GND -> GND RST -> 3V3 CH_PD -> 3V3 URXD -> DB0 (UM232R) UTXD -> DB1 (UM232R) GPIO0 -> GND GPIO2 -> 3V3
The jumper for JP1 on the FTDI serial adapter needs to connect 1 and 2, which selects an IO voltage of 3.3 V. Power will be supplied from an external power supply.
Preparation for the flashing
Load the following flash tool by cloning the Github repository:
git clone https://github.com/themadinventor/esptool.git
Now you can load the NodeMCU firmware by cloning it from Github:
git clone https://github.com/nodemcu/nodemcu-firmware.git
After the last step, you can copy the nodemcu_latest.bin from ./pre_build/latest/ into the esptool folder. It is also sufficient to only load this file from Github without cloning the whole repository.
Now we can flash the NodeMCU firmware to the module. Check the serial port number in your hardware manager. My module is connected to port 11. So I will use COM11 for the next command.
python esptool.py --port COM11 write_flash 0x0000 nodemcu_latest.bin
When you encounter an issue where the module is not found, try installing the pyserial module which seems to be missing.
pip install pyserial
If there are connection problems, try reconnecting pin CH_PD to 3.3 V. Maybe you need to repeat this step until the flash process starts.
Test the new firmware
If the flash process was successful we can check if the new firmware runs. We need to establish a serial communication to the module. Use the following settings for the connection with Hterm: COM-port you used for the flash command (COM11 on my module), the baud rate is 9600, newline needs to be set to CR+LF (carriage return and line feed), “Input control” set to ASCII and CR+LF for “send on enter”.
When you new reset your module the following should be written to the serial interface:
NodeMCU 0.9.5 build 20150127 powered by Lua 5.1.4 lua: cannot open init.lua>
For a quick test, we connect an LED with a resistor from GPIO0 to GND. With the following commands, we can toggle the LED via the console.
gpio.mode(3, gpio.OUTPUT) -- GPIO set to output gpio.write(3, 1) -- GPIO set to HIGH gpio.write(3, 0) -- GPIO set to LOW
The number 3 in the command describes the IO index. GPIO0 has the IO index 3 and not 0. Here you can find the pin map for the gpio module.
I will add other test scripts with advanced functionality in the future…
Here you can find other NodeMCU related posts.