Arduino-esp32: A fatal error occurred: Failed to connect to ESP32: Invalid head of packet ('S')

Created on 23 Mar 2018  路  29Comments  路  Source: espressif/arduino-esp32

Hardware:

Board: ?Widora Air V6?
Core Installation/update date: ?20/mar/2018?
IDE name: ?Arduino IDE?
Flash Frequency: ?40Mhz?
Upload Speed: ?115200?

Description:

When i try to connect my ESP32, i got this error "A fatal error occurred: Failed to connect to ESP32: Invalid head of packet ('S')". I tried to change upload speed or the flash frequency, but nothing work.
What can i do ?
Thanks

Sketch:

*
 *  This sketch demonstrates how to scan WiFi networks.
 *  The API is almost the same as with the WiFi Shield library,
 *  the most obvious difference being the different file you need to include:
 */
#include "WiFi.h"

void setup()
{
    Serial.begin(115200);

    // Set WiFi to station mode and disconnect from an AP if it was previously connected
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(100);

    Serial.println("Setup done");
}

void loop()
{
    Serial.println("scan start");

    // WiFi.scanNetworks will return the number of networks found
    int n = WiFi.scanNetworks();
    Serial.println("scan done");
    if (n == 0) {
        Serial.println("no networks found");
    } else {
        Serial.print(n);
        Serial.println(" networks found");
        for (int i = 0; i < n; ++i) {
            // Print SSID and RSSI for each network found
            Serial.print(i + 1);
            Serial.print(": ");
            Serial.print(WiFi.SSID(i));
            Serial.print(" (");
            Serial.print(WiFi.RSSI(i));
            Serial.print(")");
            Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
            delay(10);
        }
    }
    Serial.println("");

    // Wait a bit before scanning again
    delay(5000);
}

Debug Messages:

Connecting........_____....._____....._____....._____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to ESP32: Invalid head of packet ('S')

Most helpful comment

Hello there!
I had the same problem and I just found out it was because my upload speed (which is in "Tools") was set on 921600 instead of 115200.
Hope it would help :)

All 29 comments

Looks like your computer cannot see the ESP32

  • Are you on MAC? Check Wiki
  • Do you have the proper USB driver installed? CP2104 is the driver you need to look for Silabs drivers
  • Did you try different USB cable or different USB port?

I got the same error with and Espressif ESP32-WROOM-32. Device Manager shows the Silicon Labs CP210x USB to UART Bridge (Com15) for my port.
The sketch verifies, but does not Upload to the board. Changing the USB port to 4 gets different error.

Hello,
I fixed it by pressing "Load" button before switch the ESP32 on. The Rx/Tx leds stop to blink, so the serial port was no more use by the ESP. I tried to launch a connection, and it works .

Hi,

Although the issue is closed and the workaround works for me as well the problem still persists and I think that it could be related to writing to the Serial when the upload starts.

eg. in the above example "Invalid head of packet ('S')" might be coming from:

void setup() {
   ...
    Serial.println("Setup done");
}

