Become a subscriber (Free)

Join 29,000 other subscribers to receive subscriber sale discounts and other free resources.
:
:
Don't worry -- youre-mail address is totally secure. I promise to use it only to send you MicroZine.

How to Flash NodeMCU Firmware

This Tutorial shows you how to flash the new nodeMCU firmware into a ESP8266. This is also useful to get back to the LUA interface if you were uploading C/C++sketches using the Arduino IDE - which overwrites nodeMCU lua data.

This tutorial shows you how download and flash the latest version - since Feb 2019 some older library code has been deprecated - especially timer operation so its best to get going with the new code rather than learn outdated methods.

This information allows you to switch between Lua scripting and Arduino IDE programming easily - just by reprogramming the ESP8266.

installing Lua on an ESP8266 will allow you to use the LUA scripting language in an interactive terminal. This means code upload is far faster than the Arduino IDE compile-link-upload process.

Note: Lua is not yet ready for the ESP32 but seems to be in progress so keep an eye on the site: nodemcu-build.com

Although scripting languages are slower the processor is fast (which compensates for scripting speed) and you don't wait around for an upload as you do with the ESP8266 Arduino IDE - and Arduino IDE uploading takes about a minute so making small frequent changes is a pain. With scripting - its a few seconds and you're done. The only disadvantage is that its not C so you're going to have to learn a bit.

Breakout Board Used

The board used for experiments here is the Lolin NodeMCU V3 which has a very convenient USB interface that allows you to plug it into a PC - power is supplied from the USB port - but you will need up to 300mA~400mA (depending on the WiFi activity!) so don't use a hub, use a PC USB port or you might need an external power source.

NodeMCU firmware Update program

pyflasher start up screen

This is the easy-to use ESP8266 breakout board

Lolin nodeMCU V3 Board
Lolin NodeMCU V3 ESP8266 ESP-12E

Note: Other boards such as the ESP-01 and those without a USB interface require you to keep GPIO0 low for programming. The Lolin nodeMCU board however has this pin controlled using outputs from the USB serial chip - so its all automatic - just plug in and flash the firmware.

External Power Source

You can add an external power source to the Vin connection on the board with voltage >5V. Also connect ground labelled 'G' to complete the circuit.

Warning: The AMS1117 absolute maximum input voltage is 15V.

Find out the NodeMCU serial port in use

You can find out which port your nodeMCU is attached to by starting Control panel and navigating to hardware and "Device Manager" to find the following screen:

Device manager showing NODEMCU ESP6288 com port

Reading the documents at : https://nodemcu.readthedocs.io/en/master/en/flash/

Says the following:

flash-mode is qio for most ESP8266 ESP-01/07 (512 kByte modules) and dio for most ESP32 and ESP8266 ESP-12 (>=4 MByte modules). ESP8285 requires dout.

ESP8266 Flash Downloader

This method of flashing the ESP8266 to install the latest nodeMCU firmware uses the latest tool - which is also very easy to use, however you need to go and get a binary file for it to program into the chip - not too difficult.

Download pyflasher to install nodeMCU firmware

Download the following tool:

win32.exe here.
win64.exe here.

This will download the pyflasher that is python based but you won't need to install other files just double click and go.

The downloaded filename is : NodeMCU-PyFlasher-4.0-x64.exe

It looks like this:

pyflasher start up screen

Get a nodeMCU firmware Cloud Built Binary

Before you can use pyflasher go and get a binary sent to your email account (for the default settings this takes ~2 minutes). It sounds a bit intimidating but the steps are easy - there's only a few and its not that hard.

Visit this page...

https://nodemcu-build.com/

...and keep the default options - at the moment only the ESP8266 is supported and that's what's in the nodeMCU board so that's fine. Enter your email, click the "Start Your Build" button and wait for the binary. Here's what the options look like:

nodeMCU build options

Note: You can see the functions available for each module by clicking on the book symbols next to each check box.

The idea is to include those you need since space is limited on the ESP8266.

Programming the ESP8266 using pyflasher

Again don't forget to close the ESP8266 serial port you may have been using!

