Compile error when trying to use ESP32Servo library for UNO R4 WiFi

Please help a newbie and forgive my ignorance.

I have Uno R4 WiFi board which I need to use to control a linear actuator. Here is the board information returned by the IDE:

BN: Arduino UNO R4 WiFi
VID: 0x2341
PID: 0x1002
SN: 34B7DA637A40

I am following the Servo Guide at "DroneBot Workshop" and getting an error at the very first line of the example sketches in this guide. That line is:

#include "ESP32Servo.h"

The compile/verify error is:

In file included from /Users/Mohan/Documents/Arduino/libraries/ESP32Servo/src/ESP32Servo.h:84:0,
from /private/var/folders/8x/0wjsj3bn4pj_dc1lhdnm5m9w0000gn/T/.arduinoIDE-unsaved2026115-6424-11wdq99.rtge/sketch_feb15a/sketch_feb15a.ino:1:
/Users/Mohan/Documents/Arduino/libraries/ESP32Servo/src/ESP32PWM.h:28:10: fatal error: esp32-hal-ledc.h: No such file or directory
#include "esp32-hal-ledc.h"
^~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: exit status

I have been doing lot of independent research for the past 24 hours without any practical hint and ready to give up.

I would greatly appreciate any practical advice in getting past this issue.

The Uno R4 WiFi uses a Renesas RA4M1, not an ESP32. So that library cannot compile on it.
Just go with normal servo.h arduino library.

Posting a link to its datasheet will tell what stuff You’ve got.

Thanks. I can’t even compile something as simple as the following:

#include "ESP32Servo.h"

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

The linear actuator issues will happen after I am able to compile and start executing the code :grinning_face: .

In any case, I am using Actuonix P16-100-22-12-R linear actuator. The data sheet is available at:

Thanks again for your response.

Thanks for your reply.

I need to set custom min and max limits and the control signal period. These functions are not available in standard servo library as per the examples I read.

According to Arduino Uno R4 WiFi datasheet, ESP32-S3 is available as a co-processor, and the example usecases refer to including ESP32Servo.h in code.

Servo.h supports custom min/max.
servo.attach(pin, minPulse, maxPulse);
Do you really need custom signal period, if yes, what?

Yes. This is for a undergrad project. The Actuonix P16R allows one to vary the control signal frequency from 50–300Hz to reduce jitter. My understanding is one can use setPeriodHertz() function in ESP32Servo library for this purpose. I intended to use frequency of 250Hz (equivalent 4000 microsecond period).

Your sketch runs on the RA4M1, not the ESP32. @kmin gave you the answer in post #2.

Thanks for your reply. Being new to this, I don’t understand why all the servo examples for R4 mention this capability! Now the real question is, if I do need the functionality to control frequency of the control signal along with setting minimum and maximum pulse width at varius duty cycles, what is the right solution. Any help/recommendations are greatly appreciated.

So it should work then with servo.h
I already answered how to control min/max pulses.

You would be better off using an ESP32 based board instead of trying to use the ESP32 on the UNO R4 WiFi.

Thanks. As far as I can tell, it does not have setPeriodHertz() functionality. I justed checked the docs again.

Thanks. Back to the drawing board :cry:

It's fixed 50Hz but it has min/max pulse widths, all your actuator needs, so give it a try.

It's literally a one line change in the library to change the frequency. A few more lines if you want to add a function to make it programmable at runtime.

Thanks. I did lost of experimentation with min and max already using the standard servo library. It did not meet the requirements - this is why I researched and tried to use the esp32 library. In any case, it looks like that is not a meaningful route either. Thanks again.

Thank you for your extremely helpful reply.

Thanks you all for your replies.

I found an example of changing the control signal frequency using the Arduino Uno R4 (RA4M1 chip) with the built-in PwmOut class that allows you to specify a custom period or frequency. I will try it out and if it works, I will report back.

Only you know these "requirements".
According to the specs you linked, hard to believe it wouldn't run with standard servo.h.
With insufficient power supply different story though...

Thanks. I did not want to complicate the thread by providing details that were not relevant to my basic issue of compiling an example sketch. However, since you asked, here is the basic (again, very simplistic) description.

The experiment is about constructing a small scale wave tank to study effects of architectural choices in mitigating damage from waves in coastal areas. The tank has to simulate waves moving at, at least, 3 different speeds (slow, medium, fast) and, for each speed, 3 different amplitudes (low, normal, and high). Pretty much all parts are ready except for the actual instrumentation. The P16R, a linear actuator (with external 12V 1A power supply), drives a paddle to generate waves. The paddle stroke size (sweep angle) controls amplitude of the generated waves. How fast a wave moves is controlled by instrumenting 3 different duty cycles (10, 15, and 20%) with peak voltage fixed at 12V. From my novice understanding of how servos work, I can effect the duty cycles by controlling the pulse width. For example, at fixed control frequency of 250Hz, desired pulse widths are 400 (10%), 600 (15%), and 800 (20%) microseconds.

Hopefully, it makes sense now. It is my mistake. I thought these details were irrelevant to the basic problem. I am sorry.