I'm currently working on my senior project which requires programming several stepper motors/actuators. I currently have a Haydon Kerk BGS linear rail hooked up to a Big EasyDriver that's programmed with arduino mega 2560 (stacked with Pololu Dual VNH5019 motor driver shield). Here's a basic code that I'm currently using:
int Distance = 0; // Record the number of steps we've taken
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, HIGH);
delayMicroseconds(25);
digitalWrite(9, LOW);
delayMicroseconds(25);
Distance = Distance + 1; // record this step
// Check to see if we are at the end of our move
if (Distance == 28800)
{
// We are! Reverse direction (invert DIR signal)
if (digitalRead(8) == LOW)
{
digitalWrite(8, HIGH);
}
else
{
digitalWrite(8, LOW);
}
// Reset our distance back to zero since we're
// starting a new move
Distance = 0;
// Now pause for half a second
delay(1000);
}
}
It's basically taken from a tutorial I found online from Schmaulzhaus and makes the motor go back and forth.
Here are some areas I need help with:
-
Adjusting the code to program two actuators simultaneously.
-
How would I adjust the distance that the motor travels after each iteration. Or, in other words, how would I make the motor travel a further distance than the last? The motor currently moves back and forth in a fixed direction, but I want to be able to make it travel further every time it goes back and forth.
-
Sometimes the motor stalls and vibrates at the start, is this most likely a power issue?