So I'm trying to make a motorized dobsonian telescope using two NEMA 17 motors with Easy Driver boards. I want to control the x and y axis with a joystick. I found a code that ran one with a joystick and I tried to modify it by copying the loop and adding the y-axis. Well only the X-axis moves and it only turns CCW.
Can someone run over this and see if they see the issue that I can't? Thank you
/*This program is designed to control two nema 17 boards with easy driver board with a joystick on a Nano.
My specific use is to control the X and Y axis of a homemade telescope
considered open source, feel free to do whatever with it.
*/
#define step_pinX 3 // Pin 3 connected to Steps pin on EasyDriver X-AXIS
#define dir_pinX 2 // Pin 2 connected to Direction pin X-AXIS
#define MS1X 5 // Pin 5 connected to MS1 pin X-AXIS
#define MS2X 4 // Pin 4 connected to MS2 pin X-AXIS
#define SLEEPX 6 // Pin 6 connected to SLEEP pin X-AXIS
#define step_pinY 7 // Pin 7 connected to Steps pin on EasyDriver Y-AXIS
#define dir_pinY 8 // Pin 8 connected to Direction pin Y-AXIS
#define MS1Y 9 // Pin 9 connected to MS1 pin Y-AXIS
#define MS2Y 10 // Pin 10 connected to MS2 pin Y-AXIS
#define SLEEPY 11 // Pin 11 connected to SLEEP pin Y-AXIS
#define XPin A0 // Pin A0 connected to joystick x axis x-AXIS
#define YPin A1 // Pin A1 connected to joystick y axis Y-AXIS
#define JoySwitch 12 // Pin 12 connected to joystick button
#define Limit01 22 // Pin 22 connected to limit switch
#define Limit02 23 // Pin 23 connected to limit switch
int stepSpeed = 10; // speed of stepper motor
void setup() {
pinMode(MS1X, OUTPUT);
pinMode(MS2X, OUTPUT);
pinMode(dir_pinX, OUTPUT);
pinMode(step_pinX, OUTPUT);
pinMode(SLEEPX, OUTPUT);
pinMode(MS1Y, OUTPUT);
pinMode(MS2Y, OUTPUT);
pinMode(dir_pinY, OUTPUT);
pinMode(step_pinY, OUTPUT);
pinMode(SLEEPY, OUTPUT);
pinMode(Limit01, INPUT);
pinMode(Limit02, INPUT);
pinMode(JoySwitch,INPUT_PULLUP);
digitalWrite(SLEEPX, HIGH); // Wake up EasyDriver
delay(5); // Wait for EasyDriver wake up
digitalWrite(SLEEPY, HIGH); // Wake up EasyDriver
delay(5); // Wait for EasyDriver wake up
/* Configure type of Steps on EasyDriver:
// MS1X MS2X MS1Y MS2Y
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/
digitalWrite(MS1X, LOW); // Configures to Full Steps
digitalWrite(MS2X, LOW); // Configures to Full Steps
digitalWrite(MS1Y, LOW); // Configures to Full Steps
digitalWrite(MS2Y, LOW); // Configures to Full Steps
}
void loop() {
if (!digitalRead(JoySwitch)) { // Check joystick switch position
delay(500); // delay for debouncing
switch (stepSpeed) { // Check current value of step_speed and change it
case 1:
stepSpeed=10; // slow speed
break;
case 3:
stepSpeed=1; // fast speed
break;
case 10:
stepSpeed=3; // medium speed
break;
}
}
if (analogRead(XPin)> 712){ //if joystick is moved left
if (!digitalRead(Limit01)) {} // check is limit switch is activated
else { // if limit switch is not activated, move motor clockwise
digitalWrite(dir_pinX, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pinX, HIGH);
delay(stepSpeed);
digitalWrite(step_pinX, LOW);
delay(stepSpeed);
}
}
if (analogRead(XPin) < 312){ //if joystick is moved left
if (!digitalRead(Limit02)) {} // check is limit switch is activated
else { // if limit switch is not activated, move motor clockwise
digitalWrite(dir_pinX, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pinX, HIGH);
delay(stepSpeed);
digitalWrite(step_pinX, LOW);
delay(stepSpeed);
}
}
if (analogRead(YPin)> 712){ //if joystick is moved left
if (!digitalRead(Limit01)) {} // check is limit switch is activated
else { // if limit switch is not activated, move motor clockwise
digitalWrite(dir_pinY, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pinY, HIGH);
delay(stepSpeed);
digitalWrite(step_pinY, LOW);
delay(stepSpeed);
}
}
if (analogRead(YPin) < 312){ //if joystick is moved left
if (!digitalRead(Limit02)) {} // check is limit switch is activated
else { // if limit switch is not activated, move motor clockwise
digitalWrite(dir_pinY, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(step_pinY, HIGH);
delay(stepSpeed);
digitalWrite(step_pinY, LOW);
delay(stepSpeed);
}
}