ESP32-C3 Running A Servo

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gotapi
 
Posts: 6
Joined: Wed Feb 12, 2020 3:43 pm

ESP32-C3 Running A Servo

Post by gotapi »

Hello,

I am trying to have the QT PY ESP32-C3 run a servo. I've read how the standard Arduino Servo.h library does not support ESP32 and have tried other recommended libraries such as ESP32Servo.h and ServoESP32 with no luck. I am using the AO pin(GPIO #4).

Has anyone had any luck, experience, or suggestions?

Thanks,
Travis

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: ESP32-C3 Running A Servo

Post by adafruit_support_mike »

Starting from the basics, servo control signals are typically between 1ms and 2ms wide, and arrive at about 20Hz. The width of the pulse controls the position of the servo.. 1ms being all the way to one side, and 2ms being all the way to the other side. A 1.5ms pulse should center the servo.

Those are general values, and if you want accuracy you'll need to test the center and limit values.

Servo libraries often try to generate the pulses with one of the clock peripherals, but many times that isn't necessary. You can bit-bang perfectly good signals by counting microseconds. For a device with a 240MHz CPU clock like the ESP32, you should be able to get 1us resolution without too much trouble.

If you can afford to let the code block for 1ms-to-2ms, generating pulses is easy. If not, use the BlinkWithoutDelay technique and store the time value of the next event in a global variable, then check the time each pass through loop():

https://docs.arduino.cc/built-in-exampl ... thoutDelay

User avatar
gotapi
 
Posts: 6
Joined: Wed Feb 12, 2020 3:43 pm

Re: ESP32-C3 Running A Servo

Post by gotapi »

Thanks Mike,

I was able to get the servo to run with your advice! Much appreciated!

Travis

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”