LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to run two stepper motors concurrently w/ Adafruit Motor Shield

Could someone please help me along a path to the solution of this question? I need to run two motors at the same time but the example program provides only one control, I have tried editing the example to no avail. Please help. Thanks.

0 Kudos
Message 1 of 16
(19,753 Views)

Have yiou seen this FAQ on Adafruit?

"I have two stepper motors and I want to run them simulaneously but the example code can only control one and then the other? 

The stepper motor library step() routine does not have the ability to run both motors at a time. Instead, you will have to 'interleave' the calls. For example, to have both motors step forward 100 times you must write code like this:

for (i=0; i<100; i++) {
motor1.step(1, FORWARD, SINGLE);
motor2.step(1, FORWARD, SINGLE);
}

No existing stepper motor driver has the ability to 'intelligently' interleave the steps. You will have to write a loop or use interrupts to control the motors the way you'd like. "

I hope you also saw that the LIFA stepper Motor VI is design to work with "Easy driver" or "Big Easy Driiver" type of stepper motor drivers.  The LIFA stepper motor VI will not work with the Adafruit motor shield.

It looks like you have two options. 

Option one.  Add code to the LIFA firmwarwe to enable an Arduino to use your Adafruit motor shield to drive 2 stepper motors and revise the LIFA stepper motor VI to mke it compatible with your modifications.  This option maybe a difficult if you don't have considerable programming experience.

Option 2  Initially don't use Labview.  Just use the information supplied by Adafruit to use your Ardruino board and the Adafruit motor shield to drive your 2 stepper motors.  When this step is completed create your own VI and use the Arduino's serial interface to control the Arduino.  Option 2 does not use the LIFA firmware.  In my opinion option 2 wil be easier to implement for a novice programmer.

PLease make liberal use of the following link.

<http://www.ladyada.net/make/mshield/index.html>

Howard

Message 2 of 16
(7,619 Views)

Thank you for the reply. I am able to drive the two motors concurrently with the arduino software. However, I do not even know where to begin in LabView. Would i just be able to output commands from labview directly onto the arduino board? Any avenue of help that you reveal to me will be much appreciated. Thank you.

0 Kudos
Message 3 of 16
(7,619 Views)

Also, the updated verison of LIFA does indeed have the capability to work with the Adafruit motor shield, it works with one motor, I cannot decipher on how to get it to work with two.

0 Kudos
Message 4 of 16
(7,619 Views)

Could you post the sketck or a ponter to the location of a copy of the sketch you are using to drive 2 step motors concurrently?    Your existing sketch will make a good starting point.

Howard

0 Kudos
Message 5 of 16
(7,619 Views)

#include <AccelStepper.h>

#include <AFMotor.h>

AF_Stepper motor1(200, 2);

AF_Stepper motor2(200, 1);

void forwardstep1() { 

  motor1.onestep(FORWARD, SINGLE);

}

void backwardstep1() { 

  motor1.onestep(BACKWARD, SINGLE);

}

void forwardstep2() { 

  motor2.onestep(FORWARD, SINGLE);

}

void backwardstep2() { 

  motor2.onestep(BACKWARD, SINGLE);

}

AccelStepper stepper1(forwardstep1, backwardstep1);

AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()

{

  Serial.begin(9600);

 

  int revs1, revs2, RPM1, RPM2;

//input revoultions(for motor1 and motor2) and RPMs below:

//for negative rotation enter a negative revolution

  revs1 = -2;

  revs2 = 1;

  RPM1 = 60;

  RPM2 = 60;

 

  stepper1.setMaxSpeed(1000);

  stepper2.setMaxSpeed(1000);

  stepper1.moveTo((revs1*200)-3);

  stepper1.setSpeed(RPM1 * 3.75);

  stepper2.moveTo((revs2*200)+3);

  stepper2.setSpeed(RPM2 * 3.75);

}

void loop()

{

  if ((stepper1.distanceToGo()) != 0)

  {

    stepper1.runSpeedToPosition();

  } 

  else{

    motor1.release();

  }

  if ((stepper2.distanceToGo()) != 0)

  {

    stepper2.runSpeedToPosition();

  } 

  else{

    motor2.release();

  }

}

0 Kudos
Message 6 of 16
(7,619 Views)

Thank you for posting the code.     I won't have much time to work on getting the code to work with Labview until this weekend.  Hence this is a heads up to let you know it will take 5 to 7 days before my revisions show up.

In the mean time eep plugging you may have break through.

Howard

Message 7 of 16
(7,619 Views)

Thank you, Howard. I appreciate all your help.

0 Kudos
Message 8 of 16
(7,619 Views)

Hey Howard,

Any progress on the code? Thanks for all your help.

0 Kudos
Message 9 of 16
(7,619 Views)

I have made very little progress and have not put in the time required to complete this task.  I will continue to wiork on this task however, I will not make an estimate of when my modification will be avaialble. 

I plan on using using some thing similar to the following to interleave the two steppers.  Look it over it may help you with your effort.

void loop()

{

  if( Serial.available() )

  {

     char ch = Serial.read();

     if ( ch >= '0' && <= '9' )

      steps = ch - '0';

     elseif (ch == '+' )

       steps = steps;

     elseif ( ch == '-' )

       steps = steps * - 1;

     elseif ( ch == 'A' )      // A is stepper 1

     {

       stepper1.step(steps);

       steps = 0;

     }

     elseif( ch == 'B' )        // B is stepper 2

    {

      stepper2.step(steps);

     steps = 0;

    }

  }

}

0 Kudos
Message 10 of 16
(7,619 Views)