I am new to Arduino. I am trying to run two stepper motors NEMA 17 through respective A4988 driver and controlling via Arduino Uno.
The thought is that first stepper motor will carry out a first horizontal scan and then as it reaches to its initial position, second stepper motor will move a single step in vertical direction. This is a kind of raster scan that I want to perform with both motors.
When I am running the code, only horizontal scan motor is running and vertical scan motor is not moving. I have checked my circuit, motors and drivers and everything is working fine. I think there is some mistake in my code. It is a basic level code and I would really appreciate the help for helping me out.
int x, y; //stepper motor 'x' and stepper motor 'y'
#define BAUD (9600)
void setup()
{
Serial.begin(BAUD);
pinMode(6,OUTPUT); // Enable for x
pinMode(5,OUTPUT); // Step for x
pinMode(4,OUTPUT); // Dir for x
digitalWrite(6,LOW); // Set Enable low for x
pinMode(9,OUTPUT); // Enable for y
pinMode(8,OUTPUT); // Step for y
pinMode(7,OUTPUT); // Dir for y
digitalWrite(9,LOW); // Set Enable low for y
}
void loop()
{
digitalWrite(9,LOW); // Set Enable low for y
for(y = 0; y < 20; y++)
{
digitalWrite(6,LOW); // Set Enable low for x
digitalWrite(4,HIGH); // Set Dir high for x - Clockwise
Serial.println("CLOCKWISE HORIZONTAL SCANNING IN PROGRESS");
for(x = 0; x < 50; x++) // Loop 50 times
{
digitalWrite(5,HIGH); // Output high for x
delay(10); // Wait
digitalWrite(5,LOW); // Output low for x
delay(100); // Wait
}
digitalWrite(6,LOW); // Set Enable low for x
digitalWrite(4,LOW); // Set Dir low for x - Anticlockwise
Serial.println("ANTICLOCKWISE HORIZONTAL SCANNING IN PROGRESS");
for(x = 0; x < 50; x++) // Loop 50 times
{
digitalWrite(5,HIGH); // Output high
delay(10); // Wait
digitalWrite(5,LOW); // Output low
delay(100); // Wait
}
Serial.println("ONE STEP CLIMB ON VERTCAL AXIS");
digitalWrite(7,HIGH); // Set Dir high for y
digitalWrite(8,HIGH); // Output high for y
delay(100); // Wait
digitalWrite(8,LOW); // Output low for y
delay(100); // Wait
}
digitalWrite(9,LOW); // Set Enable low for y
digitalWrite(7,LOW); // Set Dir low for y
Serial.println("RESETTING ON VERTCAL AXIS");
for(y = 0; y < 20; y++) // Loop 20 times
{
digitalWrite(8,HIGH); // Output high for y
delay(10); // Wait
digitalWrite(8,LOW); // Output low for y
delay(100); // Wait
}
}
Do i need to look after the delay being provided??