LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending Commands to Arduino from LabVIEW

Solved!
Go to solution

Hello all,

 

I have been delivered a motor controller that is arduino-based, but that I did not make. With it I have been given a list of commands to control the motor, for example:

 

"forward.x" - runs the motor forward by x steps
"stop" - stops the motor

 

and similar.

 

My task is to create an interface to control the motor in LabVIEW. I need to be able to create a button that I can press on the LabVIEW interface that will deliver a certain command to the arduino to trigger the corresponding action, i.e., a "FORWARD" button that will deliver the command "forward.1".

 

However, I am having difficulty understanding how I can deliver such a command to the arduino via LabVIEW. There are plenty of examples online for controlling individual pins, for reading/writing data and so on, but not for delivering commands to an already-installed sketch on the board. Is it just a case of a serial write of the command to the board?

 

If anyone has any idea where to start, I would really appreciate your help. Many thanks, Sam

Samuel Allen
University of St Andrews
0 Kudos
Message 1 of 9
(593 Views)
Solution
Accepted by topic author smallen

@smallen wrote:

Is it just a case of a serial write of the command to the board?


Yes.  The Arduino shows up as a COM port to the PC and all you have to do is use that with VISA.  Depending on how the sketch is written, you may also have to append a Line Feed (\n) to your command so the Arduino knows when a command has ended.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 9
(570 Views)

Thank you! I will try with and without /n.

 

I was wondering, I have around ten commands or so and I want to implement them using buttons - what is the most efficient way to do this? I guess probably using a case structure where the case is selected by the button and each case contains the relevant string, which it then passes to the VISA write block?

 

Thanks once again

Samuel Allen
University of St Andrews
0 Kudos
Message 3 of 9
(550 Views)

While Loop with an Event Structure.  This allows you to react to the button presses without polling.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 9
(538 Views)

Thank you, I will try this!

Samuel Allen
University of St Andrews
0 Kudos
Message 5 of 9
(532 Views)
Solution
Accepted by topic author smallen

In general there are three ways of using LabVIEW with an Arduino

 

  1. Program the Arduino in the native Arduino language.
    1. LabVIEW can communicate with an Arduino using VISA just like any other instrument on a serial port.
    2. IMHO: This is the best way as you have full control over the communications protocol and you can use any of the of Arduino libraries and LabVIEW toolkits that are already out there.
    3. I highly recommend watching this video on serial communications: VIWeek 2020/Proper way to communicate over serial
  2. Use LINX (Hobbyist Toolkit or whatever they are calling it now)
    1. Full LabVIEW integration, but limited amount of Arduino libraries and peripherals directly supported
    2. The Arduino basically becomes a tethered DAQ device that needs to be connected to a computer/LabVIEW to work
  3. TSXperts Arduino compiler for LabVIEW
    1. Actually turns LabVIEW into compiled Arduino code. (A real feat on its own)
      1. Limited subset of LabVIEW vi's and primitives
      2. Very limited support for Arduino libraries 
      3. Development seems to have stopped, so those annoying bugs are here to stay
========================
=== Engineer Ambiguously ===
========================
Message 6 of 9
(509 Views)

Thank you! I am following the first route and by the sounds of it I should stick with it!

Samuel Allen
University of St Andrews
0 Kudos
Message 7 of 9
(497 Views)

I have here an example of how I have tried to implement the serial communication with the arduino based on the first approach.

 

From the IDE, if I open serial monitor with the arduino connected and type "reset", I get the desired effect (I reset the counter on the screen). Therefore, there is nothing wrong on the arduino side of things.

 

Please find attached a VI that, from what I understand, should do the same thing as typing the command in the serial monitor, but using a button in labview. When I press "OK" on this VI, I think it should send the command "reset", but the arduino actually does nothing at all.

 

Am I doing something wrong within the VI?

 

Many thanks in advance for any help you can offer.

Samuel Allen
University of St Andrews
0 Kudos
Message 8 of 9
(461 Views)

I cleaned up your VI.  Your main issue is your command string constant.  It is set to "Normal" display and you tried to add in an escape sequence.  It does not work that way.  You need to change the display style to "\ Codes" and make the display style visible.  When you do this, you will see the string change to "reset\\n".  The "\\" means a single slash character, which is what you were really sending.  Remove one of the slash characters so that you have "reset\n" and now the "\n" is the Line Feed that you need.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 9
(445 Views)