Servo.h not working in Web Editor

I'm trying to use the Web editor for an IoT project, but when I try to include the library
#include <Servo.h>
I get the following eror message

/usr/local/bin/arduino-cli compile --fqbn esp32:esp32:uPesy_wroom --build-cache-path /tmp --output-dir /tmp/654265440/build --build-path /tmp/arduino-build-3FB57BAB7B2088FCFFF2C58B89DCF85C /tmp/654265440/LED_first_try_dec19a

In file included from /tmp/654265440/LED_first_try_dec19a/LED_first_try_dec19a.ino:18:

/home/builder/Arduino/libraries/servoesp32_1_1_1/src/Servo.h:67: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);

^

/home/builder/Arduino/libraries/servoesp32_1_1_1/src/Servo.h: In member function 'T ServoTemplate<T>::mapTemplate(T, T, T, T, T) const':

/home/builder/Arduino/libraries/servoesp32_1_1_1/src/Servo.h:256:28: error: 'is_floating_point_v' is not a member of 'std'

if constexpr (std::is_floating_point_v<T>) {

^~~~~~~~~~~~~~~~~~~

/home/builder/Arduino/libraries/servoesp32_1_1_1/src/Servo.h:256:28: note: suggested alternative: 'is_floating_point'

if constexpr (std::is_floating_point_v<T>) {

^~~~~~~~~~~~~~~~~~~

is_floating_point

/home/builder/Arduino/libraries/servoesp32_1_1_1/src/Servo.h:256:49: error: expected primary-expression before '>' token

if constexpr (std::is_floating_point_v<T>) {

^

/home/builder/Arduino/libraries/servoesp32_1_1_1/src/Servo.h:256:50: error: expected primary-expression before ')' token

if constexpr (std::is_floating_point_v<T>) {

^

Multiple libraries were found for "WiFi.h"

Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5/libraries/WiFi

Not used: /home/builder/opt/libraries/wifi_1_2_7

Not used: /home/builder/opt/libraries/nina_wi_fi_1_0_1

Not used: /home/builder/opt/libraries/wifinina_1_8_14

Not used: /home/builder/opt/libraries/wifiespat_1_4_3

Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6

Not used: /home/builder/opt/libraries/indhilib_3_0_5

Not used: /home/builder/opt/libraries/da16200_wi_fi_library_for_arduino_1_1_0

Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1

Multiple libraries were found for "WiFiClientSecure.h"

Used: /home/builder/.arduino15/packages/esp32/hardware/esp32/2.0.5/libraries/WiFiClientSecure

Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6

Multiple libraries were found for "Servo.h"

Used: /home/builder/opt/libraries/servoesp32_1_1_1

Not used: /home/builder/opt/libraries/microbitv2_hhs_0_1_6

Not used: /home/builder/opt/libraries/esp32_esp32s2_analogwrite_5_0_2

Not used: /home/builder/opt/libraries/servo_1_2_1

Not used: /home/builder/opt/libraries/evive_2_0_3

Not used: /home/builder/opt/libraries/rokitsmart_1_0_9

Not used: /home/builder/opt/libraries/printoo_library_1_0_2

Not used: /home/builder/opt/libraries/xmc_servo_1_0_1

Error during build: exit status 1

Any help would be appreciated

Hi @abdkhater. Unfortunately the author of the 3rd party "ServoESP32" library uses a non-standard configuration and doesn't bother to check whether the library will compile when using the standard configuration. The developers of the "esp32" boards platform explicitly configured it to use the C++11 standard, but the author recently introduced code into the library that is specific to the C++17 standard. That means it will only compile for those using a modified configuration that forces the C++17 standard to be used when compiling the sketch instead of the C++11 intended by the developers of the "esp32" boards platform.

It is not possible to make the necessary modifications to the esp32 boards platform when using Arduino Cloud. So if you want to use the "ServoESP32" library then you will need to use the last version before the bugs were introduced. I'll provide instructions you can follow to do that:

  1. Open your sketch in "Arduino Web Editor".
  2. From the menu on the left side of the "Arduino Web Editor" window, click "Libraries".
  3. Click the "LIBRARY MANAGER" button.
    The "Favorite the Contributed libraries you use the most" dialog will open.
  4. Type ServoESP32 in the "SEARCH LIBRARY" field.
  5. Find the "ServoESP32" library in the search results.
  6. If the star to the right of the library is not already filled, click the star.
    This will add the library to your "Favorites" in "Arduino Web Editor".
  7. Click the "Done" button.
    The "Favorite the Contributed libraries you use the most" dialog will close.
  8. From the Libraries panel of the "Arduino Web Editor" window, click the "Favorites" tab.
  9. Find the "ServoESP32" library in the list of favorite libraries and hover the mouse pointer over its name.
    An "Include ▼" button will appear to the right side of the library name.
  10. Click the on the right side of the "INCLUDE ▼" button.
    A menu will open.
  11. Select "1.0.3" from the menu.

This configures the currently opened sketch to always use version 1.0.3 of the "ServoESP32" library instead of the default behavior of using the newest version of the library.

Now try compiling your sketch again. Hopefully this time it will compile without any errors.

Although it is likely that you will be able to accomplish your project using the "ServoESP32" library, but this problem does indicate that it is not being maintained properly. You might consider evaluating the alternative libraries available for controlling servos from an ESP32 board. I did give the "ESP32Servo" library a quick try a couple months back and didn't experience any problems. That library is pre-installed in Arduino Cloud.

Thanks a lot, I gave the ESP32Servo library a try and it compiled successfully.

You are welcome. I'm glad it is working now.

Regards,
Per