Here is a simple guide to get your stepper motors spinning. The video below demos what I made. You can see how everything is set up below that:
const int stepperX_pul = 0;
const int stepperX_dir = 1;
const int stepperY_pul = 2;
const int stepperY_dir = 3;
int microstep_count = 0;
void setup()
{
// Set up the x axis
pinMode(stepperX_pul, OUTPUT);
pinMode(stepperX_dir, OUTPUT);
// Set up the y axis
pinMode(stepperY_pul, OUTPUT);
pinMode(stepperY_dir, OUTPUT);
// initialize the pulse pins
digitalWrite(stepperX_pul, HIGH);
digitalWrite(stepperY_pul, HIGH);
// initialize the direction pins
digitalWrite(stepperX_dir, HIGH);
digitalWrite(stepperY_dir, HIGH);
}
void loop()
{
digitalWrite(stepperX_pul, HIGH);
digitalWrite(stepperY_pul, HIGH);
delayMicroseconds(100);
digitalWrite(stepperY_pul, LOW);
digitalWrite(stepperX_pul, LOW);
delayMicroseconds(100);
// Once we make a full revolution,
// make the motor spin the other direction
if(microstep_count >= 3200)
{
digitalWrite(stepperX_dir, !digitalRead(stepperX_dir)); // Change direction.
digitalWrite(stepperY_dir, !digitalRead(stepperY_dir)); // Change direction.
delay(100);
microstep_count = 0;
}
else
microstep_count++;
}