Search code examples
arduinomicrocontrollerarduino-unoarduino-idearduino-esp32

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0x00): Possible serial noise or corruption


I keep getting the error in the title when trying to upload a sketch. I have tried to switch to different USB ports, resetting the ESP32 camera wrover, resetting the IO extension board and the UNO and changing the baud rate from the default 921600 baud to 115200 baud as well as the lowest possible baud, holding the reset button when uploading the sketch. I do not believe I am missing any drivers either.

The wiring is all correct according to the assembly instructions of the starter kit, so I do not think it is an issue with wiring like other similar posts. I also want to note that I have flipped the IO extension board to the upload mode so it does not encounter any errors.

This is the output when the sketch fails to upload, I cannot find anything on the troubleshooting site which has fixed it either. I have tested the camera itself by connecting to the boards WiFi and then viewing the live feed on a local server so I know there is no issue with the camera itself.

Serial port /dev/cu.usbmodem00001
Connecting......................................

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0x00): Possible serial noise or corruption.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
Failed uploading: uploading error: exit status 2

Here are some images for reference:

One potential issue that was mentioned to me was that the more complex the program, the longer it could take to upload so the baud rate needs to be decreased. I have tried the lowest baud rates with no solution. Here is the sketch I am trying to upload, which just simply connects to WiFi and then displays the networks information.

#define _UNIX03_SOURCE

#include <WiFi.h>
#include <stdlib.h>
#include "WiFiInfo.h"

const char* ssid = "wifi";
const char* password = "passsword";

// int setenv(const char* password, const char* password);

void setup() {
    Serial.begin(9600);
  delay(1000);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("Starting connection to WiFi network ");
  Serial.println(ssid);
  Serial.println("\n");
  
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println("Connecting to WiFi network ");
    Serial.println(ssid);
    Serial.println("...\n");
    delay(100);
  }

  Serial.println("Connected to WiFi network ");
  Serial.println(ssid);
  GetNetworkInfo(ssid);
}

void loop() {}

System information:

  • M2 chip
  • macOS Sonoma v14.6.1

Solution

  • Is this on MacOS? A very similar problem occurs there if the board is using the WCH serial chipset. The default driver is frustratingly compatible and almost works. The solution is so install the WCH driver (which is in Chinese and includes scary text about temporarily disabling security to install) and then be sure you use the /dev/cu.wchusbserialWHATEVER names. (This is necessary on my own Macs.)

    Some boards require you to hold the boot key down during the entire upload. I've never found a pattern as to which ones; mostly I've replaced those boards with ones that use better software-managed handling of the GPIO 0 (board-specific) and EN pins.