Hello, I am having difficulty using a Joystick to control 2 1.5A NEMA 17 Bipolar Stepper Motors. I am driving it with a A4988 from HiLetgo. The program is an edited version of code created by https://www.brainy-bits.com/post/control-a-stepper-motor-using-a-joystick-and-an-arduino. The functionality I am aiming for is when I move left and right one of the steppers move, and when I move up and down the other stepper moves. This is to simulate movement in the X and Y direction. When clicking on the button on the Joystick, the speed increases. This works when I am at the slowest speed, but when I increase the speed I notice a difference in that both steppers move slower in one direction than another. This is especially true for the stepper motor controlling what's supposed to be the Y direction as pushing down on the joystick the speed stays at the slowest no matter which speed I currently am in. Attached are photos of my setup and the code used. Also the actual voltage in my circuit is a 12v multivariable power supply I just have a 9v battery there since I couldn't find a power supply like mine on fritzing.
//https://www.brainy-bits.com/post/arduino-nema-stepper-control-with-joystick-and-limit-switches CODE CREDIT
#define stepx = 14; // Pin 14 connected to the step pin in the x direction
#define dir_x = 32; // Pin 32 connected to direction pin in the x direction
#define stepy = 27; //Pin 27 connected to the step pin in the y direction
#define dir_y = 33; //Pin 33 connected to the direction pin in the y direction
#define sw = 15; // Pin 15 connected to joystick switch
int step_speed = 10; // Speed of Stepper motor (higher = slower)
void setup() {
pinMode(dir_x, OUTPUT);
pinMode(stepx, OUTPUT);
pinMode(dir_y, OUTPUT);
pinMode(stepy, OUTPUT);
pinMode(sw, INPUT_PULLUP);
}
void loop() {
if (!digitalRead(sw)) { // If Joystick switch is clicked
delay(500); // delay for deboucing
switch (step_speed) { // check current value of step_speed and change it
case 1:
step_speed=10; // slow speed
break;
case 3:
step_speed=1; // fast speed
break;
case 10:
step_speed=3; // medium speed
break;
}
}
int X_pin = analogRead(26);
int Y_pin = analogRead(25);
int val = map(X, 0, 4096, 0, 100);
int val2 = map(Y, 0, 4096, 0, 100);
if (val > 75) { // If joystick is moved RIGHT
digitalWrite(dir_x, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(stepx, HIGH);
delay(step_speed);
digitalWrite(stepx, LOW);
delay(step_speed);
}
if (val < 25) { // If joystick is moved LEFT
digitalWrite(dir_x, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(stepx, HIGH);
delay(step_speed);
digitalWrite(stepx, LOW);
delay(step_speed);
}
if (val2 > 150) { // If joystick is moved UP
digitalWrite(dir_y, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(stepy, HIGH);
delay(step_speed);
digitalWrite(stepy, LOW);
delay(step_speed);
}
if (val2 < 50) { // If joystick is moved DOWN
digitalWrite(dir_y, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(stepy, HIGH);
delay(step_speed);
digitalWrite(stepy, LOW);
delay(step_speed);
}
}

