If it helps someone.

Menu

ESP8266 with NodeMCU firmware

ESP8266 wifi module is a low cost (less than $5) , self contained module with integrated TCP/IP stack. The module comes with firmware using which the module can be controlled with simple AT commands. The module has its own application processor. So, instead of using AT commands, if we have a mechanism by which we can program the device itself, it will help in offloading some work which otherwise would be done by an additional microcontroller. ESP8266 firmware SDK is available and anybody can write their own firmware. To make the job easier there exists a firmware by NodeMCU, using which we can program ESP8266 in LUA programming language. In this article I will explain about using ESP8266 with NodeMCU firmware. This will be the basis of all other ESP8266 tutorial in my blog where I use NodeMCU.

About NodeMCU

For ESP8266 NodeMCU provides various modules using which we can control GPIO, access UART, configure wifi etc. Default firmware from NodeMCU comes with all modules. But I found a better solution where you can get custom build with selected list of modules. Thanks to http://frightanic.com/nodemcu-custom-build/, select the modules you want and you will see a link to the firmware binary file in your mailbox.

Wiring for ESP8266 with NodeMCU firmware flashing and programming

There is small difference in connecting the module for flashing and then for programming. It is just the matter of connecting an extra pin. See the table below.

Pin

Working Mode

Flash Mode

Details

VCC

3.3V

GND

Ground pin. Connect to ground pin of UART module

TXD

Connect to RXD of UART

RXD

Connect to TXD of UART

CH_PD

HIGH

HIGH

Chip Select

GPIO0

HIGH

LOW

In working mode it is optional to set this to HIGH

GPIO2

HIGH

HIGH

Here is the connection diagram. You can disconnect the GPIO0 after flashing as it is not required for programming.

Uploading the firmware

Get the NodeMCU firmware with the set of modules you will be using. We also need a firmware flasher. There are two flashers which I liked very much.

nodemcu-flasher

This program works only on Microsoft Windows platform. You can find the exceutable in gitbug project https://github.com/nodemcu/nodemcu-flasher. Run the flasher executable. Follow the steps below to update ESP8266 with NodeMCU software

When application is launched, it will show list of COM ports it can detect. So, make sure that you see the port to which ESP8266 module is connected.

Switch to Config tab and select the appropriate file you need to flash by clicking the ‘gear’ icon on the the first row. Leave rest of the fields to default.

Switch to Advanced tab and make sure you have selected the right Baudrate. With default firmware, it may be 115200, 57600 or 9600. But do check with these two options as well.

Once all these options are set, click the Flash button in Operation tab. If all settings are fine, you will see AP MAC and STA MAC willed with some values. If it did not in few seconds, check the connections and options in Baudrate in Config tab.

Now you should be able to see a progress bar which shows progress of the action. It will take few minutes to complete the action.

esptool.py for Linux

On linux systems, you can use esptool to flash the device. You can download the file from https://github.com/themadinventor/esptool. Here is the command you can use. Please change the name of binary file , device and Baudrate to suite your device.sudo ./esptool.py --port /dev/ttyUSB0 --baud 9600 write_flash 0x00000 nodemcu.bin
If you the following message, we are in good shape and the firmware is being updated.
Connecting...
Erasing flash...
Writing at 0x00004400... (5 %)

But if it is stuck at Connecting…, then you need to check the connections and Baudrate before rerunning the command. Also, make sure this device is not opened by any other application.

Check the new firmware

Once everything is done, disconnect the GPIO0. You can either connect to HIGH TTL or leave it open. I prefer to connect to HIGH TTL. You can open your favourite serial port terminal. After you connect the device to the UART, you may have to disconnect the power and connect again to reset or use the reset pin. I connect a switch between UART VCC and VCC pin of ESP8266 module. You should see a message like