06-20-2024 05:55 AM
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
Solved! Go to Solution.
06-20-2024 07:14 AM
@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.
06-20-2024 07:59 AM
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
06-20-2024 09:12 AM
While Loop with an Event Structure. This allows you to react to the button presses without polling.
06-20-2024 09:46 AM
Thank you, I will try this!
06-20-2024 12:02 PM - edited 06-20-2024 12:03 PM
In general there are three ways of using LabVIEW with an Arduino
06-21-2024 03:30 AM
Thank you! I am following the first route and by the sounds of it I should stick with it!
06-24-2024 10:50 AM
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.
06-24-2024 12:19 PM
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.