I'm using arduino connected to a sabertooth 2x12 RC driver thats connected to 2 DC motors, each motor are connected to a lithium battery.
I control the motors using servo library and each time it completes a sweeping loop that I ran, the motor rotates to a opposite direction for some reason that I cannot figure out, also another problem that I have is when I try to only turn the left motor(channel 1), the right motor(channel 2) also moves at a very slow speed, sometimes it doesn't. I've played around with the DIP switch on the RC motor driver but it didn't solve the problem
any help is appreciated
heres the code part with everything I've tried
#include <Servo.h>
Servo ST1, ST2;
int pos = 0;
void setup(){
ST1.attach(5, 1000, 2000);
ST2.attach(6, 1000, 2000);
}
void loop(){
//turnLeft();
//delay(100);
turnRight();
//delay(100);
//forward();
//delay(100);
//backward();
//delay(100);
//doNothing();
//forward and backward
/*
for (pos = 0; pos < 180; pos += 1){
ST1.write(pos);
ST2.write(pos);
delay(15);
}
delay(1000);
for (pos = 180; pos > 1; pos -= 1){
ST1.write(pos);
ST2.write(pos);
delay(15);
}
delay(1000);
/
/
//left and right
for (pos = 0; pos < 180; pos += 1){
ST1.write(pos);
delay(15);
}
delay(1000);
/*
for (pos = 0; pos < 180; pos += 1){
ST2.write(pos);
delay(15);
}
delay(1000);
*/
}
void doNothing(){
while(1){
ST1.detach();
ST2.detach();
}
}
void turnLeft(){
ST1.attach(5, 1000, 2000);
for (pos = 0; pos < 180; pos += 1){
ST1.write(pos);
delay(20);
}
delay(1000);
ST1.detach();
}
void turnRight(){
ST2.attach(6, 1000, 2000);
for (pos = 0; pos < 180; pos += 1){
ST2.write(pos);
delay(20);
}
delay(1000);
ST2.detach();
}
void forward(){
ST1.attach(5, 1000, 2000);
ST2.attach(6, 1000, 2000);
for (pos = 0; pos < 180; pos += 1){
ST1.write(pos);
ST2.write(pos);
delay(20);
}
delay(1000);
ST1.detach();
ST2.detach();
}
void backward(){
ST1.attach(5, 1000, 2000);
ST2.attach(6, 1000, 2000);
for (pos = 180; pos > 1; pos -= 1){
ST1.write(pos);
ST2.write(pos);
delay(10);
}
delay(1000);
ST1.detach();
ST2.detach();
}