LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Arduino interface to control stepper motor

Solved!
Go to solution

Hi! I'm doing this project where I have to control a stepper motor to move in both directions using LabVIEW as the control panel and an arduino board connected to a stepper motor driver controling a nema 17 motor. I tried using the built in LabVIEW functions for controling the motor with arduino, but it was too slow and I could only move the motor at slow speeds. Now I'm using VISA and the communication works, but unfortunatly, there are a lot of mistakes in the communication. In the control panel I have one numeric controller that is converted into a string, sent to arduino and arduino will then give the orders to the motor. However, When I select a value for the speed, after a few seconds the value changes. For example, I select 7 and it changes to 77. I send 7* to arduino so that it knows what to read and where to stop, but it just ignores that and changes it to 77 or something like that. Could you please help me? I am thinking about replacing the stepper motor to a servo motor too, in case you think this is a more viable option.

0 Kudos
Message 1 of 7
(3,634 Views)

You should attach a .zip file not .rar.

 

Most people won't have the 3rd party software needed too "unrar" that file and won't bother going to get it.

 

Zip is preferable since file handling for that is already built into Windows.

0 Kudos
Message 2 of 7
(3,593 Views)

Here it is, in case it helps.

0 Kudos
Message 3 of 7
(3,565 Views)

Check out crossrulz viweek presentation. Tim does a very good job explaining serial comms done properly

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 4 of 7
(3,556 Views)
Solution
Accepted by topic author mqs1998

The attached LabVIEW code uses the linefeed (\n) termination character to delimit responses.

It takes about 170 ms to read the 8 (nine first time) messages returned from the Arduino.

If you could limit this to just one message it would be faster (see note in code).

 

For the Arduino code (not an expert - just about a week of experience):

1) In setup() -  Serial.setTimeout(20); // Instead of the default 1000ms may speed up some functions 

2) "readString" may be slower than reading characters with serial.read() - based on documentation of

    serial String functions, not on actual proof.

3) As mentioned, just return the parsed data in one message to speed things up

 

steve

 

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
0 Kudos
Message 5 of 7
(3,527 Views)

Steve,

 

It's perfect! Thank you so much! It worked perfectly. Thank you!

0 Kudos
Message 6 of 7
(3,504 Views)

Hi @mqs1998,

 

I was curious how fast Arduino could communicate with LabVIEW so I modified the previous vi

and created some Arduino code.

 

The attached code lets you send a command (or loop sending commands) to the Arduino.

The Arduino parses the data and returns a count of the characters sent.

This operation takes, on average, less than 5 ms (low of <3, high of ~8).

The baud rate is set to 115,200. At 9600 baud, the same code takes about 25 ms.

 

So it is possible to send 2 ints, a float, and a string, have them parsed by the Arduino,

and get an acknowledgement - all in about 5 ms. And this can be done continuously.

 

In the Speed Test vi you can change the last character in the command. 

* returns the command character count

# returns the parsed data from Arduino - this takes a couple extra ms

_ An empty string simulates a bad command - a timeout feature catches this

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 7
(3,473 Views)