[SOLVED] Failed to connect to ESP32: Timed out waiting for packet header

Learn how to fix the Fatal Error Occurred: “Failed to connect to ESP32: Timed out waiting for packet header” error when trying to upload new code to your ESP32 board once for all.

[SOLVED] Failed to connect to ESP32: Timed out waiting for packet header

Why are you getting this error?

Some ESP32 development boards (read Best ESP32 boards) don’t go into flashing/uploading mode automatically when uploading a new code.

This means that when you try to upload a new sketch to your ESP32, the Arduino IDE fails to connect to your board, and you get the following error message:

Holding the BOOT/FLASH button

One of the ways to solve this is holding-down the “BOOT/FLASH” button in your ESP32 board while uploading a new sketch at the same time. But having to worry about this every time you want to upload new code can be tedious, specially when you’re testing and debugging your code. There is a way to fix this once for all – no need to hold down the “BOOT/FLASH” button anymore.

How to fix the Error?

To make your ESP32 board go into flashing/uploading mode automatically, you can connect a 10 uF electrolytic capacitor between the EN pin and GND.

You may want to test this setup first on a breadboard to make sure it works for your ESP32 development board.

Note: electrolytic capacitors have polarity. The white/grey stripe indicates the negative lead.

If it works, then you can solder the 10 uF electrolytic capacitor to the board. Since the EN and GND pins are far apart from each other, you can simply connect the capacitor between the EN and the GND of the ESP32 chip as shown in the schematic diagram below:

Recommended: ESP32 Pinout Reference: Which GPIO pins should you use?

The following figure shows how my ESP32 looks like after soldering the capacitor. It doesn’t occupy much space, and fortunately you won’t get more trouble connecting to the ESP32 when uploading new code.

Before trying to upload a new code, you should check the connections with a multimeter in continuity mode – check that you haven’t inadvertently solder anything to the next pin.

fix timed out waiting for packet header with capacitor testing

If everything is soldered properly, you won’t need to press the BOOT button when uploading new code. You also won’t get the Fatal Error Occurred: “Failed to connect to ESP32: Timed out waiting for packet header”.

Wrapping Up

We hope you’ve found this trick useful and it solved your problem. Thanks to Ben Hall for the suggestion.


Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »

Learn how to program and build projects with the ESP32 and ESP8266 using MicroPython firmware DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our weekly newsletter!

