Libraries problem using Arduino NANO ESP32 on IoT Cloud

Hello!
I'd like to control a servo while out of its physical and wifi range, but I'm having some trouble with that.

  • The ANESP32 is plugged and the Create Agent founds it
  • On cloud.arduino.cc I've added the device, a new thing with the device attached and created the read-and-write-on-change "servo" int. variable. Plus, added a slider attached to the variable from 0 to 180 in a dashboard
  • Created a new network connection using my 2.4GHz Wifi and the secret key
  • A servo is connected using a breadboard to the 3.3V header, GND and D10 on an Arduino Nano ESP32
    The code is posted below:
#include "thingProperties.h"
#include <Servo.h>

Servo myservo;

void setup() {

  Serial.begin(9600);
  
  delay(1500); 

  myservo.attach(10);
  
  initProperties();

  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  
}

void onServoChange()  {
  myservo.write(servo);
}

After veryifing and uploading on the COM9, bot the Sketch and the Web Editor return an error:

In file included from /tmp/1925118414/sketch_sep21a/sketch_sep21a.ino:1:

/home/builder/Arduino/libraries/servoesp32_1_1_1/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);

^

/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 "Servo.h"

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

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

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

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

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

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

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

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

Error during build: exit status 1

Could you please help me understanding what's going on?
Thanks,
Vincenzo

EDIT 1:
I've tried the NANO ESP32 Blink example in the local Arduino IDE and works like a charm
EDIT 2:
Same goes for the Arduino Web Editor

Hey @vincenzojrs , unrelated to the compilation issues, you should not connect the servo motor to the Arduino directly. Upon a servo movement, there are current spikes that can/will damage your board, and since Arduino IoT Cloud uses also a lot of power when connecting, it will likely cause your board to reset frequently!

It "works", it is just not reliable and is definitely not good for your board.

A solution to this is just to power your servo motor separately, using a battery pack with a voltage that matches your servo motor.

1 Like

Thank you so much!

Hi @vincenzojrs

Unfortunately there is a bug in the "ServoESP32" library that causes these errors.

I found an alternative library for using servo motors with the ESP32 family of microcontrollers that is actually in a functional state. The name is "ESP32Servo". I verified it does work with the Nano ESP32 board.

Unfortunately the "ESP32Servo" library is not compatible with the version of the "Arduino ESP32 Boards" platform that is currently installed in Arduino Cloud, so sketches using the "ESP32Servo" library can only be compiled using Arduino IDE at this time.

If you decide to give it a try, the ESP32Servo library can be installed using the Arduino IDE Library Manager. After that, you will find the example sketches demonstrating the use of the library under the File > Examples menu in Arduino IDE. I recommend the "Sweep" library as a nice simple demonstration.

It is necessary to make a special configuration of Arduino IDE in order to use the Nano ESP32 board with this library: select Tools > Pin Numbering > By GPIO number (legacy) from the menu. With this option selected, you must use the GPIO number of the Nano ESP32 board's pins in your sketch code instead of the numbers that are printed on the board. You can see the GPIO numbers in the pinout diagram available from this page:

For example, if you have your servo connected to the pin marked 2 on the Nano ESP32, you can see from the pinout diagram that is GPIO number 5:

image

So you must use the pin number 5 in the sketch:

myservo.attach(5, 1000, 2000);

I recommend verifying your servo is working correctly with a simple sketch like "Sweep" before moving on to integrating the servo into the significantly more complex Arduino IoT Cloud sketch.


Note that you can work with Arduino IoT Cloud Thing sketches in Arduino IDE. Arduino IDE 2.x even has a convenient integration with your Arduino Cloud sketchbook:

1 Like

Thanks ptillisch!

  • I've succeded in syncing my IDE with the IoT Cloud platform
  • Installing the ESP32Servo library (in the IDE)
  • Changing the PIN enumeration to GPIO (in the IDE)
  • Making ESP32Servo > Sweep working (in the IDE)!
    What an achievement!

Unfortunately, I need to use the IoT Cloud platform to control my board when not at home. If I push the code in the cloud which works locally after changing the enumeration, an error returns:

#include <ESP32Servo.h>
Servo myservo;

