Esp 32s servo not working correctly

Hi im trying to use the servo with my esp32s but it does not work and the error code im getting is the following:

In file included from C:\Users\hacke\AppData\Local\Temp\.arduinoIDE-unsaved2023824-24352-n4hf7f.uateh\01-SimpleServo\01-SimpleServo.ino:1:
c:\Users\hacke\Documents\Arduino\libraries\ServoESP32\src/Servo.h:68:81: error: call to non-'constexpr' function 'const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = int]'
     static const int TIMER_RESOLUTION = std::min(16, SOC_LEDC_TIMER_BIT_WIDE_NUM);
                                                                                 ^
c:\Users\hacke\Documents\Arduino\libraries\ServoESP32\src/Servo.h: In member function 'T ServoTemplate<T>::mapTemplate(T, T, T, T, T) const':
c:\Users\hacke\Documents\Arduino\libraries\ServoESP32\src/Servo.h:256:28: error: 'is_floating_point_v' is not a member of 'std'
         if constexpr (std::is_floating_point_v<T>) {
                            ^~~~~~~~~~~~~~~~~~~
c:\Users\hacke\Documents\Arduino\libraries\ServoESP32\src/Servo.h:256:28: note: suggested alternative: 'is_floating_point'
         if constexpr (std::is_floating_point_v<T>) {
                            ^~~~~~~~~~~~~~~~~~~
                            is_floating_point
c:\Users\hacke\Documents\Arduino\libraries\ServoESP32\src/Servo.h:256:49: error: expected primary-expression before '>' token
         if constexpr (std::is_floating_point_v<T>) {
                                                 ^
c:\Users\hacke\Documents\Arduino\libraries\ServoESP32\src/Servo.h:256:50: error: expected primary-expression before ')' token
         if constexpr (std::is_floating_point_v<T>) {
                                                  ^

exit status 1

Compilation error: exit status 1

I do not know the reason for this and any help or suggestion would be major. Thank you and hope you guys are having a good day.

Of course not as You have not gotten the code downloaded.

You need to use a correct syntax. More....

Please read and use this topic: How to get the best out of this forum - Using Arduino / IDE 1.x - Arduino Forum

i do have the library downloaded and the code i used was part as the example.

#include <Servo.h>

static const int servoPin = 13;

Servo servo1;

void setup() {
    Serial.begin(115200);
    servo1.attach(servoPin);
}

void loop() {
    for(int posDegrees = 0; posDegrees <= 180; posDegrees++) {
        servo1.write(posDegrees);
        Serial.println(posDegrees);
        delay(20);
    }

    for(int posDegrees = 180; posDegrees >= 0; posDegrees--) {
        servo1.write(posDegrees);
        Serial.println(posDegrees);
        delay(20);
    }
}

Why don't You follow and respond to the last line advice in reply #2?
You need to read the full reply, not only one line.

Servo.h Library is not supported by ESP32.

Include the attached Libray with the IDE and then upload the following example taken from IDE's Examples. Report the result. I attached a very old SG90 Servo, but it turns intermittently. Use seperate 5V power supply as the Servo takes about 100 - 250 mA during movement with load; whereas, ESP32's pin can supply max 40 mA (recommended use is 20 mA).

#include <ESP32Servo.h>

Servo myservo;  // create servo object to control a servo
int pos = 0;

int servoPin = 13;

void setup()
{
  // Allow allocation of all timers
  ESP32PWM::allocateTimer(0);
  ESP32PWM::allocateTimer(1);
  ESP32PWM::allocateTimer(2);
  ESP32PWM::allocateTimer(3);
  myservo.setPeriodHertz(50);    // standard 50 hz servo
  myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
}

void loop() 
{
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);    // tell servo to go to position in variable 'pos'
    delay(15);             // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);    // tell servo to go to position in variable 'pos'
    delay(15);             // waits 15ms for the servo to reach the position
  }
}

ESP32Servo-0.13.0.zip (52.6 KB)

1 Like

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