LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Controlling stepper motor with Arduino

Hi,

I am trying to control a stepper motor via labVIEW and an arduino micro. I have a VI which takes in speed (IPM), distance (In), I want to travel based on threads per inch of my threaded rod and how many step/rev my stepper motor has. The problem is that when I wire the high low signal to my step pin on my arduino it gives me an error saying that my types do not match, but I have converted the boolean "true/high" "false/low" to 0 or 1 then converted the to a unsigned 8-bit int from 0-255 which is what it says it wants. But then it still says there is a miss match.

So I have a move button which goes to a case structure then with in that case structure is a for loop which N is fed the number of steps, and then within the for loop is a flat sequence structure which makes the step pin on the arduino high for X ms and then low for X ms using a wait ms command (which im not sure is what I want to use it doesn't seem to keep very good time). Is there a better way to do this? If not how do I get this way to work properly.

I've attached my vi below. Thanks alot.

0 Kudos
Message 1 of 9
(11,279 Views)

What stepper driver are you using to interface Arduno to a stepper?  I am still in the stage of trying to understand your VI.  Hence knowing the IC you are using for a stepper driver will be big help.

Howard

0 Kudos
Message 2 of 9
(5,079 Views)

Howard,

It looks like Rymanrw is using the EasyDriver Stepper Motor Driver . His pins corespond to the  pins on the card and allows for the microsteps up to 8.

I beleive that  Rymanrw needs to include the Enable pin too. The  main chip on the EasyDriver board is the Allegro 3967 Microstepping Driver with Translator.

The board is available from SparkFun ...

Cheers,

Steve

0 Kudos
Message 3 of 9
(5,079 Views)

Sorry Howard I thought I replied the other day with my phone but I guess the post did go through. Steve is correct I will probably be using the Big Easy Driver from sparkfun or a comprable one from Polou. Here is a link http://www.sparkfun.com/products/10735. Yes I did forget about the enable pin, good catch. Thanks alot for the help.

0 Kudos
Message 4 of 9
(5,079 Views)

Hi Rymanv & Howard,

After thinking about your original problem it may make sense to let the arduino do the actual stepping since there is some latancy in the communication between LabView and the arduino. sending the steps as a bit bang method since  you have to do packets  of 15 bytes for each step. What if you were to pass the number of steps to the arduino and let it  run at its speed and then send back a completion move bit or flag  to tell LabView its ready for the next move?

Cheers,

Steve

0 Kudos
Message 5 of 9
(5,079 Views)

I had this concern as well but I wasn't sure how to implement it. Can I modify the LIFA sketch that I upload to the arduino to incorrporate that function? And how would I do that?

0 Kudos
Message 6 of 9
(5,079 Views)

Yes you could modify the LIFA sketch to incorporate functions to drive a stepper motor.  The first thing you would need to do if you wanted to modify the LIFA sketch is to study the LIFA sketch and the LIFA Packets documents to see how the existing commands work.  The code ID for the existing commnds start at 0X00 and increase from there.  Sam recommended if you wanted to add a function to the LIFA sketch, the code ID for the function start at 0XFF and decrese from there.

I see in the other thread on stepper motors National Instruments is working on adding stepper motor functionality to the LIFA sketch.  So if you modified the LIFA sketch to add stepper motor functionality it might be a dupliocation of effort. 

An alternate method wlould be to not use the LIFA and insteaduse the Arduino programming environment to write code to run on an Arduino board to drive a stepper motor and use Labview in a terminal emulation mode to communicate with an Arduio board. There is code in the Arduino Library to drive a stepper using a SN754410NE.  See <https://decibel.ni.com/content/docs/DOC-4731> for a terminal emulation VI.

Howard.

0 Kudos
Message 7 of 9
(5,079 Views)

I have seen that thread about NI adding stepper motor sunctionality to the LIFA sketch but it seems to be taking a very long time and I don't have that much time to waste. I also need a custom gui that is much more complex than the who in my current vi I am just working on all the pieces and then I will combine them once I have each component working properly. Thanks for the help I will either add my own function to the LIFA sketch or find another alternative.

0 Kudos
Message 8 of 9
(5,079 Views)

A small amount of progress in eliminating the bugs in your stepper VI program. The following is a corrected version of the formula node code used for calculating microstep size.

int mcstep;

if ( Res == 0 )

{

  MS1 = 0;

  MS2 = 0;

  mcstep = 1;

}

else if( Res == 1 )

{

  MS1 = 1;

  MS2 = 0;

  mcstep = 2;

}

else if( Res == 2 )

{

  MS1 = 0;

  MS2 = 1;

  mcstep = 4;

}

else if( Res == 3 )

{

  MS1 = 1;

  MS2 = 1;

  mcstep = 8;

}

1.  Labview kept complaing when the Full, Half, Quarter and Eight step sizes were used in the code.  They were changed to their numeric values of 0, 1, 2, and 3.

2.  An if statement is written as "if (Res == 0)"  not "if(Res) == 0".

3.  Don't declare a variable in a formula node if it is decared else where.   When you connect a Numeric Control to the Res input RES automatically becomes a declared variable.

4. The statements following the if and else if statements need to be a compound statement and require brackets, "{, }".

5.  C uses "else if" as a keyword, not "elseif".

7.  The variable mcstep must be declared in the formula node.

Howard

0 Kudos
Message 9 of 9
(5,079 Views)