From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to specify what data to read from arduino

Solved!
Go to solution

I have two thermometers, A and B, attached to my arduino uno and I need to read the current temperature from both of them. Initially I had them writing constantly but it became difficult to know for sure which I was reading from. Additionally, I occasionally encountered wildly inaccurate data due to race conditions. I tried to solve both of these problems by placing the serial print statements behind if statements.

 

command = (byte)Serial.read();
if(command == 'S') Serial.println(Ta); //return A temp
if(command == 'O') Serial.println(Tb); //return B temp

This works fine in the serial monitor but I can't seem to write to it from LabView. When I try to read from the arduino after writing either "S" or "O", labview errors out saying that "timeout expired before operation completed". I'm really not sure what I'm missing here but I'm sure I've overlooked something simple. Any insight on the matter would be appreciated. Thanks for your time.

0 Kudos
Message 1 of 8
(2,340 Views)

Please attach a VI using Save for Previous Version back to LV 18 or older.

 

LV 2019 just came out a month ago.  Not everyone is using it yet!

0 Kudos
Message 2 of 8
(2,338 Views)

Thanks for the quick response, here's the 2018 version.

 

(Edit: Just in case I've still not given you the right version I'll attach an image)

Download All
0 Kudos
Message 3 of 8
(2,331 Views)
Solution
Accepted by topic author JacobDickens

No error cluster? I haven't ever met a programmer so good they don't need to wire up the error clusters...

 

Anyway you are doing it wrong. Search the board for "Bytes at Port" (but don't use bytes at port) and you will find several serial examples that show the right way to do serial communications.

 

But do you really need to query the Arduino for the values?

  1. Consider just having the Arduino constantly send both temperatures in one line separated by a comma.
  2. Then use LabVIEW to receive and separate the two by looking for the comma.

 

========================
=== Engineer Ambiguously ===
========================
Message 4 of 8
(2,303 Views)

Separating the values with a comma works beautifully. Thank you!

GetArduinoTemp.PNG

0 Kudos
Message 5 of 8
(2,295 Views)

I would have done something like this:

s2s.PNG

This was for receiving three values (g,h,j) from an Arduino separated by commas.

========================
=== Engineer Ambiguously ===
========================
Message 6 of 8
(2,292 Views)
Solution
Accepted by topic author JacobDickens

@RTSLVU wrote:

I would have done something like this:

s2s.PNG

This was for receiving three values (g,h,j) from an Arduino separated by commas.


Spreadsheet String To Array would be the route I would go.  It would allow for any number of parameters.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 8
(2,248 Views)

That also works quite nicely, thank you.

GetTemp2.PNG

0 Kudos
Message 8 of 8
(2,235 Views)