ESP32 DEVKIT Weird output

#include <Arduino.h>
#include <BLEGamepadClient.h>
#include <math.h>


XboxController controller;
#include <ESP32Servo.h>


Servo bucketServo; 
Servo clawServo; 

const int bucketServoPin = 27;
const int clawServoPin = 14;
const int motor1Pin1 = 19; //bucket motor
const int motor1Pin2 = 18;
const int motor2Pin1 = 5;
const int motor2Pin2 = 17;
const int motor3Pin1 = 25;
const int motor3Pin2 = 26;
float bucketServoAngle;
float clawServoAngle; 

void setup(void) {
  Serial.begin(115200);
  controller.begin();
  bucketServo.attach(bucketServoPin);
  clawServo.attach(clawServoPin);
  float bucketServoAngle = 350;
  float clawServoAngle = 0; 
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  // Disable DAC1


  pinMode(motor3Pin1, OUTPUT);
  pinMode(motor3Pin2, OUTPUT);


  // Disable DAC1







}

void loop() {
  if (controller.isConnected()) {
    XboxControlsEvent e;
    controller.readControls(e);
    double angle = 180/3.14* atan2(e.leftStickY,e.leftStickX);
    bucketServo.write(angle);
    clawServo.write(angle);






    Serial.printf("lx: %.2f, ly: %.2f, rx: %.2f, ry: %.2f\n",
e.leftStickX, e.leftStickY, e.rightStickX, e.rightStickY);
    // Serial.println("x: " + (String) e.buttonX);
    // Serial.println("y: " + (String) e.buttonY);
    // Serial.println("a: " + (String) e.buttonA);
    // Serial.println("b: " + (String) e.buttonB);
    Serial.println("Left bumper: " + (String) e.leftBumper);
    // Serial.println("Right bumper: " + (String) e.rightBumper);





    if(e.dpadUp){
        digitalWrite(motor1Pin1, HIGH);
        digitalWrite(motor1Pin2, LOW);
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);    
      } else if(e.dpadDown){
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, HIGH);
        digitalWrite(motor2Pin1, HIGH);
        digitalWrite(motor2Pin2, LOW);
      }
      else if(e.dpadLeft){
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, HIGH);
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);
      } else if(e.dpadRight){
        digitalWrite(motor1Pin1, HIGH);
        digitalWrite(motor1Pin2, LOW);
        digitalWrite(motor2Pin1, HIGH);
        digitalWrite(motor2Pin2, LOW);    
      } else{
        digitalWrite(motor1Pin1, LOW);
        digitalWrite(motor1Pin2, LOW);
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);          
      }
      if(e.leftBumper == 1){
        digitalWrite(motor3Pin1, HIGH);
        digitalWrite(motor3Pin2, LOW);
        Serial.println("Hi");
      }
      if(e.rightBumper == 1){
        digitalWrite(motor3Pin1, LOW);
        digitalWrite(motor3Pin2, HIGH);
      }
      digitalWrite(motor3Pin1, LOW);
      digitalWrite(motor3Pin2, LOW);

      delay(40);
  } else {
    Serial.println("controller not connected");
  }


  delay(10);



  

  
}

double moveBucketServo(XboxControlsEvent e, double servoangle){

  if(e.buttonY = 1){
    servoangle += 1;
  } else if(e.buttonB = 1) {
    servoangle -=1;
  }
  return servoangle;

}

double moveClawServo(XboxControlsEvent e, double servoangle){

  if(e.buttonX = 1){
    servoangle += 1;
  } else if(e.buttonA = 1) {
    servoangle -=1;
  }
  return servoangle;

}


boolean checkdpad(XboxControlsEvent e){
  if(e.dpadUp){
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  } else if(e.dpadDown){
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  }
  else if(e.dpadLeft){
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  } else if(e.dpadRight){
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);    
  }
}

When I run this on a brand new DOIT Esp32 Devkit V1, I get this junk in the serial monitor even though when its supposed to say controller not connected. Could someone please help me? I am just running this on an Esp32 Devkitv1 by itself with a cable.

I would imagine that there's a whole lot more to that error message that preceded the reboot, if you just scroll up to see it.


Heres a little more of that picture and it loops this

Well, you've got a backtrace there, and from little I know of ESP32, you can use that to track down where your error occurred. Google is your friend.

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

You’re not seeing what it’s supposed to print because it’s crashing (generating a back trace) before it gets to the point where it would print it.

You could analyse the back trace as someone already suggested. Alternatively, if you don’t feel confident about that, you could try a mixture of adding some serial prints to see how far it gets and commenting out chunks of code, until you narrow down which line of code is causing the crash.

There are so many mistakes in that code that I don't know where to start but this function

is supposed to return a boolean but doesn’t return anything, which is undefined behavior. Start by fixing this


other weird stuff are found in moveBucketServo and moveClawServo where you are using assignment instead of comparison (ie you use = instead of ==)

or the fact that you declared bucketServoAngle and clawServoAngle as globals, but in setup() you redeclared them as local variables:

float bucketServoAngle = 350;
float clawServoAngle = 0;

This means the global variables never get initialized (it's time to read about scope )

...

or why you would instantly set motor3Pin1 and motor3Pin2 to LOW nanoseconds after possibly setting them HIGH depending on the leftBumper and rightBumper status...

Sorry about the code, I was just sloppily developing it as a lot of it wouldn't work, so I was just editing willy-nilly, so theres a lot of junk in my code :/. I did figure it out as I just reinstalled Arduino IDE and its libraries and it worked :smiley: