Error While Compiling Code

Hi all. I've tried to compile this code many times and I keep getting the error message : "ledcSetup" was not declared in this scope. I've tried including different versions of the Two libraries, same thing . I'm not sure where to go with this. I've tried simpler code with the " ledcSetup " and I get the same error.
I am trying to control a remote car with a grippier arm and I'm using a PS3 controller and ESP32. I got the code from Git Hub. If anyone has any ideas or has experienced this please let me know . Thanks GeeHo

#include <Ps3Controller.h>
#include <ESP32Servo.h>

#define SERVO_FORWARD_STEP_ANGLE 1
#define SERVO_BACKWARD_STEP_ANGLE -1

struct ServoPins
{
  Servo servo;
  int servoPin;
  String servoName;
  int initialPosition;  
};
std::vector<ServoPins> servoPins = 
{
  { Servo(), 27 , "Base", 90},
  { Servo(), 26 , "Shoulder", 90},
  { Servo(), 25 , "Elbow", 90},
  { Servo(), 33 , "Gripper", 90},
};

bool gripperSwitch = false;

//Right motor
int enableRightMotor=22; 
int rightMotorPin1=16;
int rightMotorPin2=17;
//Left motor
int enableLeftMotor=23;
int leftMotorPin1=18;
int leftMotorPin2=19;

#define MAX_MOTOR_SPEED 200  //Its value can range from 0-255. 255 is maximum speed.

const int PWMFreq = 1000; /* 1 KHz */
const int PWMResolution = 8;
const int PWMSpeedChannel = 4;

void writeServoValues(int servoIndex, int servoMoveStepSize, bool servoStepSizeIsActualServoPosition = false)
{
  int servoPosition;
  if (servoStepSizeIsActualServoPosition)
  {
    servoPosition = servoMoveStepSize; 
  }
  else
  {
    servoPosition = servoPins[servoIndex].servo.read();
    servoPosition = servoPosition + servoMoveStepSize;
  }
  if (servoPosition > 180 || servoPosition < 0)
  {
    return;
  }

  servoPins[servoIndex].servo.write(servoPosition);   
}


void notify()
{
  int rx =(Ps3.data.analog.stick.rx);  //Base       =>  Right stick - x axis
  int ry =(Ps3.data.analog.stick.ry);  //Shoulder   =>  Right stick  - y axis
  int ly =(Ps3.data.analog.stick.ly);  //Elbow      =>  Left stick  - y axis 
  int lx =(Ps3.data.analog.stick.lx);  //Gripper    =>  Left stick - x axis

  if (rx > 50)
  {
    writeServoValues(0, SERVO_BACKWARD_STEP_ANGLE);  
  }
  else if (rx < -50)
  {
    writeServoValues(0, SERVO_FORWARD_STEP_ANGLE);  
  }

  if (ry > 50)
  {
    writeServoValues(1, SERVO_BACKWARD_STEP_ANGLE);  
  }
  else if (ry < -50)
  {
    writeServoValues(1, SERVO_FORWARD_STEP_ANGLE);  
  }

  if (ly > 50)
  {
    writeServoValues(2, SERVO_FORWARD_STEP_ANGLE);  
  }
  else if (ly < -50)
  {
    writeServoValues(2, SERVO_BACKWARD_STEP_ANGLE);  
  }

  if (lx > 50)
  {
    writeServoValues(3, SERVO_BACKWARD_STEP_ANGLE);  
  }
  else if (lx < -50)
  {
    writeServoValues(3, SERVO_FORWARD_STEP_ANGLE);  
  }

  if (Ps3.event.button_down.r2)
  {
    gripperSwitch = !gripperSwitch;  //Toggle gripper close / open
    gripperSwitch ? writeServoValues(3, 170, true) :  writeServoValues(3, 100, true) ;
  }

  if (Ps3.data.button.up)             //Move car Forward
  {
    rotateMotor(MAX_MOTOR_SPEED, MAX_MOTOR_SPEED);
  }
  else if (Ps3.data.button.down)      //Move car Backward
  {
    rotateMotor(-MAX_MOTOR_SPEED, -MAX_MOTOR_SPEED);
  }
  else if (Ps3.data.button.right)     //Move car Right
  {
    rotateMotor(-MAX_MOTOR_SPEED, MAX_MOTOR_SPEED);
  }
  else if (Ps3.data.button.left)      //Move car Left
  {
    rotateMotor(MAX_MOTOR_SPEED, -MAX_MOTOR_SPEED);
  }
  else                                //Stop the car
  {
    rotateMotor(0, 0);
  } 
    
  delay(10);
  
}

void onConnect()
{
  Serial.println("Connected!.");
}

void onDisConnect()
{
  Serial.println("Disconnected!.");    
}

void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
  if (rightMotorSpeed < 0)
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,HIGH);    
  }
  else if (rightMotorSpeed > 0)
  {
    digitalWrite(rightMotorPin1,HIGH);
    digitalWrite(rightMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,LOW);      
  }
  
  if (leftMotorSpeed < 0)
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,HIGH);    
  }
  else if (leftMotorSpeed > 0)
  {
    digitalWrite(leftMotorPin1,HIGH);
    digitalWrite(leftMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,LOW);      
  }  
}

void setUpPinModes()
{
  for (int i = 0; i < servoPins.size(); i++)
  {
    servoPins[i].servo.attach(servoPins[i].servoPin);
    servoPins[i].servo.write(servoPins[i].initialPosition);    
  }

  pinMode(enableRightMotor,OUTPUT);
  pinMode(rightMotorPin1,OUTPUT);
  pinMode(rightMotorPin2,OUTPUT);
  
  pinMode(enableLeftMotor,OUTPUT);
  pinMode(leftMotorPin1,OUTPUT);
  pinMode(leftMotorPin2,OUTPUT);

  //Set up PWM for motor speed
  ledcSetup(PWMSpeedChannel, PWMFreq, PWMResolution);
  ledcAttachPin(enableRightMotor, PWMSpeedChannel);
  ledcAttachPin(enableLeftMotor, PWMSpeedChannel);  
  ledcWrite(PWMSpeedChannel, MAX_MOTOR_SPEED);
  
  rotateMotor(0, 0);  
}


void setup()
{
  setUpPinModes();
  Serial.begin(115200);
  Ps3.attach(notify);
  Ps3.attachOnConnect(onConnect);
  Ps3.attachOnDisconnect(onDisConnect);
  Ps3.begin();
  Serial.println("Ready.");
}

void loop()
{
}

You have a sketch written for the 2.x ESP32 core and you are trying to compile it with a 3.x core. There were many breaking changes included in the 3.x core, including the one you have run into.

PS: if you just want to compile your code and do not care about being on the bleeding edge, roll your ESP32 core back to a 2.x release with the Boards Manager.

Hi, @geeho
Welcome to the forum.

Please post the simpler code, it will be easier for us to troubleshoot.

Tom.... :smiley: :+1: :coffee: :australia:

Try commenting faking out this line and see if it compiles or changes the error:
Insert this code: void ledcSetup(){} That should make the compiler happy but it will not make it work.
"ledcSetup" was not declared in this scope. is telling you that it cannot find the function ledcSetup()

Thanks for the tip on down grading the board manager . It worked on all of the other projects that would not compile for other reasons, but not on this project and one other that uses servos and the servo library. I've tried different versions of both BM and Libraries with no luck . The only thing that changes is the error message. ( 'vector' in namespace 'std' does not name a template type.) GeeHo

I will give that a try . I did try commenting that section and the code did compile and up load but of course nothing worked . Thanks GeeHo

Here is another project I am working on . This project is just the 4 servo Gripper Arm without the remote car . I get the same errors . I've tried every ESP32 Servo library on Git Hub . No luck . Thanks

#include <Ps3Controller.h>
#include <ESP32Servo.h>

#define SERVO_FORWARD_STEP_ANGLE 1
#define SERVO_BACKWARD_STEP_ANGLE -1

struct ServoPins
{
  Servo servo;
  int servoPin;
  String servoName;
  int initialPosition;  
};
std::vector<ServoPins> servoPins = 
{
  { Servo(), 27 , "Base", 90},
  { Servo(), 26 , "Shoulder", 90},
  { Servo(), 25 , "Elbow", 90},
  { Servo(), 33 , "Gripper", 90},
};

struct RecordedStep
{
  int servoIndex;
  int value;
  int delayInStep;
};
std::vector<RecordedStep> recordedSteps;

bool recordSteps = false;
bool playRecordedSteps = false;
bool gripperSwitch = false;

unsigned long previousTimeInMilli = millis();

void writeServoValues(int servoIndex, int servoMoveStepSize, bool servoStepSizeIsActualServoPosition = false)
{
  int servoPosition;
  if (servoStepSizeIsActualServoPosition)
  {
    servoPosition = servoMoveStepSize; 
  }
  else
  {
    servoPosition = servoPins[servoIndex].servo.read();
    servoPosition = servoPosition + servoMoveStepSize;
  }
  if (servoPosition > 180 || servoPosition < 0)
  {
    return;
  }
  
  if (recordSteps)
  {
    recordRobotArmStep(servoIndex, servoPosition);
  }
  
  servoPins[servoIndex].servo.write(servoPosition);   
}

void recordRobotArmStep(int servoIndex, int servoPosition)
{
  RecordedStep recordedStep;       
  if (recordedSteps.size() == 0) // We will first record initial position of all servos. 
  {
    for (int i = 0; i < servoPins.size(); i++)
    {
      recordedStep.servoIndex = i; 
      recordedStep.value = servoPins[i].servo.read(); 
      recordedStep.delayInStep = 0;
      recordedSteps.push_back(recordedStep);         
    }      
  }
  unsigned long currentTime = millis();
  recordedStep.servoIndex = servoIndex; 
  recordedStep.value = servoPosition; 
  recordedStep.delayInStep = currentTime - previousTimeInMilli;
  recordedSteps.push_back(recordedStep);  
  previousTimeInMilli = currentTime;         
}

void playRecordedRobotArmSteps()
{
  if (recordedSteps.size() == 0)
  {
    return;
  }
  //This is to move servo to initial position slowly. First 4 steps are initial position    
  for (int i = 0; i < 4 && playRecordedSteps; i++)
  {
    RecordedStep &recordedStep = recordedSteps[i];
    int currentServoPosition = servoPins[recordedStep.servoIndex].servo.read();
    while (currentServoPosition != recordedStep.value && playRecordedSteps)  
    {
      currentServoPosition = (currentServoPosition > recordedStep.value ? currentServoPosition - 1 : currentServoPosition + 1); 
      servoPins[recordedStep.servoIndex].servo.write(currentServoPosition);
      delay(50);
    }
  }
  delay(2000); // Delay before starting the actual steps.
  
  for (int i = 4; i < recordedSteps.size() && playRecordedSteps ; i++)
  {
    RecordedStep &recordedStep = recordedSteps[i];
    delay(recordedStep.delayInStep);
    servoPins[recordedStep.servoIndex].servo.write(recordedStep.value);
  }
}

void notify()
{
  int rx =(Ps3.data.analog.stick.rx);  //Base       =>  Right stick - x axis
  int ry =(Ps3.data.analog.stick.ry);  //Shoulder   =>  Right stick  - y axis
  int ly =(Ps3.data.analog.stick.ly);  //Elbow      =>  Left stick  - y axis 
  int lx =(Ps3.data.analog.stick.lx);  //Gripper    =>  Left stick - x axis

  if (Ps3.event.button_down.start)
  {
    playRecordedSteps = !playRecordedSteps;
    recordSteps = false;
  }  
  else if (!playRecordedSteps && Ps3.event.button_down.select)
  {
    recordSteps = !recordSteps;
    if (recordSteps)
    {
      recordedSteps.clear();
      previousTimeInMilli = millis();
    }
  }  
  else if (!playRecordedSteps)
  {
    if (rx > 50)
    {
      writeServoValues(0, SERVO_BACKWARD_STEP_ANGLE);  
    }
    else if (rx < -50)
    {
      writeServoValues(0, SERVO_FORWARD_STEP_ANGLE);  
    }
  
    if (ry > 50)
    {
      writeServoValues(1, SERVO_BACKWARD_STEP_ANGLE);  
    }
    else if (ry < -50)
    {
      writeServoValues(1, SERVO_FORWARD_STEP_ANGLE);  
    }
  
    if (ly > 50)
    {
      writeServoValues(2, SERVO_FORWARD_STEP_ANGLE);  
    }
    else if (ly < -50)
    {
      writeServoValues(2, SERVO_BACKWARD_STEP_ANGLE);  
    }

    if (lx > 50)
    {
      writeServoValues(3, SERVO_BACKWARD_STEP_ANGLE);  
    }
    else if (lx < -50)
    {
      writeServoValues(3, SERVO_FORWARD_STEP_ANGLE);  
    }

    if (Ps3.event.button_down.r2)
    {
      gripperSwitch = !gripperSwitch;  //Toggle gripper close / open
      gripperSwitch ? writeServoValues(3, 170, true) :  writeServoValues(3, 100, true) ;
    }
    
    delay(10);
  }    
}

void onConnect()
{
  Serial.println("Connected!.");
}

void onDisConnect()
{
  Serial.println("Disconnected!.");    
}

void setUpPinModes()
{
  for (int i = 0; i < servoPins.size(); i++)
  {
    servoPins[i].servo.attach(servoPins[i].servoPin);
    servoPins[i].servo.write(servoPins[i].initialPosition);    
  }
}


void setup()
{
  setUpPinModes();
  Serial.begin(115200);
  Ps3.attach(notify);
  Ps3.attachOnConnect(onConnect);
  Ps3.attachOnDisconnect(onDisConnect);
  Ps3.begin();
  Serial.println("Ready.");
}

void loop()
{
  if (playRecordedSteps)
  { 
    playRecordedRobotArmSteps();
  }  
}

Here is another project I am working on that also uses the LEDC function . This one compiles and up loads just fine and the remote car works great . I'm using the same BM 2.0.0 And PS3 library and same ESP32 board and this works fine.
GeeHo

#include <Ps3Controller.h>



//Right motor
int enableRightMotor=22; 
int rightMotorPin1=16;
int rightMotorPin2=17;
//Left motor
int enableLeftMotor=23;
int leftMotorPin1=18;
int leftMotorPin2=19;

#define MAX_MOTOR_SPEED 200

const int PWMFreq = 1000; /* 1 KHz */
const int PWMResolution = 8;
const int PWMSpeedChannel = 4;

void notify()
{
  int yAxisValue =(Ps3.data.analog.stick.ly);  //Left stick  - y axis - forward/backward car movement
  int xAxisValue =(Ps3.data.analog.stick.rx);  //Right stick - x axis - left/right car movement

  if (yAxisValue <= -50)       //Move car Forward
  {
    rotateMotor(MAX_MOTOR_SPEED, MAX_MOTOR_SPEED);
  }
  else if (yAxisValue >= 50)   //Move car Backward
  {
    rotateMotor(-MAX_MOTOR_SPEED, -MAX_MOTOR_SPEED);
  }
  else if (xAxisValue >= 50)  //Move car Right
  {
    rotateMotor(-MAX_MOTOR_SPEED, MAX_MOTOR_SPEED);
  }
  else if (xAxisValue <= -50)   //Move car Left
  {
    rotateMotor(MAX_MOTOR_SPEED, -MAX_MOTOR_SPEED);
  }
  else                                      //Stop the car
  {
    rotateMotor(0, 0);
  } 
}

void onConnect()
{
  Serial.println("Connected!.");
}

void onDisConnect()
{
  rotateMotor(0, 0);
}

void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
  if (rightMotorSpeed < 0)
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,HIGH);    
  }
  else if (rightMotorSpeed > 0)
  {
    digitalWrite(rightMotorPin1,HIGH);
    digitalWrite(rightMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,LOW);      
  }
  
  if (leftMotorSpeed < 0)
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,HIGH);    
  }
  else if (leftMotorSpeed > 0)
  {
    digitalWrite(leftMotorPin1,HIGH);
    digitalWrite(leftMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,LOW);      
  }  
}

void setUpPinModes()
{
  pinMode(enableRightMotor,OUTPUT);
  pinMode(rightMotorPin1,OUTPUT);
  pinMode(rightMotorPin2,OUTPUT);
  
  pinMode(enableLeftMotor,OUTPUT);
  pinMode(leftMotorPin1,OUTPUT);
  pinMode(leftMotorPin2,OUTPUT);

  //Set up PWM for motor speed
  ledcSetup(PWMSpeedChannel, PWMFreq, PWMResolution);
  ledcAttachPin(enableRightMotor, PWMSpeedChannel);
  ledcAttachPin(enableLeftMotor, PWMSpeedChannel);  
  ledcWrite(PWMSpeedChannel, MAX_MOTOR_SPEED);
  
  rotateMotor(0, 0);
}


void setup()
{
  setUpPinModes();
  Serial.begin(115200);
  Ps3.attach(notify);
  Ps3.attachOnConnect(onConnect);
  Ps3.attachOnDisconnect(onDisConnect);
  Ps3.begin("a0:5a:5d:00:53:87");
  Serial.println("Ready.");
}

void loop()
{
}

That turns out not to be the case.

"The only thing"?

You did not think this through.

You are getting a different error.

So downgrading the core solved your original problem. ledcSetup was now defined.

And if you had read the entire new error message, the solution to the new error was given to you.

note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?

The compiler very helpfully suggested something that would have fixed the new problem with the old core. But your insistence that you have a library version problem is blinding you to everything else.