LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

sending variables from Arduino to LabVIEW

Hi,

I would like to share with you my experiment with LabVIEW + Arduino.

I wrote a "minimal" (but can be expanded for sure ) protocol to send values stored in memory on the MCU. This is probably old news but I learned a lot doing it and maybe can be useful to someone else.

Here is the link

http://www.stefanocottafavi.com/?p=412

Cheers,

Stefano

0 Kudos
Message 1 of 6
(9,901 Views)

Hi Stefano: How did you modified the arduino LiFA sketch to send internal MCU variables to Labview?. Please show us an examples ketch.

Regards.

NiloHdez

0 Kudos
Message 2 of 6
(4,675 Views)

Hi Nilo, you can find the sketches zipped in the downloads available at the top of the linked page. Please note that no major changes has been done to the LIFA code, only the “Serial.write” in the main loop have been added for these examples to work. Hope this help

Cheers,

Ste

0 Kudos
Message 3 of 6
(4,675 Views)

Hello.

I managed to get your VI to work with my program. I'm sending my variable (data from one axis of my accelerometer) as a string via serial.println. It only works with your second VI (LIFA_test_2), when I convert buffer data straight from Send Receive block to number and then plot it. Otherwise I get 0 all the time. Thing is, when it plots as I said before, it is very fluent with values from -200 to -1 and 10 to 200 (integers only), but for values 0 to 9 it gets significantly slower. What would you recommend to look at in order to improve it? I set "Bytes to read" to 4 (best results so far).

I uploaded my VI in case you wanted to look at it

Would very much appreciate an advice, cheers!

The file:

http://www.sendspace.com/file/sbarfo

0 Kudos
Message 4 of 6
(4,675 Views)

Hi Adam,

first thing to pay attention to is how many bytes we send and receive (you can read previous statement as "LIFA need to know how many bytes has to wait for!" ). We have two way to send data from Arduino: 1) Serial.print(ln) or 2) Serial.write the second one being more low level than the first one.

With 1) data will be sent as human-readable ASCII text (and as per the following links with sort of default truncation) while with 2) the data are sent as bytes.

For example to send following Arduino float numbers :

                         1.23                        1.23456               -12.34

Serial.Print         "1.23" (4bytes)         "1.23"(4bytes)      "-12.34"(6bytes)  

Serial.Println      "1.23\r\n" (6bytes)     "1.23\r\n"(6bytes) "-12.34\r\n"(8bytes)

Serial.Write        1.23 (4bytes)           1.23456(4bytes)    -12.34(4bytes)

Please note that in human-readable ASCII minus sign count for 1byte, also decimal point count for 1byte. Moreover with println always send two more character (1byte each) carriage return and newline.

The only function that guarantee a constant number of bytes, 4 in case of single precision float, is "write" and for me this is the way to go!

The LIFA_test_2 show exactly how to send one float (4bytes) over the serial line + a simple header (1byte) : total 5 bytes, always!!!

Of course that example can be modified to send multiple data / different types at the same time...

http://www.arduino.cc/en/Serial/Print

http://www.arduino.cc/en/Serial/Println

http://www.arduino.cc/en/Serial/Write

Cheers,

ste

0 Kudos
Message 5 of 6
(4,675 Views)

Hello Stefano!

It works indeed :)  I can now send one variable form Arduino to Labview without any lag.

You said that the code can may be modified to send multiple data (variables) at the same time. How can it be done? Is it about adding cases in Labview with different headers and respectively serial.write commands with their names and variable names in Arduino code?

Cheers,

Adam

Message 6 of 6
(4,675 Views)