void setup() {
        // The servo is attached to the printed D10 pin or GPIO 21
	myservo.attach(21, 1000, 2000);
}

void loop() {
	myservo.write(1);
	delay(1000);
	myservo.write(180);
	delay(1000);
}

The error:

In file included from /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Servo.h:69, from /tmp/3937737916/Untitled_sep21b/Untitled_sep21b.ino:3: /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Tone.h:11:41: error: macro "tone" requires 3 arguments, but only 2 given void tone(int pin,unsigned int frequency); ^ Multiple libraries were found for "WiFi.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFi Not used: /home/builder/opt/libraries/wifinina_1_8_14 Not used: /home/builder/opt/libraries/wifiespat_1_4_2 Not used: /home/builder/opt/libraries/indhilib_3_0_5 Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 Not used: /home/builder/opt/libraries/wifi_1_2_7 Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1 Not used: /home/builder/opt/libraries/da16200_wi_fi_library_for_arduino_1_1_0 Multiple libraries were found for "WiFiClientSecure.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFiClientSecure Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 Error during build: exit status 1
In file included from /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Servo.h:69, from /tmp/3937737916/Untitled_sep21b/Untitled_sep21b.ino:3: /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Tone.h:11:41: error: macro "tone" requires 3 arguments, but only 2 given void tone(int pin,unsigned int frequency); ^ Multiple libraries were found for "WiFi.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFi Not used: /home/builder/opt/libraries/wifinina_1_8_14 Not used: /home/builder/opt/libraries/wifiespat_1_4_2 Not used: /home/builder/opt/libraries/indhilib_3_0_5 Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 Not used: /home/builder/opt/libraries/wifi_1_2_7 Not used: /home/builder/opt/libraries/vega_wifinina_1_0_1 Not used: /home/builder/opt/libraries/da16200_wi_fi_library_for_arduino_1_1_0 Multiple libraries were found for "WiFiClientSecure.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFiClientSecure Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 Error during build: exit status 1

I guess the problem is related to the enumeration. I've also tried to attach the servo using another notation without success:

myservo.attach(D10, 1000, 2000);

The code which includes the data about my wifi connection which I expect to work on the IoT Cloud platform is:

#include "thingProperties.h"
#include <ESP32Servo.h>

Servo myservo;

void setup() {
  Serial.begin(9600);
  delay(1500);
  myservo.attach(21, 1000, 2000); // or D10??
  initProperties();

  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
 }

void onServovariableChange()  {
  servo.write(servovariable);
}

but...

In file included from /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Servo.h:69, from /tmp/728786562/Untitled_sep21b/Untitled_sep21b.ino:3: /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Tone.h:11:41: error: macro "tone" requires 3 arguments, but only 2 given void tone(int pin,unsigned int frequency); ^ Multiple libraries were found for "WiFiClientSecure.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFiClientSecure Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 Multiple libraries were found for "WiFi.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFi Not used: /home/builder/opt/libraries/indhilib_3_0_5 Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 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 Not used: /home/builder/opt/libraries/wifi_1_2_7 Not used: /home/builder/opt/libraries/wifiespat_1_4_2 Not used: /home/builder/opt/libraries/wifinina_1_8_14 Error during build: exit status 1
In file included from /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Servo.h:69, from /tmp/728786562/Untitled_sep21b/Untitled_sep21b.ino:3: /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Tone.h:11:41: error: macro "tone" requires 3 arguments, but only 2 given void tone(int pin,unsigned int frequency); ^ Multiple libraries were found for "WiFiClientSecure.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFiClientSecure Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 Multiple libraries were found for "WiFi.h" Used: /home/builder/.arduino15/packages/arduino/hardware/esp32/2.0.11/libraries/WiFi Not used: /home/builder/opt/libraries/indhilib_3_0_5 Not used: /home/builder/opt/libraries/seeed_arduino_rpcwifi_1_0_6 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 Not used: /home/builder/opt/libraries/wifi_1_2_7 Not used: /home/builder/opt/libraries/wifiespat_1_4_2 Not used: /home/builder/opt/libraries/wifinina_1_8_14 Error during build: exit status 1

