[To understand error messages shown by ESP8266 in the serial monitor, read the latest article: ESP8266 ERROR MESSAGES AND EXCEPTIONS EXPLAINED]

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 documentation 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:

  1. One ESP 8266 Module that you want to flash. [US(purchase)] [INDIA(purchase)]
  2. Some jumper wires.
  3. A breadboard.
  4. One USB to TTL converter, a.k.a UART converter. [US (purchase)] [INDIA(purchase)]
  5. 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).

CAUTION::: 

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 lifespan 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 the 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)

FlashMode and BootMode ESP12E

FlashMode and BootMode ESP12E

untitled

FlashMode and BootMode ESP12E

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.

ESP-01 FLASH MODE

ESP-01 FLASH MODE

esp8266_12e

ESP-12 FLASH MODE

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.

  1. Okay, now go to the folder where you have extracted the downloaded .zip file.
  2. There are two Firmware and one flashing tool. You may choose any firmware. Both work fine. Though the latest version is recommended.
  3. Be sure the USB to TTL converter (UART converter) is connected to your PC. Now open the flashing tool.
  4. 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.
  5. edit nothing else. Not required. Now choose the firmware by clicking on “BIN” button. Select your desired firmware.
  6. 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.
  7. 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 the ground. But DON’T release the flash/boot mode selector pins from their correct modes until flashing is complete.
  8. Now the flashing will start if things are all right. And you can see percentage completed on-screen.
  9. 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 quotes 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.

[To understand error messages shown by ESP8266 in the serial monitor, read the latest article: ESP8266 ERROR MESSAGES AND EXCEPTIONS EXPLAINED]

You may also like my previous post “Program AVR Using Arduino [Simplest Way!!]“. Have a good day 🙂

29 thoughts on “Flash AT Firmware To ESP8266 WiFi Module [EASIEST WAY!]

  1. You are awesome Sir!!!

    Some notes: When I downloaded the compressed file, it would not save correctly (corrupted) but if opened with WinRar before saving, I was able to extract the flasher & 2 x firmwares. (I hope I don’t have a new virus)

    One of my boards (ESP8266MOD LUA) on a PCB with micro USB and two buttons for Flash and RST had a bad soldering and the flash button did not work. If it’s not working for someone, get a multimeter and find the GND, Vcc, GPIO 0, 2, 15 pins on the original WiFi module and make sure they are LOW, LOW, HIGH (GPIO 15,GPIO 0, GPIO 2) and the board has 3.3V because my Flash pin GPIO 0 was floating at 2V regardless if the flash button was pressed. Attaching a wire to ground quickly solved the problem after 30 minutes of frustration.

    Maybe a future write-up could include an advanced tutorial how to use the custom AiThinker or Espresso flash utilities to specify the crystal freq, SPI mode, Flash Size, and combining bins.

    Like

  2. The process did start but at the end it showed “Failed to leave flash mode”. What shall i do? I did try to open the serial monitor but it didnt accept any commands

    Like

    • Yes, it shows that message every time even after a successful flashing. Don’t worry. If you’ve followed all the instructions carefully, it’s flashed correctly. Close the flashing tool and restart the esp. Open any serial monitor and try sending AT commands. Don’t forget to close the flash tool and all other softwares that are using the COM port before opening the serial monitor.

      Like

      • I am using putty software. and ESP-01. Wanted to ask, after the flashing is done what should be the connections of Reset pin and GPIO0 pin?

        Like

        • I did follow all the instructions. After flashing when i tried to send commands via putty, i still wasnt able able to type after trying different baud rates. Then i connected gpio0 to vcc and i was able to type successfully on 115200 baud rate. But my esp isnt responding. After typing ‘AT’ and pressing ENTER, Esp isnt responding. Please do help sir..

          Like

        • The reset pin is best to be pulled up to Vcc using a 10k resistor between RST and Vcc, also, a capacitor of 100nF between RST and GND helps to remove ripples and thus prohibits unintentional resets.)

          GPIO0 must be high after flashing is done. GPIO15 must be low all the time regardless it’s normal operation mode or flashing mode.

          Like

          • Okay sir thank you so much!!
            I am using ESP-01 so dont have an external accessible pin for GPIO15. I have kept GPIO0 floating.
            The commands didnt work in Putty but is working in Flash Magic. Thank u.
            Have couple more questions related to my project on ESP, Can u please help me out?

            Like

              • Thank you!! Actually i am making a project on Auto Car parking Management. Like on the parking slots there will be Ultrasonic sensors which would give the status of the slot via a LED (if ON: Slot Vacant; if OFF: Slot Occupied). This data will be sent to ATmega32 microcontroller which will send to my ESP and my esp will then send to the webpage which i have build. I am having trouble in what code should i put in ESP to communicate with my Atmega and webpage.
                (Using Atmega as i need more GPIOs)
                Also the baud rate i used while testing my ESP now was 115200 but my Atmega is running on 9600. So what shall i do?

                Like

                • I can help you with ideas about this project, but you must handle the coding part yourself.
                  1. Either increase ATmega’s UART baudrate (simple) to 115200 or set esp’s baudrate to 9600 using AT command. Just google it and you can find how to do it.
                  2. I hope your webpage is hosted by some free/payed server. There should be option to set up a SQL database. Create a table there and update values as per the decision of atmega.
                  3. In webpage, update values as per the sql table. Example: Parking slot “m” is “status”.
                  Here, “m” is no. of the slot and “status” is either free or occupied. In table, m and status are two columns. “Status” holds 0 or 1 (occupied or free).
                  4. Atmega decides slot no and status of it, generates a http GET request with those data, update the sql table by connecting to the internet via esp.

                  Like

                  • Okay Got it. Thank you.. I have prepared the database and the tables.
                    And how can i upload the program on esp? i have usb to ttl converter and usbasp and am using Arduino IDE

                    Like

                  • You can’t “upload” program to esp as long as you are using AT firmware. AT firmware needs commands from the host microcontroller to perform each task.
                    Google “how to send get request using esp8266 at commands”.
                    Note down the commands and save them as strings in your C code of atmega.
                    When needed, send those command strings over uart to the esp.
                    Esp responses with “OK” if succeeded.

                    Like

          • You say GPIO15 must be low all the time regardless of flash mode or normal mode, but your breadboard setup has it it the circuit with the “program” button, so it would only be low when that button is pressed – is this an error in the setup?

            Like

  3. I tried to use the flashing tool and did exactly what its said, the flasher begins to erase the last firmware and write the new one and on 1% the flasher crashed and close.

    Like

    • Have you tried resetting the ESP right before starting to flash.? It helps most of the time. Also check for connection issues. 95% problems in ESP occurs due to connection problems. Try soldering wires directly to it instead of using breadboard.

      Like

Leave a comment