LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send multiple different data from Labview to Arduino

Solved!
Go to solution

Hello Everyone!
I am making a Labview based software to control different loads. In this system i am using Arduino as a Micro controller. I am Facing a problem to send multiple data to arduino from labview, e.g, i want to send four different numeric values from different fields and then i want these values in arduino also stored in different variables. At a time i want to read data from arduino as well. In Short i want to send and receive multiple data from arduino to Labview and Labview to Arduino. Thanks in advance. Waiting for experts help.

 

0 Kudos
Message 1 of 7
(2,722 Views)

Hi Salman,

 

what have you tried and are you stuck?

What is a typical "value" to send from/to Arduino?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(2,719 Views)

Hi GerdW, First of all thanks for your reply. Basically i am dealing with PID library of arduino. My arduino code is working perfectly. In this code i change the values of P, I, and D. These values are stored in specific variables. The problem is this i want to set these variable values from Labview to Arduino. In short I am making a software to control PID values from the Labview to Arduino. I am using VISA Write Module in Labview to send data to Arduino. Please tell me how to receive these individual values from Labview and to store these values in arduino different variables. For example i create four different numeric control and i send data like 3 from first numeric, 6 from second, 10 from third and 12 from fourth and i want these values to store in different variables in arduino, like "int a=3"  "int b=6"  "int c=10"  "int d=12".

Best regards,

 

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

Write a string to the Arduino using the serial port like "3,6,10,12LF" where LF  is the linefeed character.  Then have the Arduino code to a readln on the serial port and break it down into 4 values based on the comma locations.

0 Kudos
Message 4 of 7
(2,672 Views)

RavensFan Thanks for reply. Actually i am almost new to Labview, that's why i am not understanding what are you telling me the solution. Can you please attach a example VI and Code end also.

 

0 Kudos
Message 5 of 7
(2,669 Views)
Solution
Accepted by topic author Engr_Salman

Presumably you are currently sending something to the Arduino using the VISA Write node you mentioned.

 

If this is working, you're probably using something like Serial.read to get single characters - and you can use code like the example here https://forum.arduino.cc/index.php?topic=288234.0 to get a "line" of characters by checking if the character that was read is equal to e.g. a line feed character.

 

Then, send your values to the Arduino with the last character each time (the termination character) being Line Feed constant.

On the Arduino, parse the string (char buffer) into tokens using something like strtok, then parse as needed.

Since you know the number of elements, you can probably write simple (but brittle) code by just assigning each block to a specific variable based on its position in the string (i.e. a = first token, b = second token, ...).


GCentral
0 Kudos
Message 6 of 7
(2,663 Views)

Cbutcher thanks for reply. Your providing information seems good. I will try your methods then I will discuss further here 🙂

0 Kudos
Message 7 of 7
(2,641 Views)