Introduction: How to Flash NodeMCU Firmware in ESP8266
ESP8266 has become the de facto board for IoT prototyping applications and even for some complete commercial producs .So it has become necessary for any IoT hobbyist to learn to program ESP8266 SoC through some means. Currently there are three ways to flash and program ESP8266
- AT Commands
- ESP8266 Official SDK
AT commands is like the most primitive way for using your ESP.While it is easy very to flash AT command firmware (mostly it'll be available by default) it is far more difficult while writing complex programs involved in home automation
ESP8266 SDK is the latest means of flashing firmware which developers are still struggling due to lack of proper documentation and tutorials.Once you are able to flash the firmware properly in your ESP then you can start building your applications based on embedded C very easily
So what was actually needed was a firmware which was easy to flash into ESP like the AT command firmeware and write applications based on it very easily like the ESP8266 SDK.
NodeMCU by default refers to the firmware although it encompasses a complete open-source IoT platform including firmware,documentation and a development kit based on ESP12E module.The firmware uses Lua scripting language and is based on eLua project built upon ESpressif Non-OS SDK. As of now NodeMCU is maintained as an open source project with great documentation and an awesome online community to help you in every step
Step 1: Components Required
- An ESP8266 board.The board which is used for this instructable is NodeMCU devKit v1.0
- A micro to USB (type male) cable to upload the code to NodeMCU devKit v1.0 and power the device
- NodeMCU firmware build files (Explained below)
- USB to TTL convertor and associated drivers. NodeMCU devkit already has the convertor in the board.Just download the appropriate driver (CP2102 / CH340)
- ESplorer application (link)
Step 2: Get the Required Build Files
NodeMCU supports over 40 different modules including various IoT protocols such as MQTT, CoAP etc.But due to resource constraints of the ESP SoC we need to select the required modules and build the firmware to be flashed.
Fortunately there is a cloud based build service available to do the same job NodeMCU Cloud build service .It has a nice UI where user just needs to select the required modules and the cloud service will build the files.By default the basic modules will be pre-selected.Select the necessary modules which is required for your application and click on Start your build.You will receive the build files via e-mail within an hour
Do not select debug or SSL support checkbox if you are a beginner as you most probably won't be needing it.Please make sure you download from the given link as soon as possible as it's active only for 24 hours
Step 3: Flash Mode in ESP
To enable ESP8266 firmware flashing GPIO0 pin must be pulled low before the device is reset. Conversely, for a normal boot, GPIO0 must be pulled high or floating.
If you have a NodeMCU dev kit(ESP 12) then you don't need to do anything, as the USB connection can pull GPIO0 low automatically while flashing. If you have an ESP-01 or other device without built-in USB, you will need to enable flashing yourself by pulling GPIO0 low or pressing a "flash" switch.
Step 4: NodeMCU Flasher for Windows
NodeMCU flasher is a firmware programmer for NodeMCU DEVKIT V0.9. You can use it to program NodeMCU DEVKIT or your own ESP8266 board.As of now it works only on Windows but the creator of this tool has promised to come up with a cross platform tool in near future.
Download for the link based on your OS version 64 bit or 32 bit
Check out this article if you want to flash it from linux environment http://invent.module143.com/2016/07/21/nodemcu-tutorial-1/
Step 5: Flashing the Firmware
Open NodeMCU flasher application and click on "Log" tab.Initially it'll be empty
- Now connect your ESP device to the computer after enabling flash mode
- The COM port number will be displayed in the log tab
- Go to "Config" tab and select the file you had created using cloud service,The address should be 0x00000
- Go to Operation tab and click on Flash button.The MAC address and COM port will be automatically filled and the progress bar starts moving
- If you check the log tab now it'll show you the status of flashing each block
- Once the flash is successfully completed you will get a green tick on bottom left corner
Now your ESP device is ready to be programmed using Lua scripts.Remove the USB cable and connect again to bring the device back to normal mode
Step 6: Checking in ESPlorer
Download ESPlorer from here and extract the zip file.Make sure that ESP device is connected and double click on ESPlorer.jar file to open the application.Your system should have atleast Java SE Runtime 7 installed.
Left panel is for creating and editing Lua scripts and right panel acts as a serial monitor.Select the COM port and Baud rate(By default it'll be 9600) and click on Open button.If your firmware is properly flashed into ESP you will get the message "NodeMCU firmware detected" as shown in the image.
Step 7: Possible Issues While Flashing
- Log screen showing error message in NodeMCU Flasher :
If the log screen shows error message unplug the device and connect again until it auto detects the port.
- COM port not detected in ESPlorer:
If port is not selected by default close and reopen ESPlorer application
- After clicking Open serial monitor just displays "Communication with the MCU…":
Two possible scenarios
- If it is stuck at Communication with the MCU… double click on RTS near Open button until there is a response from the MCU.
- If it throws some random garbage values or not responding keep changing the baud rate value between 9600 and 115200 until you get a “>” symbol as shown in the image. Then set the baud rate to 9600.
Question 3 years ago
It cannot auto detect even when I keep reconnecting.
5 years ago
Step 2 is missing one thing. "Branch to Build From" choice is not clear.
6 years ago
Arunmozhi sir how can i know the default baudrate of firmware flashed ?
6 years ago
Welcome to Instructables. Thanks for sharing the great tutorial.