Download the float version of your binary - this is recommended even though it uses more memory but is up to you.

Settings:

  • Keep the serial speed at 115200.
  • Choose the serial port or use auto detect.
  • Choose DIO for ESp-12E
  • Choose Erase Flash - just to make sure!

Click "Flash NodeMCU":

pyflasher finished

Note: When you start the serial terminal this Lua interface uses 115200 baud not the 9600 as the previous version used.

Warning: The ESP8266 does not start immediately - When you first start it it will format the ESP8266 file system - takes about 40 seconds.
This is the output you will see - not just one line as for the 2015 version of nodeMCU:

nodeMCU latest binary terminal output

The above screen is from the ESPlorer terminal.

Testing the LUA interface

Type a command into the lua interface (into a serial terminal):

   >print("Hello world")

it will respond with:

   Hello World
   >

Note: this is all interactive - there was no compiling a C source file and waiting for upload.

NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
lua: cannot open init.lua
> print("Hello World")
Hello World
>

A Simple ESP8266 LUA Example

Controlling a GPIO pin using LUA

Now lets try and turn on an LED

LED Current calculation

If you don't want to add an external LED use pin 4. Current schematics don't show it but I found it by accident. LED operation is inverted, for this pin, since it is pulled high so digital write low sets the LED on.

Note: Some people do not use a resistor in series with the LED but that is relying on the max current from the nodeMCU as 12mA - other boards will allow more current out (and blow up the LED) so it is best practice to use a resistor - when you forget which board you are using!

I use a 1k since you can see the LED even with that high value. For this case current = (3.3-2)/1k = 1.3mA - you can se it so it is good enough for testing

The usual case is to use a 330R resistor in a 5 volt system. In that case you get (5-2)/330=10mA.

LEDs can usually take 20mA so choosing 10mA for a 3V system gives R= (3.3-2)/10e-3 129R so 120R would do.

LED Connection

Connect an LED and resistor on a breadboard to D0.
LED Round side to D0
LED flat side (look closely) to resistor
other end of resistor to Ground (G).

Type the following commands:

> gpio.mode(0,gpio.OUTPUT)
> gpio.write(0,gpio.HIGH)
> print(gpio.read(0))
1
> gpio.write(0,gpio.LOW)
> print(gpio.read(00))
0
>

You can see the LED turning on and off using the interactive Lua script interface.

What's Next

NEXT: Now you have updated the Firmware and Lua is working on your ESP module. The next thing to do is to install a Lua uploader/Editor. This makes it easy to upload files to the device, and program it over the serial connection. One popular uploader is ESPlorer.

Forwards to Using ESPLorer and Lua>>>
I would prefer the Arduino IDE>>>

New! Comments

Have your say about what you just read! Leave me a comment in the box below.



Privacy Policy | Contact | About Me

Site Map | Terms of Use



Visit our Facebook Page:
To Visit Click Here


Recent Articles

  1. How to use the ADS1115

    A tutorial on using the ADS1115 precision 16 bit ADC for low power use.

    Read more

  2. ESP8266 Webserver in Lua

    ESP8266 Webserver: This code shows you how to use lua to create a webserver using html button inputs to contrtol an LED on the ESP module.

    Read more

  3. ESP8266 NodeMCU Firmware: ESP8266 flash

    How to flash nodemcu firmware into a ESP8266 so you can use the LUA scripting language.

    Read more

  4. NodeMCU Examples

    Nodemcu examples starting off wioth simple ones and progressing to wifi coding. This is an excellent tutorial to start learning how to use nodeMCU with lua.

    Read more

  5. How to use ESPLorer to upload lua scripts

    Find out how to download the ESPLorer and use it to upload lua scripts

    Read more

  6. The TCS230 Color Sensing Chip: How it works and how to use it.

    How to use the TCS230 (/TCS3200) Color detector chip and easily add it to any of your projects.

    Read more

Readers Comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."

- Ranish Pottath

"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com<

"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


Learn Microcontrollers

"Interested in
Microcontrollers?"

Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon

Back to Top