HomeESP8266/ESP32Flashing ESP8266 with NodeMCU (Windows, Linux, Arduino and Raspberry Pi)

Flashing ESP8266 with NodeMCU (Windows, Linux, Arduino and Raspberry Pi)

How to flash NodeMCU on ESP8266 boards via serial port or Arduino

ESP8266 is the most popular connected microcontroller out there. If you want to take advantage of it, you need to flash a firmware first. There is more than one option when it comes to firmware but flashing ES8266 (and ESP32) method remains the same regardless. This tutorial will show you how to flash ESP8266 (and other boards like ESP32 & ESP8285) and how to program it.

ESP8266 Flash Guide

Before we start with the ESP8266 flash guide, I would like to highlight 2 most common issues that you may encounter. If you follow this guide with these in mind, you should have no issues whatsoever if you keep these points in mind

Issue no 1

Always double-check the jumper cables. Regardless of how good and clear a guide is, if you fail to connect the cables correctly – you won’t be able to flash the microcontroller. Trust me when I say this. These mistakes are far too easy to make.

Put aside 5 jumper cables in different colours and use it just for flashing. Be consistent with how you use the colour coding (Vcc-Red, GND-Black, RX-Green, TX-Blue, GPIO00-Yellow). It will help you with keeping things organized!

Issue no 2

ESP8266 is a 3.3V board. Unless it comes as a dev board with power regulator or similar, make sure to use a correct power supply. While we are talking electricity, the current must be sufficient to flash the board successfully. 500mA supply is recommended. USB 2.0 port should be enough to deliver it.

Buy ESP32

Buy it using these links to support NotEnoughTech.

Preparations

There is more than one tool out there to complete the process. If you are going to flash Tasmota on your ESP chip, consider using Tasmotizer (more about it in this post). It will save you time and there is no need for the software requirements below.

Start with the software, mostly because the download will take you a few moments, this will give you some time to hook up the jumper cables correctly. You will need several programs. Once the firmware is flashed, you will use only one.

Software requirements:

Hardware Hookup

Get serial port adapter  (FTD1232) if possible, you can also use Arduino Uno to flash the firmware.

Take a closer look at your serial port adapter. There are 2 ways to connect your ESP8266, but before you do this make sure your adapter is not running at 5V. Mine has a bridge which selects the 3.3V and 5V. You want to make sure that ESP8266 is running on 3.3V.

Another thing to note is the DTR pin. The FTD1232 has that pin available, other adapters may not.

ESP8266FTD1232 DTRFTD1232 no DTRArduino Uno
VCC & CHPDVCCVCC3.3V
GNDGNDGNDGND
TxRxRxTx
RxTxTxRx
GPIO 00DTR or GNDGNDGND
GPIO 16/RSTGND (don’t connect)GND (don’t connect)GND (don’t connect)

Don’t use external power, it can mess up the flash process. Connect cables as per the table above. For GPIO16/RST – reset pin use female-male cable and leave it hanging from the ESP8266. You will need it to touch the GND pin to reset the ESP.

If you have more than 2 ESP8266 consider making an adapter, reconnecting the cables each time is annoying. I have a nice build log here.

If you are using the Arduino as the serial adapter you have to also connect the RESET pin on Arduino Uno to the GND. This will put the microcontroller into the adapter mode.

Lastly, check the cables again. It’s easy to get something wrong.

Flash

I will show you how to erase the flash, which could be the issue of all your troubles. It’s a good point to start and not many sources mention this step. If you are on Windows, you need Python 2.7 installed and the pyserial library (links above). If you are on Linux or a Raspberry Pi, things are a little easier for you – just:

git clone https://github.com/espressif/esptool.git
cd esptool

The easiest way to get the ESP8266 into the flash mode is:

  1. Pull down the GPIO 0 (connect it to GND or DTR, DTR may not work with esptool)
  2. Start the flash (press Flash button or execute the cmd command)
  3. Reset the ESP8266 by pulling down the GPIO16/RST pin  (touch any of the GND pins with a male end)

Open the folder with esptool and bring up the cmd (right click +shift > Open command window here). Check what port has been assigned to your FDT1232 by bringing up a device manager.

If you are on Linux or Raspberry Pi use: $ dmesg | grep tty. This should give you a device port name:/dev/ttyUSB0. Run the command (python.exe path + esptool.py --port [your com port here] erase_flash)

