| File | Size | Hits |
|---|---|---|
LIFA_test_1.zip | 5.7 KiB | 432 |
LIFA_test_1.vi | 16.5 KiB | 422 |
LIFA_test_2.vi | 19.1 KiB | 425 |
LIFA_test_2.zip | 5.8 KiB | 529 |
METHOD 2: BYTE ARRAY
The approach described before is not that flexible as it assumes a fixed number of bytes is exchanged. Moreover data were sent encoded in ASCII and not as C data type implementation.
A more versatile approch would be send data to LabVIEW as sequence of bytes (binary). This would allow to send variable length data and reconstruct them inside LabVIEW, and require proper serialization functions in the firmware.
The following example show how to read a single precision float (4 bytes). A fifth byte is prepended and used as header for the transmitted data. LabVIEW wait for 5 bytes on the serial line, read the first of them and if it’s not equal to 0×69 flush the serial receive buffer and wait for the next packet. If the header is recognized the remaining 4 bytes are swapped to convert Arduino’s little-endian to LabVIEW big-endian format, then casted to a single precision float.
Hi Stefano: Please how did you modified the arduino LIFA sketch to send MCU memory variable to LABVIEW. Please show us an example.
Hi Nilo, you can find the sketches zipped in the downloads available at the top of the 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. Any further suggestion will be appreciated.
Cheers,
Ste
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
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″ “-12.34″(6bytes)
Serial.Println “1.23\r\n” (6bytes) “1.23\r\n”() “-12.34\r\n”(8bytes)
Serial.Write 1.23 (4bytes) 1.23456(4bytes) -12.34(4bytes)
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
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
Hi,
I’m fairly new to programming with labview, how would I go about it so I could reverse the process and send a variable from LV to the arduino at the same time?
Hi dude,
Great approach! But I go another approach. I use LIFA firmware and modified as follow:
case 0×08: // Read Analog Pin
readAn(command[2]);
// retVal = analogRead(command[2]);
// Serial.print( (retVal >> 8), BYTE);
// Serial.print( (retVal & 0xFF), BYTE);
Regards,
AungKL
hi,
i’m trying to do this, but always receive “SYNC” , could you help me, i’m using labview 2010.
hi,
i’m trying to do this, but always receive “SYNC” , could you help me please?, i’m using labview 2010.