Urgent: A fatal error occurred: Failed to connect to ESP32: No serial data received

Intially the code was properly uploaded to the esp32. But suddenly it stopped. I have tried few methods but nothing helps.

Hi @valkyrie2811 ,

Welcome to the forum..

Could be a few different things..

You don't give allot of information..

If it's Windows then possible that a recent os update changes your drivers..

Look here first, see if it helps..

else need more info..

happened too me a few weeks ago, windows 11 and a esp32cam..
i got "a device attached to the system is not functioning properly" something like it anyways..
downgraded my driver and i was coding again..

good luck.. ~q

I have tried almost everything.
few library functions got updated I have even downgraded them. But it is still showing the same error.
I am using esp32 woom 32ue

following is the code:
#include <Wire.h>
#include <ICM_20948.h>
#include <ESP32Servo.h> // Use the ESP32Servo library

// Define pins
const int buttonPin = 12; // Button connected to GPIO12
const int l298nPin1 = 14; // L298N connected to GPIO14
const int l298nPin2 = 15; // L298N connected to GPIO15
const int servoPin = 13; // Servo connected to GPIO13

// Define state variables
bool buttonPressed = false;
bool actuatorExtended = false;
int servoPosition = 120; // Initial position set to 120 degrees

// Create objects
ICM_20948_I2C myICM; // Use I2C for communication
Servo myServo;

// Function to extend actuator
void extendActuator() {
digitalWrite(l298nPin1, HIGH);
digitalWrite(l298nPin2, LOW);
delay(5000); // Adjust delay based on actuator speed and travel time
digitalWrite(l298nPin1, LOW);
}

// Function to retract actuator
void retractActuator() {
digitalWrite(l298nPin1, LOW);
digitalWrite(l298nPin2, HIGH);
delay(5000); // Adjust delay based on actuator speed and travel time
digitalWrite(l298nPin2, LOW);
}

// Function to check movement and control servo
void checkMovement() {
// Update the sensor data
myICM.getAGMT();

// Print accelerometer values for debugging
Serial.print("accX: ");
Serial.print(myICM.accX());
Serial.print(" accY: ");
Serial.print(myICM.accY());
Serial.print(" accZ: ");
Serial.println(myICM.accZ());

// Check for significant movement along the X-axis
if (myICM.accX() > 1.0) {
myServo.write(0); // Move servo to 0 degrees
} else if (myICM.accX() < -1.0) {
myServo.write(180); // Move servo to 180 degrees
}
}

void setup() {
// Initialize serial communication
Serial.begin(115200);

// Initialize button pin
pinMode(buttonPin, INPUT_PULLUP);

// Initialize L298N pins
pinMode(l298nPin1, OUTPUT);
pinMode(l298nPin2, OUTPUT);

// Attach servo to pin
myServo.attach(servoPin);
myServo.write(servoPosition); // Set initial position to 120 degrees

// Initialize ICM-20948
Wire.begin();
if (myICM.begin(Wire, 0x69) != ICM_20948_Stat_Ok) { // Use I2C address 0x69
Serial.println("Failed to initialize ICM-20948");
while (1);
}
Serial.println("ICM-20948 initialized!");

// Set up ICM-20948 with correct configuration methods
ICM_20948_fss_t myFSS; // Full Scale Settings
myFSS.a = gpm2; // Set accelerometer to 2g
myFSS.g = dps250; // Set gyroscope to 250 degrees per second

if (myICM.setFullScale(ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr, myFSS) != ICM_20948_Stat_Ok) {
Serial.println("Failed to set full scale ranges");
while (1);
}

ICM_20948_dlpcfg_t myDLPFcfg;
myDLPFcfg.a = acc_d5bw7_n8bw3; // Accelerometer DLPF setting
myDLPFcfg.g = gyr_d5bw7_n8bw9; // Gyroscope DLPF setting

if (myICM.setDLPFcfg(ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr, myDLPFcfg) != ICM_20948_Stat_Ok) {
Serial.println("Failed to set DLPF configuration");
while (1);
}
}

void loop() {
// Check button state
if (digitalRead(buttonPin) == LOW) {
delay(50); // Debounce delay
if (!buttonPressed) {
buttonPressed = true;

  if (!actuatorExtended) {
    extendActuator();
    checkMovement();
    actuatorExtended = true;
  } else {
    retractActuator();
    myServo.write(servoPosition); // Move servo to initial position
    actuatorExtended = false;
  }
}

} else {
buttonPressed = false;
}

checkMovement(); // Continuously check for movement

delay(10); // Small delay to avoid rapid toggling
}

Have you tried just uploading a simple sketch?

Like, just a loop that prints "hello" once every 5 seconds or something?

Br Max

Don't think it's the code..
That error usually means your computer is not seeing the board..
Could also just be a bad usb cable..
Check your device manager, look under Ports and see if it's listed..

~q

i used another cable and even another port but it didnt help.
its listed under ports in device manager

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