RoboticsBrno / ServoESP32

⚙️ Generate RC servo signal on a selected pins with ESP32 device and Arduino framework.
MIT License
136 stars 32 forks source link

Added Support for ESP32-C3 #25

Open EinRainerZufall opened 1 year ago

EinRainerZufall commented 1 year ago

The changes were only tested on a XIAO-ESP32-C3. This should solve problem #20 .

After some testing I found out that ledc only work down to 200Hz on the ESP32-C3.

I have also added the solution @h2zero in #18 for the bit deep

mikaeltulldahl commented 1 year ago

Are there no way to support lower frequencies than 200 Hz on C3?

JarekParal commented 1 year ago

The library in v1.1.0 has a new parameter frequency which user can use in the attach(...) function and set it according to the ESP32 chip. Thank @mikaeltulldahl and his #23 PR.

Without that, we would need to add define for each new ESP32 chip, which is not such practical.

Now users can set the frequency like this:

Servo servo1;
const int servoPin = 4;
const int frequency = 200; // Hz

servo1.attach(
    servoPin, 
    Servo::CHANNEL_NOT_ATTACHED, 
    Servo::DEFAULT_MIN_ANGLE, 
    Servo::DEFAULT_MAX_ANGLE, 
    Servo::DEFAULT_MIN_PULSE_WIDTH_US, 
    Servo::DEFAULT_MAX_PULSE_WIDTH_US, 
    frequency
);

@EinRainerZufall Let me know if you are ok with this solution, and we can close this PR.