madhephaestus / ESP32Servo

Arduino-compatible servo library for the ESP32
138 stars 53 forks source link

3 or more servos gets crazy #19

Closed RadekVoltr closed 3 years ago

RadekVoltr commented 3 years ago

With following code :

`// create four servo objects Servo servo1; Servo servo2; Servo servo3; // Published values for SG90 servos; adjust if needed int minUs = 1000; int maxUs = 2000;

int servo1Pin = 21; int servo2Pin = 22; int servo3Pin = 23;

void setup() {

    ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
servo1.setPeriodHertz(50);      // Standard 50hz servo
servo2.setPeriodHertz(50);      // Standard 50hz servo
servo3.setPeriodHertz(50);      // Standard 50hz servo

servo1.attach(servo1Pin, minUs, maxUs);
servo2.attach(servo2Pin, minUs, maxUs);
servo3.attach(servo3Pin, minUs, maxUs);

servo1.writeMicroseconds(1200); delay(1); servo2.writeMicroseconds(1200); delay(1); servo3.writeMicroseconds(1200); delay(1);

delay(10000);

servo1.writeMicroseconds(1500); delay(1); servo2.writeMicroseconds(1500); delay(1); servo3.writeMicroseconds(1500); delay(1);

delay(10000);

//servo1.writeMicroseconds(1800); delay(1); servo2.writeMicroseconds(1800); delay(1); servo3.writeMicroseconds(1800); delay(1);

delay(10000);` servo gets crazy. I can use 2 of them. Doesn't matter which ones but after I send 3rd request, it push servo to one side and ignore other changes including stop.

ESP32 Wroom32 Dev Kit compile with Platform.io, library from their storage

RadekVoltr commented 3 years ago

ok, it looks that problem is in case that 3 servos have same frequency. Servo 3 is then set to channel 8. Some how it gets workarrounded by using different frequency so 3rd servo goes to channel number 2 but then I get strange pulse each 1s.

servo1.setPeriodHertz(50);      // Standard 50hz servo
servo2.setPeriodHertz(50);      // Standard 50hz servo
servo3.setPeriodHertz(49);      // Standard 50hz servo
madhephaestus commented 3 years ago

hmm, i use this library with 16 independant servos regularly. can you link to a whole project i can run and try it?

RadekVoltr commented 3 years ago

Ok, I will investigate it on my end first and let you know.

RadekVoltr commented 3 years ago

Omg, I am idiot.

Using external power source for servos and forgot to connect ground during development. For some reason it was able work on 2 servos and not on more. I am very , very sorry.

madhephaestus commented 3 years ago

no worries :) Happy roboting!