Go Down

Topic: Need help with stepper motors (Read 157 times)previous topic - next topic

jjk226

Apr 10, 2015, 06:33 am
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( == 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:

1. Adjusting the code to program two actuators simultaneously.

2. 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.

3. Sometimes the motor stalls and vibrates at the start, is this most likely a power issue?

Robin2

#1
Apr 10, 2015, 09:24 am
Have a look at this simple stepper code and at stepper motor basics.

You have not told us what power supply (volts and amps) you are using nor what current the stepper motors require. And have you the current limit on the BigEasydriver correctly set?

If you want to move two motors at the same time it is easiest if you make the code to move a motor one step into a function. Then you can write code like this pseudo code

Code: [Select]
`void loop() {   if (timeForMotorA) {      stepMotorA();   }   if (timeForMotorB) {      stepMotorB();  }}`
...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy