LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino ADXL325 through COM port

Solved!
Go to solution

Hello,
I have a project with an Arduino and accelerometer ADXL325.
Arduino has the code to process the accelerometer data. I am connecting the Arduino to my PC via Silicon Labs CP2102 and with the use of RealTerm receive the output. My last task is to get this output using the LabView environment. I have tried already different schemes with VISA, but every single one failed. It was supposed to be easy, but I need some guidance.
Thanks in advance 🙂

0 Kudos
Message 1 of 16
(4,203 Views)

LabVIEW to Arduino is serial communication.

 

Arduino resets when serial  port is first opened. You must alllow for that in your code.

 

And post your VI.

 

And do you have working code on the Arduino ?  I would like to see that.

0 Kudos
Message 2 of 16
(4,167 Views)

I have a working code that is written with the usage of avr-gcc, programmer USBasp. I am not using the Arduino IDE. I do not have any saved VI's, I have tried something similar to this one:

p17ukc1li4f1j1c1j1qiq1qus1qf05.png

0 Kudos
Message 3 of 16
(4,132 Views)

What baud rate are you opening the port on the Arduino?

 

Use "VISA Configure Serial Port.vi" instead of open port to match up the serial settings (baud, data bits, stop bit, parity) and use a termination character (<CR> and/or <LF> are somewhat standard.) 

 

In your LabVIEW code don't use bytes at port. Just set a termination character with the "VISA Configure Serial Port" and a timeout that you think is reasonable. VISA read will just read data until it sees the termination character or times  out. (This will also throttle your loop which in your example is running as fast as it can while usually doing nothing.)

0 Kudos
Message 4 of 16
(4,118 Views)

Whether he needs to use termination character(s) depends on how he wrote his Arduino code.

 

0 Kudos
Message 5 of 16
(4,100 Views)

The problem with reading "bytes at port" is that there is no guarantee that you are getting a complete message. You might just be reading in the middle of a message being sent. Using a termination character makes sure you get a full message before you read the data. It's generally better to just set the bytes to read as something larger than you ever expect to get and use a term. char.

0 Kudos
Message 6 of 16
(4,082 Views)

Hope the OP is paying attention. 😛

0 Kudos
Message 7 of 16
(4,064 Views)

Currently, the baud rate is set to 57600. 
My output in RealTerm looks as follows in the picture. How can I read it properly in LabView?

I need only these numbers, shall I convert string to number somehow or any other advice?

2.PNG

1.PNG

  

0 Kudos
Message 8 of 16
(3,850 Views)
Solution
Accepted by topic author michcie

You don't wire termination character into bytes to Read!  If your termination character is 10 (the default meaning Line Feed), you'll only get the first 10 bytes.

Then another read, another 10 bytes, and another read, unless you happen to have a line feed character in which the final read will be the last part of the line.   Your total message is 36 bytes long which means it would take 3 reads of 10, and a final read of 6.

 

Wire a number larger than your longest message into the VISA Read.  Try 100.  Then when you read it, you will get a full message.  You can get rid of the termination character property node.

 

Once you have the full message, look at Scan from String with a format string of  angle_xz=%.3fdgangle_yz%.3f and you should be able to get the two values as actual numerics rather than strings.  You may need to play with that format string some.  Having all of those characters jammed together could interfere with the string parsing.  It would be better if you did something simpler with the arduino so it just output the values as comma separated and did not output the string parts.

0 Kudos
Message 9 of 16
(3,766 Views)
Solution
Accepted by topic author michcie

It looks like that data you are getting is terminated with <CR><LF>. Get rid of the property node with "TermChar". Feeding that into "byte count" doesn't make any sense. Just set the "byte count" to something larger than you expect to see. With the "Configure Serial Port" set to use a termination character and the character set to 10 <LF> VISA read will read until it sees that character.

 

To get the the numbers use "scan from string" on the read buffer.

 

Annotation 2020-01-04 102458.png

Annotation 2020-01-04 102032.png

 

 

0 Kudos
Message 10 of 16
(3,763 Views)