Hello!!
I am trying to control 4 servos at the same time. The program I wrote is pretty basic but I can't seem to get my head around the results I'm seeing.
I'm just trying to input a change in position (in microseconds) in the serial monitor and have all four servos move to their new position at the same time.
I was initially using no delays between servo.writes but they were all out of order and really funky looking. I started adding small delays and eventually settled on a 15ms delay between writes. This eliminated the lag between the servo position changes!
I don't understand why this is happening as I've never had this problem before.
For reference, I am using these servos https://flightcomp.com/products/bms-207wv-mini-digital-high-torque-high-speed-coreless and I am running them at 7.4 volts 1A max. I am using the teensy 3.2.
Any help would be appreciated!!
I am trying to control 4 servos at the same time. The program I wrote is pretty basic but I can't seem to get my head around the results I'm seeing.
I'm just trying to input a change in position (in microseconds) in the serial monitor and have all four servos move to their new position at the same time.
I was initially using no delays between servo.writes but they were all out of order and really funky looking. I started adding small delays and eventually settled on a 15ms delay between writes. This eliminated the lag between the servo position changes!
I don't understand why this is happening as I've never had this problem before.
For reference, I am using these servos https://flightcomp.com/products/bms-207wv-mini-digital-high-torque-high-speed-coreless and I am running them at 7.4 volts 1A max. I am using the teensy 3.2.
Any help would be appreciated!!
Code:
#include <Servo.h>
Servo s1;
Servo s2;
Servo s3;
Servo s4;
int s1Pin = 21;
int s2Pin = 20;
int s3Pin = 23;
int s4Pin = 22;
int s1Start = 1520;
int s2Start = 1400;
int s3Start = 1520;
int s4Start = 1520;
int s1Pos;
int s2Pos;
int s3Pos;
int s4Pos;
int sDelay = 15;
void setup() {
Serial.begin(115200);
s1.attach(s1Pin);
s2.attach(s2Pin);
s3.attach(s3Pin);
s4.attach(s4Pin);
s1.writeMicroseconds(s1Start); // Move servo to the intermediate position (30 deg) instead of it moving on its own to its neutral position of 1500 us
s2.writeMicroseconds(s2Start);
s3.writeMicroseconds(s3Start);
s4.writeMicroseconds(s4Start);
delay(1000);
}
void loop() {
if (Serial.available()) {
int val = Serial.parseInt();
s1Pos = s1Start + val;
s2Pos = s2Start + val;
s3Pos = s3Start + val;
s4Pos = s4Start + val;
// delay(1000);
s1.writeMicroseconds(s1Pos);
delay(sDelay);
s2.writeMicroseconds(s2Pos);
delay(sDelay);
s3.writeMicroseconds(s3Pos);
delay(sDelay);
s4.writeMicroseconds(s4Pos);
// delay(1000);
Serial.println(val);
}
}