LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to read array from serial port (Arduino) in Labview

Solved!
Go to solution

Hello, 

 

I'm using an Arduino Nano Every to collect six different values from thermocouples, the serial line is: 

17.38, 19.22, 18.30, 19.22, 19.22, 17.38
This is a simple VI for a bigger project, but the values at the output are 0 and i can´t understand why. 
 
 

 

0 Kudos
Message 1 of 7
(226 Views)

@Guilherme_Baptista1234 wrote:
This is a simple VI for a bigger project, but the values at the output are 0 and i can´t understand why. 

We cannot see your VI. I also recommend to give a bit more details.

0 Kudos
Message 2 of 7
(220 Views)

I'm sorry, i thought i had attached it.

Here it is. There's no more inf.ormation, I only want to read the numbers, separately in LabVIEW. 

This is what the arduino gives:

 

Serial.print(T[0]); Serial.print(", ");
    Serial.print(T[1]); Serial.print(", ");
    Serial.print(T[2]); Serial.print(", ");
    Serial.print(T[3]); Serial.print(", ");
    Serial.print(T[4]); Serial.print(", ");
    Serial.println(T[5]);
 
Thank you.

 

0 Kudos
Message 3 of 7
(216 Views)

There are a few things to consider. First off, you should watch this video:

 

https://www.youtube.com/watch?v=J8zw0sS6i1c

 

Your current structure is not going to work for what you're doing, as you don't know how many characters to read at a time; you'll get out of sync with your transmits and receives. (Short version: you need to learn how to use termchars).

 

Second, you need to figure out if the data is getting to your VI or not. What does "Read buffer" say? You said the outputs are all zeros; sounds like you have an empty string getting returned. Right now we can't tell if you have a problem with the serial side or the decoding side.

 

Third, your loop should exit on error, and you should display that error.

 

Fourth, you can actually use a single "array subset" function; it automatically indexes for you. But if you switch to using a termchar in LabVIEW, your VI will read out the whole string at once, and you can just call it a 1D array (wire a 1D double array to the "type" input on Spreadsheet String to Array). I'd also recommend just displaying the array, not splitting them out (it's easier to read).

 

Fifth, your code converts the string to a 2D array using the "delimiter (tab)" control, which is (in your example) an empty string. That should be a comma. (Right click and select "Make current value default).

 

Sixth, what Arduino board are you using? If it supports Serial.printf, that'll be easier to read and maintain in your code (IMHO). That would change your code to a single line:

 

Serial.printf("%f,%f,%f,%f,%f,%f\n",T[0],T[1],T[2],T[3],T[4],T[5]);

 

(forgive me for syntax errors, going from memory here)

0 Kudos
Message 4 of 7
(178 Views)

 

Second, you need to figure out if the data is getting to your VI or not. What does "Read buffer" say? You said the outputs are all zeros; sounds like you have an empty string getting returned. Right now we can't tell if you have a problem with the serial side or the decoding side.

 

Firstly, thank you for you reply.

 

My "Read Buffer" is also empty, the problem might be in the serial side.

I've seen the video you suggested, and thank you for that recommendation, but i only want to read the values in LabView. 

 

 

Sixth, what Arduino board are you using? If it supports Serial.printf, that'll be easier to read and maintain in your code (IMHO). That would change your code to a single line:

 

Serial.printf("%f,%f,%f,%f,%f,%f\n",T[0],T[1],T[2],T[3],T[4],T[5]);

 

(forgive me for syntax errors, going from memory here)


 I'm using an Arduino Nano Every, but i need the values separated because later I will use them to control heat resistors to maintain in a certain wanted temperature. 

 

Third, your loop should exit on error, and you should display that error.


It is not showing any error. 

Guilherme_Baptista1234_0-1767951475020.png

 

Currently, my VI is looking like this.

But the problem in the "serial side" maintains.

0 Kudos
Message 5 of 7
(132 Views)
Solution
Accepted by topic author Guilherme_Baptista1234

Thank you for your help, I found the problem. 

I had the Serial Monitor in arduino IDE open and it only can send information to one terminal at a time.

Thank you for your help!

0 Kudos
Message 6 of 7
(124 Views)

I'm glad you fixed it, but to clarify- when I said "Your loop should exit on error", I meant "You should modify your loop such that it exits on seeing an error". Right now, your loop keeps running indefinitely since you have a constant wired to Stop. If you wire the Error line to Stop, it'll stop the loop when it shows an error.

 

You've been getting errors this whole time without seeing them. With your loop set with a constant on Stop, you can only halt the loop using the Abort button. When you do that, the whole thing aborts immediately- it never calls the code outside the loop. In general you shouldn't ever use the Abort button for normal use- it's a debugging tool that can leave many things in an indeterminate state.

 

I'd recommend in your case adding a Stop boolean button on your front panel, then wiring that to an Or along with the Error line. Wire the output of the Or to the Stop? terminal in your loop. Then the loop will exit gracefully when either an error happens OR you click the Stop button on your front panel.

 

(Note... the big red button at the top of all LabVIEW windows is the Abort button, not a Stop button. There's a big difference!)

0 Kudos
Message 7 of 7
(81 Views)