Hi, guys. This tutorial is for helping you to flash firmware in your favorite ESP8266 module. I guess almost all of you have a good enough idea about ESP8266. Still, here a short note on it for you. Let’s get started,
What ESP8266 Is?
The ESP8266 is a low-cost Wi-Fi chip with full TCP/IP stack and microcontroller capability produced by a Shanghai-based Chinese manufacturer, Espressif. The chip first came to the attention of western makers in August 2014 with the ESP-01 module, made by a third-party manufacturer, AI-Thinker. This small module allows microcontrollers to connect to a Wi-Fi network and make simple TCP/IP connections using AT commands. It also has a decent amount of internal memory (512kb-4mb), so it can also be used as a standalone IoT device with a lesser number of GPIO pins.
Enough, now let’s go back to the main topic again.
Problems That We Face With It
No doubt this module is super cheap, hence a mouth-watering grab for electronics hobbyists who want to make their projects talk to the cloud. BUT, this module may even give you nightmares. As proper documentations are unavailable, a lot of confusion occurs. The main problem is, inability to communicate to it. Often new users complain that their modules are not working, they are unable to send commands to it, getting gibberish output at the serial monitor for all baud rates. Well, baud rate, so what is it? this is just the data transfer rate at which two digital devices communicate. ESP8266 has a big flaw at its baud rate selection. Out of the box, it seldom responses to a baud rate chosen from available ranges. As result, it becomes unusable and frustration grasps us.
What Is The Reason?
Wrong Firmware. Yes, that’s the culprit. By default, it comes with AT firmware preloaded and some module comes with no firmware at all. But it is hard for a user to get the reason why their modules are not working. Due to some serious bugs in the firmware, the baud rate of ESP8266 never matches the baud rate we set to serial monitor (e.g. RealTerm, HyperTerm, Arduino IDE’s serial monitor etc). So all we get is some gibberish data or NO data at all.
Procedure To Solve It
So, now it’s pretty clear to us that we have to upload a fresh and working firmware. So let’s do it step by step:
1) THINGS YOU NEED:
- One ESP 8266 Module that you want to flash. [US(purchase)] [INDIA(purchase)]
- Some jumper wires.
- A breadboard.
- One USB to TTL converter, a.k.a UART converter. [US (purchase)] [INDIA(purchase)]
- Firmware flashing software and latest AT Firmware (zipped altogether)
2) DOWNLOAD :
Download the .zip file and extract it. There are 3 files there. One Flasher and two Firmware.
v0.9.5.2_ AT_Firmware.bin (firmware), v0.9.2.2_ AT_Firmware.bin (firmware), esp8266_flasher.exe (flasher).
⇒Click here⇐ to download ⇓.
3) BUILD THE CIRCUIT :
OK, nothing much. Just a simple circuit to put your ESP8266 in flash mode. Circuit varies depending upon your ESP variant. Two most popular modules are ESP-01 and ESP-12(E/F).
ESP8266 chips are not 5V tolerant, hence NO module based on ESP8266 is 5V tolerant. You have to deal with 3.3V logic level. To convert 5V logic to 3.3V logic you may use logic level shifter. Providing 5V to any pin may cause instant damage or reduction of life span in long run.
ESP8266 has two modes. Flash mode(for uploading new firmware or program) and Boot mode(normal startup and execution of existing firmware or program). It’s quite confusing that which wiring i.e. pin modes are correct for a specific Mode (flash or boot). Hence I consulted data-sheet from AI-Thinker’s website (official developer of ESP8266 based modules). But damn! that was in Chinese. Anyway, Google translator came handy and I could figure out how to set the pins to set flash mode or/and boot mode. The datasheet (in Chinese) is here.
To put the module in flash/programming mode,
ESP-01: CONNECT GPIO0 TO GROUND (SET IT LOW OR 0)
ESP-12(E/F): CONNECT GPIO0 TO GROUND (SET IT LOW OR 0)
CONNECT GPIO15 TO GROUND (SET IT LOW OR 0)
CONNECT GPIO2 TO Vcc (SET IT HIGH OR 1)
Please note: The “Flash Mode” is “UART download mode” on the table, and “Boot Mode” is “Flash Boot Mode” on the table. “UART download mode” refers downloading new firmware in module’s flash memory. Which is also known as flashing. And “Flash Boot Mode” refers booting normally from the firmware of flash memory.
As per my experience, pulling GPIO2 HIGH is not necessary, at least in my case I simply ignored it and things went alright. But it is recommended to follow instructions of data-sheet. Here I attached two breadboard design but GPIO2 left floating (neither high nor low). Don’t follow it blindly. Rather apply the pin settings I stated above.
4) UPLOADING PROCESS :
Well, when all circuitry is done, you can upload any firmware/program over UART. Here we’ll only explain uploading AT firmware. It’s the default one in the ESP8266.
- Okay, now go to the folder where you have extracted the downloaded .zip file.
- There are two Firmware and one flashing tool. You may choose any firmware. Both works fine. Though the latest version is recommended.
- Be sure the USB to TTL converter (UART converter) is connected to your PC. Now open the flashing tool.
- Edit the COM port number correctly. To check where your UART converter is connected, go to device manager > COM and LPT ports. There you can see the COM port number of the converter.
- edit nothing else. Not required. Now choose the firmware by clicking on “BIN” button. Select your desired firmware.
- Now again check if all circuitry is all right. Okay, now put ESP8266 in flash mode or “UART download mode” by either holding the flash button on breadboard (if you followed the given breadboard diagram) or simply set the specific pins to required mode as per instructions are given earlier.
- Now press and hold Reset button or simply connect reset pin to ground and click “DOWNLOAD” option in flash tool, and then release reset switch or detach it from ground. But DON’T release the flash/boot mode selector pins from their correct modes until flashing is complete.
- Now the flashing will start if things are all right. And you can see percentage completed on-screen.
- It may give errors like “Can’t connect” or “Invalid packet head” etc. It happens mainly for two reasons. Deficient power supply to ESP module, or error in circuitry. Use a dedicated 3.3V power supply for ESP. And if still getting the error, try holding the reset button for a while, when “DOWNLOAD” button is clicked on flash tool. It may solve the problem.
5) COMMUNICATE WITH REBORN ESP8266 MODULE :
So, now it’s time to communicate with your module. Open the serial monitor of Arduino or any other application like hyperterm, coolterm, Realterm, Putty etc.
Set the correct COM port again. Select the baud rate to 9600/115200/19200 (one of these 3 will work). Select “Both LN & CR” in Serial monitor. For other applications, you need to add “\r\n” without quote after every AT command.
Now type AT. The response should be OK. If you get no response or gibberish response, try changing baud rate. Once you get “OK”, Bingo!! You made it!! Now there are other AT commands to perform a lot more tasks. Check it for a list of AT commands and their usage.
You can also consult ESP8266 datasheet from bbs.espressif.com to get AT command lists.
END OF STORY:
So, that’s how we flash firmware in ESP8266. If it helped you, let me know in comments. Also if you have any query regarding this, don’t hesitate to ask. You may also like my previous post “Program AVR Using Arduino [Simplest Way!!]“. Have a good day 🙂