By "control your board", do you mean using an Arduino IoT Cloud dashboard? If so, that is no problem. The dashboard will work exactly the same regardless of whether you used Arduino Cloud or Arduino IDE to upload the Thing sketch to your Device.

I already explained that the ESP32Servo library can't be compiled in Arduino Cloud. The reason is because currently there is no "Pin Numbering" menu in Arduino Web Editor due to Arduino Cloud having an outdated version of the Nano ESP32 boards platform installed. So this error is expected. Once the Arduino Cloud developers get around to updating the platform you will be able to compile the library in Arduino Cloud, but until then the only option is to use Arduino IDE.

For some reason when you post output on the forum the line endings are missing, which causes it to all be mashed together on a single line. That makes it absolutely impossible for the helpers here to read the important information contained there. I suggest you investigate this problem as it will seriously impact your ability to get assistance here on the forum in the future. A moderator had to edit your previous post to fix the problem.

This is how it should look (just the same as it does in the Arduino Cloud output panel:

In file included from /home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Servo.h:69,

from /tmp/2614102731/sketch_sep21a/sketch_sep21a.ino:1:

/home/builder/Arduino/libraries/esp32servo_0_13_0/src/ESP32Tone.h:11:41: error: macro "tone" requires 3 arguments, but only 2 given

void tone(int pin,unsigned int frequency);

^

Error during build: exit status 1

Do you see how much easier it is to read?

Thanks, ptillisch! Much clearer!
I’d like to control the servo over the cloud so that it moves when I’m not at the computer.
Actually, it’s supposed to press a button to power up the UPS which automatically powers up the computer.
It seems that using the new NanoESP32 isn’t the way (till today).
Would you say that an ESP8266 will work?

You can definitely do that with the Nano ESP32. The only catch is that in order to use the ESP32Servo library you will need to upload your sketch using Arduino IDE. But at most that is a minor inconvenience.

Please take careful note of what I said in my previous reply:

A common misconception is that you can only develop, compile, and upload Arduino IoT Cloud Thing sketches using Arduino Cloud. That is false. You also have the option of doing any of those things using Arduino IDE.

It is most convenient to do the initial Thing setup in Arduino IoT Cloud (though you also have the option to do it locally via the Arduino Cloud CLI, but once you have set up your Thing, there is no requirement to continue using Arduino Cloud for working with the sketch.


Another thing to note is that there are other ways than the "ESP32Servo" and "ServoESP32" libraries to control a servo motor on the Nano ESP32 board from your sketch. I only mentioned the ESP32Servo library because it was a solution I found quickly while investigating your support request and found to be usable (unfortunately with the caveat I only discovered at the end of my investigation since I was using Arduino IDE).

It is possible there are other libraries, some of which might work.

Failing that, you could make the necessary modifications to the source code of either of those libraries and then import your custom version of the library via Arduino Web Editor.

Or you can also just add the necessary low level code directly to your sketch code. You can extract the code from either of those libraries.

I would guess so.

1 Like

Thanks for your precious time, ptillisch!
As you would guess, I'm a newbie so... :smiling_face:
Unfortunately, I need to use the IoT Cloud to control the servo remotely, without creating a new webserver, open a port into my router etc. (my ISP won't let me do that). I found also Blynk, which has similar capabilities, compared to IoT Cloud.
My next steps are going to be:

  • Looking for another library which doesn't require the change in pin enumeraton
  • Trying to use Blynk
  • Use an ESP8266

I'll let you know in the coming week!
Thanks a lot,
Vincenzo

As I already explained, the need to use Arduino IDE doesn't affect that in any way whatsoever.

If you don't want to use Arduino IDE for some other reason, that is perfectly fine, but if you are only avoiding doing it because you think it will require you to "create a new webserver" or "open a port into your router", etc. you are wrong.

I don't know how I can explain it to you any more clearly so I'll exit this conversation now. I can only suggest that you simply try uploading a working Arduino IoT Cloud Thing sketch (the "Cloud Blink" template is always a good simple demo) to your Arduino board using Arduino IDE, then prove to yourself that it works just the same as it would have if you had uploaded it to the board using Arduino Cloud.