40 thoughts on “[SOLVED] Failed to connect to ESP32: Timed out waiting for packet header”

  1. I wonder what would occur if I used a 100uf Capacitor instead of the 10uf one as recommended in the post above? Would it hurt the ESP board?

  2. I have an ESP32 with this problem. I have added the capacitor as described in the article. Now the upload start automatically, but the software does not start. I I press the reset I obtain the following message
    rst:0x1 (POWERON_RESET),boot:0x0 (DOWNLOAD_BOOT(UART0/UART1/SDIO_FEI_FEO_V2))
    waiting for download

    the only way to start the program is to switch off and the switch on again the esp32.
    Any Idea?

  3. I have resolved the problem in my previous post by adding a resistor of one 1kohm between the pin EN and the 3v.
    Now the upload runs automatically and the reset maintain its function.

  4. I would like to add that in some cases, with some esp32 I must add a 47 uF capacitor + resistence of 1Kohm for resolving the problem.

  5. Muito Obrigado pelo excelente post, me ajudou e muito e tenho certeza que vai ajudar muitas outras pessoas. “Compartilhar conhecimento só enriqueci o nosso saber”

  6. Hello, thanks for the info.

    I have the same problem, but the device I’m using is ESP-32 CAM, so the pinouts are different from the original ESP-32. Do you have a solution for this? Thanks again in advance.

  7. I have a Lolin D32 board which was giving this error. It has only one button(Reset). I put the capacitor like suggested above but the error was persistent. As a last ditch effort I used a jumper on GPIO0 to GND during compile and upload(I use Arduino IDE). Now the code is uploaded without a problem. I remove this jumper and the board functions as programmed.

    • Hi.
      Thank you for sharing your solution. It will certainly be useful for other readers that use the Lolin D32 board.
      Regards,
      SAra

  8. Thank you for the article. I have exactly the same board as in your pictures. It was enough to use 2.5 uF and no resistor was needed. However I didn’t like the metal can of the capacitor so close to the antenna. An alternative location is negative to the pin of the AMS1117 that is closest to the USB connector, positive to the middle pin of the transistor closest to D2. And of course if project allows, the capacitor can be applied on the underlying project PCB.

  9. Many thanks, it worked!
    Is this for esp8266 or is it just in case of this error in esp32? Well, I noticed that the sketch loads faster.

  10. Hi,
    I’m getting error “Connecting…….._____….._____….._____….._____….._____….._____…..____An error occurred while uploading the sketch”
    its a Webcam ESP32s.
    I’ve been able to connect to “factory setting AP” and test the camera and wifi ok but doesn’t matter what I try I can get it to upload a new sketch. I have two and one works as expected but the other is a no go.
    Would try to add a 10 uF electrolytic capacitor but the pinout on the Webcam ESP32 is different from the image shown above. Do you have the EN pin placement for Webcam ESP 32?

    Any ideas?

      • Hi Sarah thanks for the reply but I had followed all the troubleshooting elements of the guidelines. I have one esp32 webcam that works so i know my setup is correct.
        My real question was: were is EN pin on the esp32 webcam so I could try the capacitor fix. The esp32 in that example was not a webcam version.

  11. Thanks for posting the solution. I had been using the ESP32 on my Windows 10 desktop with no issues uploading. Wanted to move over to my MAC Laptop. First issue was the lack of USB driver on the MAC. Found info on that, but then it kept failing to connect – timing out. I assumed it was still an issue with the USB Port / Driver, till I saw your comment about holding down the Boot button throughout the upload process. Worked perfectly. Thank you.

  12. Hey Sara Santos!
    I pulled up EN to 3v3 with a 10K ohm resistor and a switch to ground it while uploading.
    I Pulled up IO0 to 3.3V using a 10K ohm resistor and A button switch to pull it down to GND while uploading the code.
    The Tx and Rx are also correctly connected to the FTDI programmer(PS. I’m using the same 3.3V- 5V programmer that I use for Esp8266).
    And still I am receiving this error. I have even tried attaching capacitor between the EN pin and the gnd. Still the code is just not flashing.
    It flashed once and I was able to blink a LED, but after that the device is just not flashing the code.!
    Please suggest a solution 🙂

    “”Connecting…….._____….._____….._____….._____….._____….._____…..____An error occurred while uploading the sketch
    _

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header””

  13. I am trying to connect with Custom ESP32 Board, Here I have used USB to UART converter for programming the ESP32. While programing first time it showed the timed out and waiting for packet header After I used 10uF capacitor across EN and Ground pin first time it’s programmed fine, Next time I tried to program its showes the same error.

    I don’t know how to resolve this.

    • Hi Rick.
      Yes, It think it should work.
      I recommend testing the circuit on a breadboard first to make sure it works, and only then solder the capacitor to your board.
      Regards,
      Sara

      • Hi, Sara.

        Thanks for really quick reply!

        I just tried it. The cap slows the connection operation a few seconds, but once it connects it still gives the timeout error. My esp32 has a lot of serial activity going on – GPS, OLED, LoRa, SD Card – which I think challenges the USB flashing.

        On another note, I’m using Windows 10, which has the irritating habit of frequently causing the serial port to lose my esptool script, forcing me to restart the PC. Ever see that issue?

        Thanks!

        • Hi Rick.
          The timeout error means that the ESP is not in flashing mode (to receive the code).
          Usually, the solution is to press the BOOT button when you start seeing the dots appearing on the serial monitor.
          In the board you’re using, I think it is the PRG button you need to press when you see the dots.
          Pressing the PRG button solves the problem?
          Unfortunately, I don’t have a board like that to experiment.

          I usually don’t have problems with the serial port. But sometimes if your ESP32 needs a lot of current to operate (like you have), your usb port might not provide enough power and some “strange” things can happen like disconnecting from your computer and having to restart.

          Regards,
          Sara

      • Hi, Sara.
        I found the flashing worked when I temporarily removed one of the peripheral device that was drawing power through the ESP32_LoRa chip. After flashing I reconnected it, and everything is working great. Thanks, again!

  14. I have resolved the problem.
    In my case, there is a jumper (on the FTDI programmer) which sets the output to be 3.3V or 5V.
    It should go along with the power supply pin you use on the ESP32 (3.3V or 5V pin).
    Hope this helps.

  15. I found my problem was with the USB port on my laptop. If I use a USB 3.0 cable (USB-A -> USB 3) in the USB 2.0 port, I get the exact error messages above. When I moved the cable to the USB 3.0 port it worked just fine. I didn’t realize my laptop had a single 2.0 port which is the one I naturally use due to it’s location. As I understand, it should have worked with the USB 2.0 port, but it does not on my laptop either due to the cable or the port. Hope this helps someone.

Leave a Comment

Download our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.