I am trying to control 2 stepper motors with a joystick. I started by trying to make two steppers turn together, but this was impossible. My motors come from the Elegoo starter kit, so it came with an example code. I ran it and it was working with one stepper, but not two. After checking 8 times the connections and trying to debug my code, I figured that the motor was not working if I placed it anywhere else than pins 8 through 11. When I place it anywhere else, it just vibrates but doesn't move. I have searched through an infinite amount of threads about this same subject but none were talking about placing the motor on specific pins nor any solution at all. I couldn't reply since the threads were closed so I decided to start a new thread and hope that someone help me.
Here's the code I am trying to run if it can help :
//www.elegoo.com
//2018.10.25
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
*/
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 15; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
// initialize the stepper library on pins 8 through 11:
Stepper X(stepsPerRevolution, 8, 10, 9, 11);
// initialize the stepper library on pins 2 through 5:
Stepper Y(stepsPerRevolution, 2, 3, 4, 5);
void setup() {
X.setSpeed(rolePerMinute);
Y.setSpeed(rolePerMinute);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
X.step(stepsPerRevolution);
Y.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
X.step(-stepsPerRevolution);
Y.step(-stepsPerRevolution);
delay(500);
}