Learn how to resolve the Fatal Error that Occurred: “Failed to connect to ESP32: Timed out waiting for packet header” error while trying to upload new code to your ESP32 board once and for all.
Why are you getting this error?
When uploading new code, some ESP32 development boards may not automatically enter flashing or uploading mode.
This means that the Arduino IDE fails to connect to your board when you try to upload a new sketch to your ESP32, and you see the following error message:
![[Resolve] Failed to connect to ESP32: Timed out while waiting for packet header 2 timed out waiting for packet header](https://lededitpro.com/wp-content/uploads/2023/06/timed-out-waiting-for-packet-header.webp)
Holding the BOOT/FLASH button
One way to fix this is to simultaneously upload a new sketch and hold down the “BOOT/FLASH” button on your ESP32 board. However, worrying about this each time you upload new code may be tiresome, particularly when you're testing and debugging your code. There is a way to resolve this issue once and for all: no longer do you need to hold down the “BOOT/FLASH” button.
How to fix the Error?
Connect a 10 uF electrolytic capacitor between the EN
pin and GND
to put your ESP32 board into flashing or uploading mode automatically.
To make sure it works for your ESP32 development board, you may want to test this setup on a breadboard first.
![[Resolve] Failed to connect to ESP32: Timed out while waiting for packet header 3 esp32 capacitor flashing mode automatic](https://lededitpro.com/wp-content/uploads/2023/06/esp32-capacitor-flashing-mode-automatic.webp)
Note: Electrolytic capacitors have polarity. The white/grey stripe indicates the negative lead.
If it works, solder the 10 uF electrolytic capacitor on the circuit board. Because the EN
and GND
pins of the ESP32 chip are so far apart, you may simply connect the capacitor between the EN
and GND
, as shown in the schematic diagram below:
![[Resolve] Failed to connect to ESP32: Timed out while waiting for packet header 4 esp32 capacitor flashing mode automatic 2](https://lededitpro.com/wp-content/uploads/2023/06/esp32-capacitor-flashing-mode-automatic-2.webp)
The following image shows how my ESP32 looks after soldering the capacitor. It doesn't occupy much space, and thankfully, you won't have any more trouble connecting to the ESP32 when you upload new code.
![[Resolve] Failed to connect to ESP32: Timed out while waiting for packet header 5 fix timed out waiting for packet header capacitor f](https://lededitpro.com/wp-content/uploads/2023/06/fix-timed-out-waiting-for-packet-header-capacitor_f.webp)
Check the connections with a multimeter in continuity mode to make sure you haven't inadvertently soldered something to the next pin before trying to upload a new code.
![[Resolve] Failed to connect to ESP32: Timed out while waiting for packet header 6 check connections capacitor fix timed out packet header](https://lededitpro.com/wp-content/uploads/2023/06/check-connections-capacitor-fix-timed-out-packet-header.webp)
When uploading new code, you won't need to press the BOOT button if everything is correctly soldered. You will also not get the Fatal Error: “Failed to connect to ESP32: Timed out waiting for packet header” message.
![[Resolve] Failed to connect to ESP32: Timed out while waiting for packet header 7 done uploading esp32](https://lededitpro.com/wp-content/uploads/2023/06/done-uploading-esp32.webp)
Conclusion
We hope you’ve found this trick useful and that it solved your problem. Thanks to Ahmed Samir for the suggestion.
If you like ESP32, you may also like:
- Install ESP32 Board in Arduino IDE in less than 1 minute
- Get MAC Address of ESP32/ESP8266 and Change It (Arduino IDE)
- Getting Started with MicroPython on ESP32 and ESP8266
- How to Install ESP32 Boards in Arduino IDE 2.0
We hope you find this tutorial useful. Thanks for reading.