Hii everyone, I wrote this code to control 2 stepper motors, only the first driver works. Although voltage goes to the 2nd drive but the motor does not drive. I think there is an error in the code. I'm adding it here too. I will be grateful if you could help me.
// 1.Step
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;
const int dirPin2 = 4;
const int stepPin2 = 5;
const int stepsPerRevolution2 = 180;
void setup()
{
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(dirPin2, OUTPUT);
}
void loop()
{
digitalWrite(dirPin, HIGH);
digitalWrite(dirPin2, HIGH);
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(2000);
}
delay(1000); // Wait a second
digitalWrite(dirPin, LOW);
digitalWrite(dirPin2, LOW);
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin2, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
digitalWrite(stepPin2, LOW);
delayMicroseconds(1000);
}
delay(1000); // Wait a second
}