Timed out waiting for packet header *** [upload] Error 2

A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
*** [upload] Error 2

I’ve been able to get past this error with my Nano by pulling it out of the breadboard.
Why does it happen, and how can i fix it?

Huh? Which is it… an ESP32 style board, or an Arduino Nano? Otherwise, it’s because you’re trying to upload ESP32 to an Arduino Nano, which is plain wrong!

Otherwise, if it really is an ESP32-based development board it’s probably becasue it isn’t resetting properly when instructed to do so as part of initialising the programming process. A workaround is to press and hold the reset button, press the upload button on your computer, and when it says connecting in the upload log, let go of the button, and it should continue properly.

i.e. [SOLVED] Failed to connect to ESP32: Timed out waiting for packet header | Random Nerd Tutorials

Thanks. There are two boards in the prompt, because the error has shown up when using any kind of board. My Chinese Nano doesn’t work the first time if it’s in the breadboard. And it fails to connect a lot. I often switch to something else.

The reset button appears to work sometimes, but PlatformIO automatically re-attempts, and I’m able to upload after some random number of attempts. The randomness of it has convinced me to stop pushing the button. I have a twin, and I’ll see if that reset button resets that unit.