[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.



Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our newsletter!

140 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?

    Reply
      • For me it worked only with 100uF capacitor. I tried with many capacitors ranging from 10-470 uF. There wasn’t en pin in my ESP32s board so i soldered the third one on the chip and the first one.

        Reply
    • Before doing any soldering make sure that you are using the correct GND pin. On my ESP32 Wroom Devkit V2 , the pin next to the 5V pin is incorrectly labelled as GND whereas it should have been CMD, and using it by mistake gave this error message

      Reply
      • Thank you!! I was using the GND pin next to the 5V pin and it did not work. Because of you tip, I tried a different GND pin and Boom! It worked!

        Reply
  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?

    Reply
  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.

    Reply
  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.

    Reply
  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”

    Reply
  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.

    Reply
  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.

    Reply
  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.

    Reply
  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.

    Reply
  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?

    Reply
      • 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.

        Reply
  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.

    Reply
  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””

    Reply
  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.

    Reply
    • 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

      Reply
      • 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!

        Reply
        • 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

          Reply
      • 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!

        Reply
  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.

    Reply
  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.

    Reply
  16. I just bought an esp32 , and I am a beginner .
    when I upload the blink , this failed message comes, please help me

    A fatal error occurred: failed to connect to ESP32: timee out waiting for packet header

    Reply
    • Hi.
      I recommend following the suggestion in this article.
      Also, you may need to reduce the upload rate in your Arduino IDE in Tools > Upoload Speed.
      I hope this helps.
      Regards,
      Sara

      Reply
  17. For me with the 10uF the ESP32 did not start the program after the download.
    With a 1uF the ESP32 starts the program automatically after the download.

    Checking the board, it looks like the CP2102 (USB to Serial) is not an original one, as it has no label on it.

    On another ESP32 (Which is working normaly) the CP2102 has a label printed on top.

    Reply
    • Hi:
      I am using a LOLIN D1 Mini. After several successful uploadings I suddenly got this error; however this board does not have an EN Pin and it only has a RST .

      Do you have any suggestion to correct the problem?
      Thanks in advance, Gerardo

      Reply
  18. I note that Expressif recommends to load the En line with a 100nF cap if you have programming “connecting” problems
    https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection
    I had the same problem on a NodeMCU-32s.

    The nice part is that the En line is right next to the 3.3V line and at AC all power pins are the same so connecting a cap to the 3.3V line or Gnd will provide the same filtering (assuming this cap provides noise filtering or slew limiting). I used a 0805 100nF MLCC which just fit between the 0.1″ spaced pins 1 and 2 (En and 3.3V) on the top of the NodeMCU. Now it programmes perfectly.

    A large cap caused me problems with reset after programming but this smaller cap works fine.

    Reply
  19. Connecting…….._____….._____….._____….._____….._____….._____….._____

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
    Soldered the capacitor to EN and GND.
    Tried this thing as well: https://randomnerdtutorials.com/esp32-cam-troubleshooting-guide/
    not working.
    I’m using ESP32 CAM AI-Thinker
    5V, tested ever single connections with volt meter. Everything works fine.
    Tried all possible ways.
    Watched like 3 hours of youtube.
    Doesn’t fix the problem. Any suggestions? I would really appretiate that.

    Reply
  20. First of all – thank you for sharing this solution.
    I recently bought two ESP32-boards from OLIMEX and had problems uploading. It was very strange, since it worked the first time, but never again ??? After googling around for quite some time, I found your solution.
    DanKoloff from Olimex gave me some tips too, but it was a capacitor at EN that helped. From curiosity I tested different caps, diffent resistors and the two Olimex-boards plus a AZ-delivery ESP32-Dev which I had bought the week before.
    You can find the table of my tests at
    https://github.com/OLIMEX/ESP32-POE/issues/11
    Regards, Karl

    Reply
    • Hi Karl.
      I’m glad you solved your problem and thanks for sharing that table. It may be useful for many of our readers.
      Regards,
      Sara

      Reply
  21. Hi Sara,
    I was not really satisfied with this solution. Also I noticed, that the RST-button did not always work. Shortly I heard of power-monitoring ICs for the gereation of a clean reset.
    So I ordered a few TPS3809K33 (SMD) and a few MCP102-300 (for breadboard tests). The ESP32-PoE from Olimex has a RST-button from EN to GND. Since the MCP102 has an open collector output, you can connect it directly to ESP_EN (pin4 on EXTERN1). But if you use the TPS3809 (it has a push-pull output), I suggest a resistor in between the output of the IC and EN. I use 4k7 since it only draws current while RST is pressed.
    For me this is the best solution, since it is not dependent on the time constant and now even the RST-button works flawlessly. Now I can upload code and use the RST-button.
    Regards, Karl

    Reply
  22. Hey guys,

    I admit I’ve never encountered this problem before. The board I’ve been using so far seems to be free of this malfunction… But since I unpacked 3 other identical boards (that I bought at the same place), I’m now facing the problem.

    For those who are interested, here are the boards I use:

    https://www.aliexpress.com/item/33057018346.html

    I guess I can compile my projects with the DoIt ESP32 DevKit v1 model. Anyway, that’s what I’ve been doing since the beginning, and it works. If you think it’s not the most appropriate model for compiling, don’t hesitate to let me know!

    I’ve tried by all means to solve the problem with software, but without success. And I stumbled upon a post on the forum with the reference to this article… A providential chance!

    The solution is simple and efficient. Nevertheless, I have a small question: why 10 µF? How did you choose this value? In an empirical way, or is there a logical explanation for that?

    In any case, a big thank you… I can finally stop pulling my hair out on this thing that was driving me crazy.

    All the best,
    Steph

    Reply
      • Indeed, as far as I’m concerned, my boards are very widespread, and they are very similar to Rui and Sara’s favorite boards… so it’s easier to find a solution.

        On the other hand, thanks for the info about the MCP102, it’s good to know!

        Thanks Karl!

        Reply
  23. Very handy little trick. I was suffering with this error for a while, but thanks to you i can use my boards just fine 🙂

    Reply
  24. I own a TTGO LoRa Esp32 v2 and I am struggling to upload the new code (.bin). I treat it with really care, I was uploading and testing some codes and suddenly, it stop allowing me to upload new programs.

    I have tried many different things and combinations of all of them:

    usb ports
    usb wires
    2 linux
    windows
    arduino ide
    platformio
    pressing the RST button (it doesn’t have boot)
    changing the baud rate (upload speed)
    changing the flash freq
    changing the board type (TTGO Lora32 v1, v2, Heltec…)

    And I get always this:

    python /home/user/.arduino15/packages/esp32/tools/esptool_py/2.6.1/esptool.py –chip esp32 –port /dev/ttyUSB0 –baud 115200 –before default_reset –after hard_reset write_flash -z –flash_mode dio –flash_freq 80m –flash_size detect 0xe000 /home/user/.arduino15/packages/esp32/hardware/esp32/1.0.4/tools/partitions/boot_app0.bin 0x1000 /home/user/.arduino15/packages/esp32/hardware/esp32/1.0.4/tools/sdk/bin/bootloader_dio_80m.bin 0x10000 /tmp/arduino_build_119083/WiFiScan.ino.bin 0x8000 /tmp/arduino_build_119083/WiFiScan.ino.partitions.bin
    esptool.py v2.6
    Serial port /dev/ttyUSB0
    Connecting…….._____….._____….._____….._____….._____….._____…..____An error occurred while uploading the sketch
    Failed to connect to ESP32: Timed out waiting for packet header

    The weird thing is that I achieved loading sample programs like OLEDHelloWorld and it is working (showing that program in the OLED), but I cannot boot/upload any other program since that happened (yesterday).

    Any idea?

    Reply
  25. I faced the same problem, after adding 10uF capacitor it still could not work.
    Finally, I found that problem caused by myself, I connected TX0 RX0 pin to RS485 transceiever. After moved the transceiver to UART2 the problem gone.

    Reply
  26. I am using a DOIT ESP32 WROOM-32D board and facing same issue. Adding a 10uF capacitor solves the sketch loading problem but the board needs to be manually reset every time.

    Reply
  27. Hi Sara
    On the RPi /Node red side everything seems fine, with mqtt nodes showing connected.

    Then, to download the code, I tried a several ESPs, using a capacitor etc and nothing worked. Finally I found that I had an ESP 12F, tried this, and amazingly it uploaded. However, when I went to do the test as you suggested (before building the DHT circuit) the message I get I failed to get an MQTT connection.
    My router says that I have an IP address for the ESP12F,
    If you have any suggestions why I can’t connected to the MQTT on RPI – that would be much appreciated. I put the correct address of my RPi in the code and included the 1883 port in the address. So frustrating when you get so close.

    Reply
  28. Hello,

    I have the AI Thinker module of ESP32-CAM. My problem is similar but at a later stage. When I upload the sketch, it can connect and start writing, however at the end it fails with the same error as above. Here is the output:
    esptool.py v2.6
    Serial port /dev/ttyUSB0
    Connecting…….._
    Chip is ESP32D0WDQ5 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: f0:08:d1:76:94:38
    Uploading stub…
    Running stub…
    Stub running…
    Changing baud rate to 460800
    Changed.
    Configuring flash size…
    Warning: Could not auto-detect Flash size (FlashID=0x0, SizeID=0x0), defaulting to 4MB
    Compressed 8192 bytes to 47…
    Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 4217.0 kbit/s)…

    A fatal error occurred: Timed out waiting for packet header
    A fatal error occurred: Timed out waiting for packet header

    Reply
  29. Hi, I put 10 uF electr. (smd) cap.
    It was not working.
    Then i put an 1k resistor (THT) between rst and 3v3
    It was not working.
    Then take the resistor and now it is working 😀 😀 (cap. is still soldered)
    I really do not understand yet, but maybe this can help sy else too.

    Reply
  30. Hi all,
    For those who find ESP WROOM 32 not flashing, no need for capacitor or to press BOOT key.. just change the board to “ESP32 Dev Module”. It works like a charm

    Reply
  31. Currently I’m testing a nodeMCU ESP32 with 38 pins and on 1µF capacitor (metal-film) works fine to solve the flash-problem. I can imagine that for this particular problem a metal-film capatictor is more suitable than an electrolytic capacitor. Anyway it’s much more fun that pressing the EN-button every time. Thank you for this hint and of course for all your helpful tutorials.

    Reply
  32. After lots of experimentation with different RC timings on EN, different bulk capacitance and PS filtering, I eventually discovered that this is a regression in esptoolpy 2.6 and 2.8. Using version 2.1, my ESP32 will flash perfectly every time at up to 430kbps. I’ve reported this to esptool (https://github.com/espressif/esptool/issues/570) and hopefully they’ll be able to figure it out. For folks using Platform IO, you can add the following to your platformio.ini to cause it to use esptoolpy 2.1:

    platform_packages = [email protected].0

    Reply
  33. This is my solution for the board Lolin32 Lite

    Arduino IDE
    Board : “ESP32 Dev Module”
    Upload Speed: “115200”
    Cpu frequency: “240Mhz”
    Flash Frequency:”80Mhz”

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

    Then Do this: Remove any connector from the board or at least from 3.3 pin

    After:
    “Hash of data verified.
    Leaving…
    Hard resetting via RTS pin…”

    It’s working!

    Ciao 🙂

    Reply
  34. Hello All,

    I am unable to upload the blink example to ESP32. i am using ESP32 devkit v1. I tried to hold boot button and momentarily pressed EN button for the upload. It always fail with following error message. I tried with different capacitor value but still failing. In monitor mode when i pressed boot button and EN. It shows waiting for download in terminal. I closed the terminal and then tried to upload again but so far i have not able to upload the code once. Any help would be appreciated. I tried with different USB cable but still not working. i tried with Arduino IDE also using IDF framework (terminal build) but nothing works. i wanted to try any other suggestion before i would like to buy new ESP32 dev kit again.

    Flash logs from Terminal
    Executing action: flash
    Running ninja in directory c:\users\mohan\esp\esp-idf\examples\get-started\blink\build
    Executing “ninja flash”…
    [1/4] Performing build step for ‘bootloader’
    ninja: no work to do.
    [1/2] cmd.exe /C “cd /D C:\Users\Mohan\esp\esp-idf\components\esptool_py…” -P C:/Users/Mohan/esp/esp-idf/components/esptool_py/run_esptool.cmake”
    esptool.py –chip esp32 -p COM4 -b 115200 –before=default_reset –after=hard_reset write_flash –flash_mode dio –flash_freq 40m –flash_size 2MB 0x8000 partition_table/partition-table.bin 0x1000 bootloader/bootloader.bin 0x10000 blink.bin
    esptool.py v3.0
    Serial port COM4
    Connecting…….._____….._____….._____….._____….._____….._____….._____

    A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
    CMake Error at run_cmd.cmake:14 (message):
    esptool.py failed
    Call Stack (most recent call first):
    run_esptool.cmake:21 (include)

    serial monitor (only boot button)
    rst:0x10 (RTCWDT_RTC_RESET),boot:0x1 (DOWNLOAD_BOOT(UART0/UART1/SDIO_FEI_REO_V2))
    waiting for download
    ets Jun 8 2016 00:22:57

    (boot and EN button)
    rst:0x1 (POWERON_RESET),boot:0x1 (DOWNLOAD_BOOT(UART0/UART1/SDIO_FEI_REO_V2))
    waiting for download

    Reply
      • Hi Sara,
        Thanks for the response. I tried just using boot button but it did not work. I also used 10 microfarad capacitor connecting EN & GND as mentioned but that also did not work for me. I changed the micro USB cable as well this time for testing. Also i tested with IDF framework, PlatformIO and Arduino IDE and all 3 upload fails. May be i will buy a new Dev Kit and test it. Thanks again for your response.

        Reply
        • Hi Mohan, there is a regression in the current version of esptool.py that caused this to fail regularly for me; an older version (2.1) works perfectly. One of the maintainers is looking into the problem.

          I am using platformio with vscode; here’s an example of my platformio.ini that works; you can also try slowing down the upload_speed:

          [env:esp32dev]
          platform = espressif32
          board = esp32dev
          framework = arduino

          [env]
          upload_speed = 460800
          upload_port = COM4
          upload_protocol = esptool
          platform_packages = [email protected].0

          Reply
  35. Hi David,
    Thank you for your response. i tried as you have suggested but it seems to fail again. Here is the output

    Verbose mode can be enabled via -v, --verbose option
    CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
    PLATFORM: Espressif 32 (2.1.0) > Espressif ESP32 Dev Module
    HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
    DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
    PACKAGES:
    – framework-arduinoespressif32 3.10004.201016 (1.0.4)
    – tool-esptoolpy 1.20100.0 (2.1.0)
    – tool-mkspiffs 2.230.0 (2.30)
    – tool-openocd-esp32 2.1000.20201202 (10.0)
    – toolchain-xtensa32 2.50200.80 (5.2.0)
    LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 26 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Retrieving maximum program size .pio\build\esp32dev\firmware.elf
    Checking size .pio\build\esp32dev\firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [ ] 4.7% (used 15436 bytes from 327680 bytes)
    Flash: [== ] 16.5% (used 216621 bytes from 1310720 bytes)
    Configuring upload protocol…
    AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
    CURRENT: upload_protocol = esptool
    Looking for upload port…
    Use manually specified: COM4
    Uploading .pio\build\esp32dev\firmware.bin
    esptool.py v2.1
    Connecting….
    Chip is ESP32D0WDQ6 (revision (unknown 0xa))
    C:\Users\Mohan.platformio\packages\[email protected]\esptool.py:2236: DeprecationWarning: inspect.getargspec() is deprecated since Python
    3.0, use inspect.signature() or inspect.getfullargspec()
    Uploading stub…
    operation_args,,,_ = inspect.getargspec(operation_func)
    Running stub…
    Stub running…
    Configuring flash size…
    Warning: Could not auto-detect Flash size (FlashID=0xffff*** [upload] Error 2
    ff, SizeID=0xff), defaulting to 4MB
    Compressed 15872 bytes to 10319…

    A fatal error occurred: Timed out waiting for packet content
    ========================================================== [FAILED] Took 29.13 seconds ==========================================================
    The terminal process “C:\Users\Mohan.platformio\penv\Scripts\pio.exe ‘run’, ‘–target’, ‘upload'” terminated with exit code: 1.

    Reply
    • Is your ESP32 connected to COM4? In my example I used COM4, but you should change that to whatever serial port your ESP32 is connected to. Also, if it doesn’t work at such a high speed, try slower upload speeds such as 115200 or even 57600.

      Reply
  36. Hello David, Sara,

    I tested with new ESP32 development board and it is working fine. I think the first board that i had may have hardware fault. It always printed warning that it cannot detect flash size. anyways thank you for the reponses. Have a great day!!

    Reply
  37. The trick with the 10 uf capacitor works like charm. As it says at the beginning pay attention… “connect a 10 uF electrolytic capacitor between the EN pin and GND”. The pin location of EN and GND are different for every board model, depending on the manufacturer. So make you connect the right pins.

    Reply
    • Hi Radu,
      Which capacitor voltage you connected to your board? There is many voltage, 25v or 50v…I tried to put a comment here but the administrator didn’t approve…Please, help me.
      Thank you

      Reply
  38. Was getting intermittent “Invalid head of packet error 0x2E”
    was driving me nuts, found this solution, and 100% fix. (10uf fitted)
    on ESP32 TTGO

    Thank You 🙂

    Reply
  39. As Ezio Somà says above, on some boards a pull up resistor added to the EN pin is a partial fix. The boards I’ve been using are WeMos ESP32 Mini clones and, after scoping the reset issue, they appear to use FET instead on NPN transistors to drive the EN and GPIO0 pins. They do have a cap (and ~10k pullup) on EN but the EN signal only rises to around 1.6v when GPIO0 is set low – this is close to/on the threshold for high/low level. Because of this, sometimes the ESP32 doesn’t come out of reset until GPIO0 is set high again (i.e it doesn’t see GPIO0 low so just boots normally – not into flash mode). Adding another pullup (4K7 to 1K) to EN helps get the EN signal slightly above the 1.6V threshold – however, it’s fighting against the FET so doesn’t always work but it does improve the reset reliability considerably (the boards I have, when warm, wouldn’t reset to flash mode reliably 9 times out of 10 previously, now its the other way around).

    Also of important note is that, unlike the reference design which uses NPN transistors, the FET actively drives GPIO0 (and EN) high during run time (the pin should float after reset) so you can’t use GPIO0 on these boards for any other function!

    Reply
  40. Bonjour,
    Je n’ai pas de pas de EN broche, j’ai une carte

    Fengyuanhong TTGO T-Beam ESP32 WiFi sans Fil Bluetooth Module ESP 32 GPS NEO-M8N IPEX Lora 32 Titulaire de la Batterie, 868MHz: Amazon.fr: Cuisine & Maison

    Et quand je retiens le bouton “BOOT /FLASH” cela ne fonctionne pas.

    Merci de votre réponse

    Reply
  41. is the capacitor Voltage affect the result ? i use the 16V electrolyctic capacitor 10uF for my ESP32, is it okay ?

    Reply
    • You should use a ceramic capacitor rated for at least 6.3V or a solid tantalum capacitor rated for at least 10V (pay attention to the polarity with a tantalum). Do not use an aluminum electrolytic.

      Capacitor voltage ratings are minimums; you can always use a capacitor with a higher voltage rating. As a rule of thumb, the voltage rating should be 2x what is actually present; you can go a little less with ceramic capacitors. For example, if you are powering an ESP32 with 3.3 volts, you can use a 6.3 volt or higher ceramic capacitor, but with a tantalum or electrolytic capacitor, the voltage rating should be greater than 3.3 x 2 = 6.6V (for example 10V or 16V are popular ratings).

      The purpose of the capacitor is to help make sure the ESP32 voltage stays above its minimum limit when it makes a sudden demand for power. If the traces supplying power to it are too inductive (too long or too thin) or the voltage regulator is slow to react to sudden changes in current, the voltage will drop at the ESP32 and can cause it to reset. Placing a low-ESR capacitor very near the power input to the ESP32 provides a small reservoir of power that can help meet sudden increased power demands (e.g. turning on a WiFi transmitter).

      The reason not to use an aluminum electrolytic capacitor is its relatively high ESR (series resistance). The high ESR will result in a greater voltage drop when the ESP32 suddenly pulls a lot of current. They also tend to have lower ripple-current ratings.

      Good luck!

      Reply
      • Oops, I didn’t read carefully enough (that you are using the 10uF capacitor on EN to stretch the reset pulse).

        Before increasing the EN pulse duration, you might want to try placing a bulk capacitor between 3v3 (pin 2) and ground (pin 1) as described above. I use a 22uF bulk capacitor (anything between 22uF and 100uF is probably a good choice). The reference design of a 10K pull-up and a 1uF on EN then works well.

        My concern is that stretching the reset pulse may masking underlying power problems; it will fix your problem at reset but there may be other problems in operation when the ESP32 makes sudden power demands. If you have an oscilloscope, it would be good to watch the power fluctuations at the input to the ESP32 module.

        Reply
  42. Boa tarde,

    Qual foi a voltagem que utilizaram no capacitador? Vou comprar um e não queria comprar um errado.

    Obrigada.

    Reply
      • Boa tarde,

        Obrigada pela resposta mas comigo não funcionou, nem com os botões EN/Boot funciona…Vocês tem alguma ideia do que posso fazer?

        Obrigada.

        Reply
        • Fazendo o procedimento indicado, a placa deve funcionar.
          A não ser que tenha um modelo muito diferente que necessite de outro tipo de “truque”.
          Se nada funcionar, talvez seja melhor comprar outra placa. Pode ser um placa dessa placa em específico.

          Reply
  43. Would be nice to add a theory of operation, or how/whey this should resolve the problem. Maybe also include the correct process for flashing an ESP32 outside of a development board, the best solution for a development board, and why some boards fail.

    I believe to flash an ESP32, pin IO0 needs to be LOW (0v) when the chip boots. To boot/reset the device, you bring EN/RST pin LOW. In normal operation both of these pins should be pulled HIGH (3.3v). I’m not sure why a capacitor is aiding in this operation, I think it could actually hinder it. Espressif has a PDF on their example development board: https://dl.espressif.com/dl/schematics/ESP32-Core-Board-V2_sch.pdf It’s possible the ESP32 sees the EN pin as low as the capacitor charges by way of the pull up resister. That would explain the strangely high value that is being suggested of 10 or 100 uf.

    I have a USB programmer that has different serial pins on it (Rx, Tx, RTS, CTS, RI, DSR, OCD, DTR, RST). Different pins are brought to 0v at different times. I played around with the programmer and an ESP8366 for some time trying to determine the best pins to connect to the ESP8266 pins. I ended up with RTS connected to reset, and DTR connected to Program/Boot/Flash/GPIO0. Same pins work for ESP32. And same pins as mentioned in the above PDF.

    On a board I was using, I had to eliminate the capacitors I had added for debouncing in order to get the ESP32 to flash. Seem for boards that are not flashing automatically, there’s problems with the EN or IO0 pins that are not allowing the flash reset sequence. Maybe too strong of pull up resistors to 3v3 are being used? You can test the pins resistance to 3v3 rail with a multimeter to find what they are. Should be around 10k-30K.

    Reply
  44. I’m seeing a odd looking part right by the en button, and I’m wondering if it might be the capacitor to enable flashing without pressing the buttons? You can find the part sitting angled on the board in this board sold on Amazon…

    amazon.com/dp/B086MGH7JV/ref=cm_sw_r_cp_apa_glt_fabc_0HKVGH7NWNVNFBTH1095

    Reply
  45. Hi,
    I am working on esp32-wroom-32u. I tried 10uF and 100uF capacitors. It’s not working either. I keep getting the same error. Do you have a suggestion?

    thanks

    Reply
    • Hi Huseyin,
      I had the same problem with my NodeMCU ESP32 (with AI-Thinker ESP32-S module), and I found out that both our ESP32 has the same pinout layout. Have a look at the links (for others, please find your appropriate datasheet to find the correct pin):
      espressif.com/sites/default/files/documentation/esp32-solo-1_datasheet_en.pdf
      espressif.com/sites/default/files/documentation/esp32-wroom-32d_esp32-wroom-32u_datasheet_en.pdf
      I also had tried all solutions in the post and comment section but nothing works for me. Then I tried directly connecting GPIO0 to GND but only to successfully upload the code, but then showing the error “waiting to download” (I can’t remember exactly).
      Finally I tried putting a 1k Ohm resistor between GPIO0 and GND, then ta-da, IT WORKS PERFECTLY!!!
      It may not work for some ESP32 dev boards, but in general, you have to pay attention to these strapping pins: https://github.com/espressif/esptool/wiki/ESP32-Boot-Mode-Selection#boot-mode-message
      Good luck

      Reply
  46. Hi everyone,

    I am new to esp32 and I spent several hours trying to solve this. I finally did, thanks for your help !
    It seems that every esp32 devices are different so here is my configuration and solution.

    I use a NodeMCU Joy-It equipped with the esp32-wroom-32, with esp-idf.
    – Bought here : conrad.fr/p/carte-de-developpement-joy-it-node-mcu-esp32-modul-sbc-nodemcu-esp32-1-pcs-1656367
    – Doc here : joy-it.net/en/products/SBC-NodeMCU-ESP32

    A) In menuconfig (idf.py menuconfig) —> Serial flasher config :

    [ ] Disable download stub
    Flash SPI mode (QIO) —>
    Flash SPI speed (40 MHz) —>
    Flash size (4 MB) —>
    [*] Detect flash size when flashing bootloader
    Before flashing (Reset to bootloader) —>
    After flashing (Reset after flashing) —>
    ‘idf.py monitor’ baud rate (115200 bps) —>

    B) Add a 47µF between pins “EN” and “GND”.

    C) Before executing “idf.py -p /dev/ttyUSB0 flash”, I have to do this sequence :
    1) Press and hold “Boot”
    2) Press and release “En”
    3) Release “Boot”

    After flashing I finally was able to see those logs :

    Wrote 163472 bytes (86248 compressed) at 0x00010000 in 2.2 seconds (effective 598.2 kbit/s)…
    Hash of data verified.
    Compressed 3072 bytes to 103…
    Writing at 0x00008000… (100 %)
    Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.0 seconds (effective 547.3 kbit/s)…
    Hash of data verified.

    Leaving…
    Hard resetting via RTS pin…

    Done

    Before all this I obtained following errors :
    1) A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0xZZ)” with 0xZZ random hex value
    2) A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header

    Hope this will help someone 😉

    Reply
  47. Much simpler solution. Put a jumper between IO0 and GND. They are adjacent on the board. Remove it when done

    Reply
  48. I had this happen with an ESPDUINO-32 & Wemos D1 R32 ESP32 Board while trying to flash from a Dell D410. The Dell is quite old, a 32bit machine.

    What I did was move over to another PC, a newer Zotac compact computer. It was able to flash without problem.

    From a Raspberry Pi it worked if I pressed the reset button as soon as I saw the timeout indication (dots-dash-dots) during flashing. But this fix did not work on the D410.

    Reply
  49. I have tried absolutely everything for the “ESP32-WROOM-32D” but no solution given in this forum has helped me. It does not load the code. Will anyone have a solution that works? Thanks.

    Reply
    • Hi.
      When you say “it does not load the code”, what do you mean?
      What happens exaclty? Can you provide more details?
      Regards,
      Sara

      Reply
  50. Hi,

    Do you have a recommended board that does automatically go into flashing mode so we don’t need to solder anything? I noticed you did have a page of recommended boards, but it doesn’t say whether they automatically go into flashing mode or not. Thanks

    Reply
    • Hi Thomas.
      I don’t think there’s a way to know if that will happen or not.
      Some ESP32 boards that I’ve bought go automatically into flashing mode and others don’t. Even from the same suppliers.
      I usually buy my boards from banggood or ebay (seller alice1101983).
      Regards,
      Sara

      Reply
  51. One thing that worked for me, repeatedly is putting ferrite beads at each end of the cable. Resetting the ESP32 is one thing, but even with the capacitor, using a poor quality USB cable will certainly continue to fail.

    Without soldering a capacitor, try ferrite bead clips on your cable first (you can find plenty of examples on the internet).

    Works a charm.

    Reply
  52. I have a custom board where I am using an ESP32 Wroom module. I am not able to flash code via serial communication. I am using FTDI232 USB to UART for serial communication. I am able to get serial messages in my serial monitor which mean there is no issue in serial wires.

    I have jumped my EN and GPIO0 line from my board to breadboard where I am changing the EN & GPIO 0 wires to GND instead of switch. This is just to be sure that I am pulling down the signals while booting and there is no noise or sudden voltage fluctuation while toggling the signals.

    For extra precaution I have also pulled up or pulled low following strapping pins:
    1) EN: has 10K pull up with 10uF cap between EN & GND
    2) GPIO 0: has 0.1uF between GPIO 0 and GND. I use jumper cables from my board to breadboard where I manually pull it down to GND.
    3) GPIO 2: Floating. I checked signal via scope it stays low.
    4) GPIO 4: 10K pull down resistor and 0.1uF cap between GPIO4 and GND
    5) GPIO 12: 10K pull down resistor
    6) GPIO 5: 10K pull up resistor to 3.3V
    7) GPIO 15: 56K pull up resistor to 3.3V

    While uploading the code I pull down first GPIO 0 line and then EN line to GND and later when I see _’Connecting…….._____’ message on my Arduino IDE terminal I pull up the EN line and keep pressing the GPIO0 line until the Arduino IDE display error message: ‘A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header’

    What I understand is that I can put ESP32 in program mode if my GPIO 0 is zero after reset and if my GPIO 0 is high after reset then it goes into normal mode. In my case, I can enter in and out of both modes and my serial communication prints that message but I can’t flash new code because of packet header issue/ time out of the session.

    I know I can enter my ESP32 into program mode as I see following message on my serial monitor. Whenever my GPIO 0 is low and then when I toggle the EN signal from 1 (high) to 0 (low) and then back to 1(high). It shows following message which is good
    ‘rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))
    waiting for download’

    Reply
    • (reposting as reply to correct post.)

      I just tested with the same adapter I have.

      Solder a pin to the DTR and RTS pins if needed. Make sure you are using the 3.3v jumper position. I have my Arduino IDE set to ESP32 Dev Module, and the COM port which my adapter created. If you make these connections, no need to push any buttons, it programs automatically.

      Connect:
      ESP32 GPIO0 -> FTDI232 DTR
      ESP32 EN -> FTDI232 RTS
      ESP32 TX -> FTDI232 RX
      ESP32 RX -> FTDI232 TX
      ESP32 3.3v -> FTDI232 VCC
      10K pull-up to 3.3v on ESP32 EN
      10K pull-up to 3.3v on ESP32 GPIO0

      Reply
  53. Yes, I did look at it. Do you know if I do hard wiring to strapping pins in the configuration above then it should work. Are all the pins configuration looks correct to you?

    Reply
  54. I just tested with the same adapter I have.

    Solder a pin to the DTR and RTS pins if needed. Make sure you are using the 3.3v jumper position. I have my Arduino IDE set to ESP32 Dev Module, and the COM port which my adapter created. If you make these connections, no need to push any buttons, it programs automatically.

    Connect:
    ESP32 GPIO0 -> FTDI232 DTR
    ESP32 EN -> FTDI232 RTS
    ESP32 TX -> FTDI232 RX
    ESP32 RX -> FTDI232 TX
    ESP32 3.3v -> FTDI232 VCC
    10K pull-up to 3.3v on ESP32 EN
    10K pull-up to 3.3v on ESP32 GPIO0

    Reply

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.