Motor Shield: 2 motors at the same time

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Maximeh
 
Posts: 3
Joined: Wed Nov 10, 2010 12:44 pm

Motor Shield: 2 motors at the same time

Post by Maximeh »

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 !!!

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield: 2 motors at the same time

Post by adafruit_support_bill »

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); 
}

Maximeh
 
Posts: 3
Joined: Wed Nov 10, 2010 12:44 pm

Re: Motor Shield: 2 motors at the same time

Post by Maximeh »

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

User avatar
adafruit_support_bill
 
Posts: 88088
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Shield: 2 motors at the same time

Post by adafruit_support_bill »

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

Maximeh
 
Posts: 3
Joined: Wed Nov 10, 2010 12:44 pm

Re: Motor Shield: 2 motors at the same time

Post by Maximeh »

Great ! Thank you !
I'm going to look at this !

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”