LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

LIFA Serial

Attached is a VI set for Serial communication using an Arduino.  It utilizes serial port 1 and was tested with an Arduino DUE (pins 18 & 19) but should work with any of the Arduinos with multiple UARTs such as the Mega.

The attached text file is the addition to the firmware that will need to be added.  Lastly the Command.ctl will add the appropriate command enums.

Download All
Message 1 of 35
(14,877 Views)

is it possible for u to explain the "command" functions, if i wanted to create som more so i could get an understanding ?

0 Kudos
Message 2 of 35
(6,211 Views)

I'm not entirely sure what you mean by command functions.  To clarify, the arduino LIFA firmware allows for commands to be sent from the PC to the board (via serial interface / usb).  These commands are processed by a case statement to determine which command is sent, and then the code specific to that command is run on the board itself.  The 4 "commands" I included in the text file are Initialize Serial which simply starts the serial communication on the UART1 (pins 18/19) on my board.  Send serial data sends out bytes of data.  Read serial data queries the amount of available bytes, sends that amount first back to the pc (so the pc knows how many bytes to expect) and then sends the actual bytes of data).  End serial just closes the UART serial interface.

As far as the Labview VIs go, I included 5.  Serial Init starts serial communication with the specified baud rate.  Serial close closes the same. Serial write breaks the input into 10 byte chunks and sends out serial write commands as mentioned earlier until all of in input data has been sent.  Serial read reads the amount of available bytes, and then reads that many bytes from the device.  The only one that is vaguely ambigious is the Serial Find Regex, this VI reads all imcoming serial data until a Regular Expression match is found or the timeout is hit, then lets you know which was the case and includes the matching string (if matched).

I hope this sufficiently answers your question, let me know if you have any further questions.

Message 3 of 35
(6,211 Views)

makes some sense, but how do you figure out the command function in the arduino code, why use command 2 and not command 4 etc

but im gonna try out your program to use my ID12

0 Kudos
Message 4 of 35
(6,211 Views)

I think what you mean is the command array in the Arduino code where you see "command[2]" etc.  The way the command array works is that it is a 15 byte array sent to the board.  The first byte (command[0]) is always 0xFF.  The second byte  (command[1]) dictates which command you are sending.  command[2] through command[13] are the data payload and vary depending on how the command is implemented in the arduino firmware.  command[14] is the checksum and is the modulus of all previous bytes summed divided by 256..

command[14] = (sum(command[0]... command[13]) % 256)

Let me know if I was unclear.

Message 5 of 35
(6,211 Views)

That helped me alot ! thanks mate, now it makes more sense

0 Kudos
Message 6 of 35
(6,211 Views)

Do you have a VI as reference ? cause it seems to me that it only works half the times, but i guess its my LabVIEW programming thats done wrong.

0 Kudos
Message 7 of 35
(6,211 Views)

I have attached a Serial Example that will do a read and/or write.

Let me know if you have any problems.

Message 8 of 35
(6,211 Views)

Thank you for the Example, i have now been working all day with this project of mine.

My conclusion:

It works very good, except for 1 thing.. when using the Serial Read then it has to be inside of the Serial Read Vi, it reads the data and not outside that took me some time to figure out when i could push some data to LabVIEW

But it helped me alot

0 Kudos
Message 9 of 35
(6,211 Views)

Incoming data is buffered and the Serial Read VI reads that buffer, I'm not sure of the size of that buffer but you'll lose data if it runs long enough without a read.  For my purposes I send a write, then send a read and check for expected response (usually with the read regex).

0 Kudos
Message 10 of 35
(6,211 Views)