Controlling a servo with ESP32-C3

kmaker
Posts: 2
Joined: Tue Feb 22, 2022 3:36 am

Controlling a servo with ESP32-C3

Postby kmaker » Tue Feb 22, 2022 3:47 am

Hi, I'm working on a project that uses ESP32-C3 (ESP32-C3-01M from Ai-thinker) to control a 9g servo. So far, I'm having no luck getting it to work. I've tried several servo libraries for ESP32, like esp32servo, and ledc based servoesp32, and none could make it work. I was able to see ledc control an LED on GPIO4 using ledc. While I see several mention of servo projects using ESP32-C3 on the internet, chip selector on Espressif shows ESP32-C3 to be not recommended for servo. I have been powering the servo with 5v power, and try to feed the PWM output directly into control pin. I know the servo is alive as it works with ESP8266 based setup i have.

I just wanted to find out if I'm on a path that's not going to succeed, or if there're other's who's been able to make it work... thanks!

kmaker
Posts: 2
Joined: Tue Feb 22, 2022 3:36 am

Re: Controlling a servo with ESP32-C3

Postby kmaker » Wed Feb 23, 2022 4:02 am

shortly after I posted, I had a small series of breakthrough. what i learned:
1. servo can be controlled by plugging in the control pin directly (I tried GIPO4 and GPIO2)
2. ledc can be initialized with different bid width and frequency, but it stops working if I set anything less than 200 for the frequency. ServoESP32 had 16 as bitwidth, but that didn't work and changing it to 8 worked.
3. since servo is controlled by pulses of width 1-2ms, i had to compute appropriate duty ratio value in 200hz

and after that it worked!

Who is online

Users browsing this forum: No registered users and 36 guests