In my case the message is "Invalid head of packet ('{')" and I'm using the aREST library that sends a standard json resposne to every serial input and it starts with '{'

Hopefully someone more knowledgeable than me can find a permanent solution.

Hi,

Although the issue is closed and the workaround works for me as well the problem still persists and I think that it could be related to writing to the Serial when the upload starts.

eg. in the above example "Invalid head of packet ('S')" might be coming from:

void setup() {
   ...
    Serial.println("Setup done");
}

In my case the message is "Invalid head of packet ('{')" and I'm using the aREST library that sends a standard json resposne to every serial input and it starts with '{'

Hopefully someone more knowledgeable than me can find a permanent solution.

I just got my first ESP32 (ESP32 Dev board), had the same issue, held down the boot button and my sketch uploaded fine.

ESP32-lyrat board: I fixed by press buttons while upload mode:
https://docs.espressif.com/projects/esp-adf/en/latest/get-started/index.html#upload

Yes as I've mentioned this method works for me as well but it makes it impossible to use OTA update with the device as you have to be physically present, pressing the button for the update to be able to run..

Press the "Boot" button on your ESP, Start uploading your code from Arduino IDE and keep "Boot" pressed till upload completes.

yes that's what the workaround is mentioned many times before, but in case the OTA (Over The Air) updates you can not physically access the device.. that is the whole point of it..

Hi,, I had the same problem. I really spent a bunch of time to realize that the problem was I didn't close the serial monitor. I'm using Platform.IO, but I imagine the problem could be similar.

Hello there!
I had the same problem and I just found out it was because my upload speed (which is in "Tools") was set on 921600 instead of 115200.
Hope it would help :)

hello everyone,
im an interne at a lab and i m new to programing. my tutor game me the M5stack to work on with the arduino IDE. i saw in a video that i have to install the m5stack libraries which i did.
when i go to "examples" to lunch "factory test" to be able to use the other examples on the arduino, i had a problem :
A fatal error occurred: Invalid head of packet (0xF0)
Can someone pls help ?
thank you !

Hello,
I fixed it by pressing "Load" button before switch the ESP32 on. The Rx/Tx leds stop to blink, so the serial port was no more use by the ESP. I tried to launch a connection, and it works .

@jfornech 馃憤 Thank you so much. It works now.

I had the same issue with ESP WROOM32.
Thanks for your tip.
Holding BOOT button fixed it.

hello every one.. i am in final year of CSE. I have my major project in IOT based Smart Waste Management System.
i have uno board, esp, breadboard, jump wires....and installed esp libraries in arduino ide.
But when i upload the code while selecting tools->Board->generic ESP8266.. it gives me the error ->esptool.FatalError: Failed to connect to ESP8266: Invalid head of packet (0xF0)

although in my code there are two empty functions setup() and loop()..

Please help me. thanx in advance

This forum is for esp32. esp8266 is a different piece of hardware.

can you plz tell me what should i do..

Hold on "Flash" button on ESP8266 while you are uploading your code

there are only a reset button on ESP8266 board.... I don't see any flash button on this board

My upload speed was 921600. After changing upload speed to 115200 it worked for me.

My upload speed was 921600. After changing upload speed to 115200 it worked for me.

Cool, that solved it for me as well, incredible, I never thought, faster is better :-)! Thanks a lot for this hint!

Press the "Boot" button on your ESP, Start uploading your code from Arduino IDE and keep "Boot" pressed till upload completes.

Thank you, this solved my problem

hi is there any pdate solutions to fix this issue beside holding the Boot button solutions, ?

holding the boot button on ESP32 on uploading code until code loaded solved problem.

Holding boot button was not sufficient for my case (ESP Lyrat). I had to keep pressing Boot while pressing "RST" button once. I have not seen any other resource that suggested this, I guess I am lucky.
Update: I found it in the latest esp32 "get started ADF" document, though the info was not available in the IDF document.
It says: "To upload the binaries, the board should be put into upload mode. To do so, hold down Boot button, momentarily press Reset button and release the Boot button.".

I have found the solutions from another blog you can solder some appropriate capacitor arround 10nF or above between RST and GND pin for the detail you can check randomnerdtutorials

I have found the solutions from another blog you can solder some appropriate capacitor arround 10nF or above between RST and GND pin for the detail you can check randomnerdtutorials

Could you please paste the link?

I have found the solutions from another blog you can solder some appropriate capacitor arround 10nF or above between RST and GND pin for the detail you can check randomnerdtutorials

Could you please paste the link?

Here you go
https://randomnerdtutorials.com/solved-failed-to-connect-to-esp32-timed-out-waiting-for-packet-header/
Also look at the comment section there are some other guys that trying different capacitor value as well

I had the same problem. For me when I press upload onthe IDE and get the message of connecting, I remove and put back the VCC and it show connecting. It's likely that the same effect would also be if I unplug and plug the rest wire, but I have not tried that.

My connections:

ESP12E Chip FTDI
VCC, CH_PD 3.3V
GRND, GPIO15, GPIO0 GRND
TX RX
RX TX

I remove the GPIO15 and GPIO0, once the upload is done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mistergreen picture mistergreen  路  4Comments

docloulou picture docloulou  路  3Comments

merlinschumacher picture merlinschumacher  路  4Comments

N0rbert picture N0rbert  路  4Comments

lonerzzz picture lonerzzz  路  3Comments