>>c:\Python27\python esptool.py --port COM5 erase_flash

Execute the line and then immediately reset the ESP. You should see this:

If you on the Linux or Raspberry Pi, you can continue with the esptool, if you are using Windows you can now switch to the NodeMCU flasher tool.

I’ll continue with the esptool as we are one command away from the firmware flash:

>>c:\Python27\python esptool.py --port COM5 write_flash -fm dio -fs 8m 0x00000 C:\node1.bin

The command is built in the following way: (path to python) esptool.py — port [your com port] write_flash -fm [mode: dio for 4MB+, qio for <4Mb]) -fs (flash size 8Mb in my case) 0x00000 (path to bin file)

As before, execute the command and reset the ESP8266 by shorting the GPIO16/RST pin to GND.

If you are using Windows and NodeMCU flash tool the procedure is similar:

Then press flash and reset the ESP8266 by shorting the GPIO16/RST to GND:

The flash will take few moments and you will see the progress:

Once the flash is complete you are ready to upload your Lua files. This is where the ESPlorer comes in handy. Disconnect the GPIO 0, we don’t need it any more. Set the baud rate to 115200 open the COM port and reset the ESP8266 by shorting the GPIO16/RST and GND. Your screen should look like this:

Congratulations. You are nearly done! While this is not a Lua script tutorial I will provide you with a init script. Init is the file that loads on boot. It should contain the vital set up of your script. Avoid entering the entire project into the init file, get the init file to set up your environment, connect to the network and launch the needed scripts. It’s a good idea to create a wait in the init file in case you made a mistake. This way you will have a few seconds to flash new init file even if your ESP8266 ends with a boot loop.

function startup()
    if file.open("init.lua") == nil then
        print("init.lua deleted or renamed")
    else
        print("Running")
        file.close("init.lua")
        dofile("YOUR_SCRIPT.lua")
        
    end
end
signalPin = 3
gpio.mode(signalPin, gpio.OUTPUT)
gpio.write(signalPin, gpio.LOW)
print("Connecting to WiFi access point...")
wifi.setmode(wifi.STATION)
wifi.sta.config("YOUR_SSID", "YOUR_PASSWORD")
-- wifi.sta.connect() not necessary because config() uses auto-connect=true by default
tmr.alarm(1, 1000, 1, function()
    if wifi.sta.getip() == nil then
        print("Waiting for IP address...")
    else
        tmr.stop(1)
        print("WiFi connection established, IP address: " .. wifi.sta.getip())
        print("You have 10 seconds to abort")
        print("Waiting...")
        tmr.alarm(0, 10000, 0, startup)
    end
end)

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

M5Paper

Programable, ESP32 based awesome dev platform with 4.7 e-ink display by M5Stack

More HATs

client-image
client-image

Argon One M.2

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO and M.2 SSD support

More cases on

client-image
client-image

Best Raspberry Pi Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

Slow Internet Warning

0
From time to time my Internet grinds to a stop. Since Raspberry Pi 4 comes with a 1Gbps Ethernet, I decided to take advantage of it and create a reporting system in NodeRED that will monitor and report when the ISP is not keeping the contractual agreements. Works with Alexa, Google Home, Android and Windows 10.

How fast Raspberry Pi NAS is?

0
Let's see how fast Raspberry Pi NAS really is?

Argon18: Argon ONE SSD modification

0
Argon One case just got better - now you can boot it from USB without ruining the design thanks to Argon 18: Argon One SSD modification

HOW TO...

It took me 2 months to boot CM4 from NVMe

0
Complete beginners guide to Compute Module 4 boot from NVMe.

Raspberry Pi Zero 2 W vs other Zero boards

0
It's time to test the Raspberry Pi Zero 2 W against other Raspberry Pi boards from Zero series: power, WiFi, temperature and core performance

C/C++ and MicroPython SDK for Raspberry Pi Pico on Windows

0
A guide to SDK toolchain for Raspberry Pi Pico and C/C++ , Micropython on Windows.

A comprehensive guide to Grafana & InfluxDB

0
How to use Grafana and InfluxDB on Raspberry Pi for IoT sensors in home automation

How to boot Raspberry Pi 4 from USB

0
How to set up and boot Raspberry Pi 4 from USB drive - headless guide.