Hi all,
I'm fairly early in the process of building a pan / tilt, 2 axis analog joystick controlled system, open-loop style with stepper motors for now (because I already have a couple beefy 1.8º steppers). I'm driving them with a couple of Big Easy Drivers from Sparkfun (Big Easy Driver - ROB-12859 - SparkFun Electronics) and Arduino Uno. My current issue is running both motors at the same time. One motor at a time is responding as expected with my mapping of the joystick values to use for microsecond delayed stepping of the motors via the Big Easy Drivers. However when both motors are engaged they act in unison, responding to the lowest speed value (highest step delay value) of either axis of the joystick; additionally, then running both motors at half the speed either motor would run solo at the same, mapped pot(joystick) value.
I have tried the following:
-reassigning output pins and physically distancing each of the motor control wires.
-separately feeding power to each of the stepper motors.
-and on that note: when supplying power to only one stepper motor (to it's driver), the problematic results persist,
leading me to believe it is a programing/coding issue.
-for now, I'm stepping in full steps, all microstepping yields the same relative results.
-moderate to thoroughly searched Arduino forums and google for this issue.
Thank You ahead of time for any help,
andrew
here is my code (not using libraries):
int stepPin1 = 5;
int dirPin1 = 6;
int M1_1 = 2;
int M1_2 = 3;
int M1_3 = 4;
int stepPin2 = 12;
int dirPin2 = 13;
int M2_1 = 9;
int M2_2 = 10;
int M2_3 = 11;
int pot1;
int pot2;
int panSpeed1;
int panSpeed2;
int tiltSpeed1;
int tiltSpeed2;
int minStepDly = 900; // was 5000 then 1500
int maxStepDly = 7000; // was 15000 then 16000
unsigned long currentMillis = 0;
unsigned long currentMillis2 = 0;
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
boolean flag;
void setup() {
pinMode(stepPin1, OUTPUT);
pinMode(dirPin1, OUTPUT);
pinMode(M1_1, OUTPUT);
pinMode(M1_2, OUTPUT);
pinMode(M1_3, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
pinMode(M2_1, OUTPUT);
pinMode(M2_2, OUTPUT);
pinMode(M2_3, OUTPUT);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
digitalWrite(M1_1, HIGH); // these are for microstepping the Big Easy Driver...
digitalWrite(M1_2, LOW);
digitalWrite(M1_3, LOW);
digitalWrite(M2_1, HIGH);
digitalWrite(M2_2, LOW);
digitalWrite(M2_3, LOW); // ... both set to full stepping for now
Serial.begin(9600);
}
void loop() {
currentMillis = millis();
currentMillis2 = millis();
if (currentMillis - previousMillis >= 20 && flag == true){
pot1 = analogRead(A0);
panSpeed1 = map(pot1, 544, 1023, maxStepDly, minStepDly);
panSpeed2 = map(pot1, 0, 480, minStepDly, maxStepDly);
previousMillis = currentMillis;
flag = false;
}
if (currentMillis - previousMillis >= 20 && flag == false){
pot2 = analogRead(A1);
tiltSpeed1 = map(pot2, 544, 1023, maxStepDly, minStepDly);
tiltSpeed2 = map(pot2, 0, 480, minStepDly, maxStepDly);
previousMillis = currentMillis;
flag = true;
}
//deBugging();
if (pot1 <= 480){
digitalWrite(dirPin1, HIGH);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(panSpeed2);
digitalWrite(stepPin1, LOW);
delayMicroseconds(panSpeed2);
}
if (pot1 >= 544){
digitalWrite(dirPin1, LOW);
digitalWrite(stepPin1, HIGH);
delayMicroseconds(panSpeed1);
digitalWrite(stepPin1, LOW);
delayMicroseconds(panSpeed1);
}
if (pot1 <= 544 && pot1 >= 480){
digitalWrite(stepPin1, LOW);
}
if (pot2 <= 480){
digitalWrite(dirPin2, LOW);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(tiltSpeed2);
digitalWrite(stepPin2, LOW);
delayMicroseconds(tiltSpeed2);
}
if (pot2 >= 544){
digitalWrite(dirPin2, HIGH);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(tiltSpeed1);
digitalWrite(stepPin2, LOW);
delayMicroseconds(tiltSpeed1);
}
if (pot2 <= 544 && pot2 >= 480){
digitalWrite(stepPin2, LOW);
}
}
void deBugging(){
if (currentMillis2 - previousMillis2 >= 500){
Serial.print("pot1= ");
Serial.print(pot1);
Serial.print("\t panSpeed1/panSpeed2= ");
Serial.print(panSpeed1);
Serial.print("/");
Serial.print(panSpeed2);
Serial.print("\t pot2= ");
Serial.print(pot2);
Serial.print("\t tiltSpeed1/tiltSpeed2= ");
Serial.print(tiltSpeed1);
Serial.print("/");
Serial.println(tiltSpeed2);
previousMillis2 = currentMillis2;
}
}