Arduino upload error

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

The upload tool sent its request and the chip said nothing back. The line of dots and underscores in the output is it trying again and again.

  • Upload error
  • 4 common causes
The message

What the Arduino IDE prints

Output window
Connecting.....__.....__
A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
Failed uploading: uploading error: exit status 2

Unlike the wrong boot mode error, nothing answered at all: the port, the speed or the wiring is the usual reason.

Causes

The 4 usual causes in order

1The upload speed is too high for the cable

A long or cheap cable corrupts fast transfers.

  1. In Tools, set Upload Speed to 115200.
  2. Upload again. If it works, a better cable lets you raise the speed later.

2The port is wrong, or another program has it

A serial monitor or a second IDE window can hold the port.

  1. Close the Serial Monitor and every other program that reads serial ports.
  2. Unplug the board, plug it in again, and pick the port that appears.

3The board is not resetting into download mode

The EN and BOOT lines may not be reaching the chip.

  1. Hold BOOT, tap EN once, then let go of BOOT, while Connecting... shows.
  2. Check that nothing is wired to EN, GPIO0 or GPIO2.

4The USB chip driver is missing or the supply sags

Boards with a CP210x or CH340 chip need a driver on Windows. A weak port resets the chip.

  1. Install the driver for the chip on your board.
  2. Plug straight into the computer, not a hub.
On a real board

What to do at the bench

Mokxi's Upload to board writes to a classic ESP32 from Chrome or Edge, through the same ROM bootloader esptool talks to, so the same causes stop it and the same fixes apply.

Run the sketch in Mokxi before you blame the board. If it builds and runs there, the code is fine and the problem is the connection to the real board.

Test the sketch in Mokxi first

Run the sketch here before you blame the board. If it builds and runs in Mokxi, the code is fine and the fault is the connection to the real board. Mokxi never uploads in a simulation, so it cannot raise this error itself.

A sketch to try first
void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println("blink ready");
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

Run it in Mokxi

FAQ

Questions and answers

What is a packet header?

The first bytes of every message from the chip. The tool waited for them and none came.

What are the dots and underscores?

Each one is an attempt to sync with the chip. A long line means the chip never answered.

Which setting changes first?

Upload Speed. Dropping it to 115200 is the quickest change and fixes many cases.