Hi There, i am working on building rc car using esp32 and xbox controller, i am able to connect the controller to the board, but somehow the servo which i am using is mg90s and it doesnt work with it, no matter what different library i use, can someone help me in that?
How is the servo powered ?
I think you need to read the pinned post re 'How to get the most from the forum'
Sharing code, circuit , power and details about components usually goes a long way in getting meaningful input.
Some time ago I worked with an MG996r which is a somewhat weaker but similar servo motor. The following code may help you get started (setting right frequency and duty cycle). Try changing these parameters.
// Suppose MG996R is driven by PWM on PIN 12
void setup()
{
Serial.begin (115200);
/* older libraries:
seledcSetup (0, 50, 10); // set 50 Hz PWM on channel 0 with 10 bit resolution
ledcAttachPin (12, 0); // attach pin 12 to channel 0
*/
ledcAttach (12, 50, 10); // set 50 Hz PWM on pin 12 with 10 bit resolution
}
void loop() {
Serial.printf ("center at %i\n", 75);
/* older libraries:
ledcWrite (0, 75);
*/
ledcWrite (12, 75);
delay (4000);
for (int dutyCycle = 75; dutyCycle <= 128; dutyCycle++){
Serial.printf ("right %i\n", dutyCycle);
/* older libraries:
ledcWrite (0, dutyCycle);
*/
ledcWrite (12, dutyCycle);
delay (25);
}
delay (2000);
for (int dutyCycle = 128; dutyCycle >= 22; dutyCycle--){
Serial.printf ("left %i\n", dutyCycle);
/* older libraries:
ledcWrite (0, dutyCycle);
*/
ledcWrite (12, dutyCycle);
delay (25);
}
delay (2000);
for (int dutyCycle = 22; dutyCycle <= 75; dutyCycle++){
Serial.printf ("right %i\n", dutyCycle);
/* older libraries:
ledcWrite (0, dutyCycle);
*/
ledcWrite (12, dutyCycle);
delay (25);
}
}
…which library is that one ???
for ESP32 I use the library ESP32Servo and it works great
No library. Pure PWM.
Try a different pin, pin12 is a strapping pin.
Leo