Hello,
I've just bought an arduino and a motor shield from adafruit. I'm totally new in arduino and quite new in programming. With these stuffs, I want to drive two stepper motors.
Thanks to all the information on adafruit website, it works great.
Now, I would like my two motors to spin at the same time. So, I would like these two functions to be exucuted at the time:
motor.step(100, BACKWARD, SINGLE);
motor2.step(100, FORWARD, SINGLE);
Is it possible ?
Is it parallel programming ?
Thank you for your help !!!
Motor Shield: 2 motors at the same time
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield: 2 motors at the same time
The AFMotor library does not support asynchronous stepper commands. To do this you would need something like:
Code: Select all
for(int i = 0; i < 100; i++)
{
motor.step(1, BACKWARD, SINGLE);
motor2.step(1, FORWARD, SINGLE);
}
-
- Posts: 3
- Joined: Wed Nov 10, 2010 12:44 pm
Re: Motor Shield: 2 motors at the same time
Thank you very much for the answer !
But I would like that in a same duration, the two motors turn at different speed, with different number of steps ... I have to think about it ...
But I would like that in a same duration, the two motors turn at different speed, with different number of steps ... I have to think about it ...
- adafruit_support_bill
- Posts: 88088
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor Shield: 2 motors at the same time
It's a little trickier, but not too difficult. You just have to figure out how to divide up the steps proportionally.
If you want to be as linear as possible, there is an algorithm by Bresenham that can be adapted. If you are interested, take a look: http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
If you want to be as linear as possible, there is an algorithm by Bresenham that can be adapted. If you are interested, take a look: http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
-
- Posts: 3
- Joined: Wed Nov 10, 2010 12:44 pm
Re: Motor Shield: 2 motors at the same time
Great ! Thank you !
I'm going to look at this !
I'm going to look at this !
Please be positive and constructive with your questions and comments.