Fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header_

// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;

// defines variables
long duration;
int distance;
int safetyDistance;

void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}

void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);

// Calculating the distance
distance= duration*0.034/2;

safetyDistance = distance;
if (safetyDistance <= 5){
digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(buzzer, LOW);
digitalWrite(ledPin, LOW);
}

// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}

code as ------^

error=====
Variables and constants in RAM (global, static), used 28176 / 80192 bytes (35%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1496 initialized variables
╠══ RODATA 936 constants
╚══ BSS 25744 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60363 / 65536 bytes (92%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 27595 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 236388 / 1048576 bytes (22%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 236388 code in flash
esptool.py v3.0
Serial port COM12
Connecting......................................____
A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header_

Is your ESP8266 connected to COM12?

yes

It says done uploading

The uploading program terminated, so it's done but it wasn't successful.

The error output you get is about the same you get if you connect to a device which isn't an ESP. So how do you know that COM12 is your ESP?

did you fix that issue

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.