LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems when plotting in Labview data from Arduino in real time. XY graph

Solved!
Go to solution

Hello, 

 

It is my first time working with Labview and I am having some problems when I try to plot data from Arduino. I have been using serial port communication and I am able to plot single variables on normal graph. The problem comes when I want to plot two variables using XY graph. In this case I want to plot volume on X axis and pressure on Y axis. These results come from Arduino as a string and then they are processed in Labview. The come with an initial letter which is the "identification" symbol for the string and a comma as the termination symbol. I don't know why my VI does only represent one point each time instead of a continuous graph as I have seen in other examples. It would be great if you could help me.

 

I add my VI and arduino files.

 

Thanks.

 

Lucas.

Download All
0 Kudos
Message 1 of 12
(3,790 Views)
Solution
Accepted by topic author Lucas_DF

First of all, your data protocol needs a little help.  At the end of your loop() part in the engine.cpp, you have a bunch of measurements being pumped out of the serial port with commas in the middle.  That is mostly good.  Where you went slightly astray is when writing the last value, you should use "Serial.println(t_gases_LabVIEW);" and not have the comma after it be written.  What this does is add a termination character to your message.  So now you are transmitting what we call a comma delimited line or spreadsheet string.  And as long as you promise to keep this same order, you don't need to add the "vol", "rc", etc. to your data stream.  In fact, you can simplify your whole ending (everything below your "TRANSFORMACION PARA LABVIEW" to this:

 

  Serial.print(pmedia*100);
  Serial.print(",");
  Serial.print(angulo);
  Serial.print(",");
  Serial.print(Vi);
  Serial.println(",");
  Serial.print(avance*10,0);
  Serial.print(",");
  Serial.print(Rc*10);
  Serial.print(",");
  Serial.print(avance1*10);
  Serial.print(",");
  Serial.print(porcentaje);
  Serial.print(",");
  Serial.print(avance2*10);
  Serial.print(",");
  Serial.print(ang_inyeccion*10);
  Serial.print(",");
  Serial.print(Vc*100);
  Serial.print(",");
  Serial.print(RPM);
  Serial.print(",");
  Serial.print(t_sal_ref);
  Serial.print(",");
  Serial.print(t_ent_ref);
  Serial.print(",");
  Serial.println(t_gases);
  delay(50);

 

 

About 1/2 the lines and variables.

 

Now on the LabVIEW side...DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis)

The reason is because we added the termination character to the last data write in the message.  So we can use that on the LabVIEW side to ensure we got a complete message.  Your initialization already has the termination character turned on and set to the Line Feed, which is what we need.  Now when you do your read, you just tell it to read more bytes than you ever expect in a message.  The read will stop when it finds the termination character, therefore ensuring you have a complete message.  Now for the data parsing, it gets even easier now.  You can just use the Spreadsheet String To Array to parse the data string and then Index Array to pull out the values you actually care about.



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 2 of 12
(3,778 Views)

First of all, thanks for your answer. I have done the changes you recommended me. These are:

- Change my VI in order to send the data to an array.

- Eliminate the Bytes at port block

- Change my Arduino on the part of  "TRANSFORMACION PARA LABVIEW"

 

However, I think  I am doing something wrong but I don't know what it is. I included the Index Array block and then I connected into a XY graph through a bundle block, but it does not plot the data. Another thing I don't understand very well is that when I choose the index value in order to select one of the measures, how do I know if the data is been stored in the rows or in the columns?

 

For example, in the VI I include in this message, the index array should be choosing the data in column 1 and column 2 (if the measures are in columns). Is that right?

 

By the way, I would like to know if it is better to use the ex build XY or the normal one.

 

Thanks a lot.

 

Lucas.

 

 

Download All
0 Kudos
Message 3 of 12
(3,731 Views)

@Lucas_DF wrote:

Another thing I don't understand very well is that when I choose the index value in order to select one of the measures, how do I know if the data is been stored in the rows or in the columns?


If you did your Spreadsheet String T Array properly (wire a 1D Array into the type instead of the default 2D), you will have only a row (no columns).

 

I am on my phone, so I can't look at your code at this time.



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
0 Kudos
Message 4 of 12
(3,718 Views)

The 2-D array of doubles should be a constant, not a control.

 

If you want column 0 and column 1, then you should wire the 0 and 1 into the column inputs, not the row inputs.

 

An XY graph will only show what you send to it.  It doesn't maintain a history like a Waveform Chart does.

 

You can drop a Build XY Graph Express VI from the front panel palette.  It will drop the XY graph along with an Express VI that builds the "chart" functionality, in other words history, into it so that over the 1000 iterations of the For Loop you'll see the accumulated data and not just the iteration by iteration data.  Perhaps that is what you want.

Message 5 of 12
(3,715 Views)

Hello,

 

Thanks for answering, I made some changes in my VI based in your last answer. I put indicators just to see what is receiving the express build XY, and it seems to be the numbers I want. It represents  the points I am sending, but it doesn't represent the accumulated data yet. I share a picture of what I am referring to:

Lucas_DF_0-1589186458091.png

As you see, it only represents the last point that arrives to the express XY graph, instead of representing also the ones which were sent before. If you could help me to solve this, it would be great.

 

On the other hand, I have change my Arduino code into a simpler one just to make these tests. I include in this message both, the VI and the Arduino code.

 

Thanks.

 

Lucas.

Download All
0 Kudos
Message 6 of 12
(3,689 Views)

Hi Lucas,

 


@Lucas_DF wrote:

As you see, it only represents the last point that arrives to the express XY graph, instead of representing also the ones which were sent before. If you could help me to solve this, it would be great.


Read the help for this ExpressVI: it offers just one setting in its properties -  and you have choosen the wrong option…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 12
(3,680 Views)

Finally got around to looking at your new VI...

 

1. You don't need the Wait in the loop.  The VISA Read will limit the loop rate as it waits for the termination character to be read.

2. The Index Array is expandable and it automatically increments the index for each dragged element.  And the first one defaults to index 0.

3. As GerdW stated, your Build XY Graph is currently set up to "Clear data on each call".  Turn that off.

4. You might want to turn your error cluster tunnels into a shift register.  This way your errors will propagate through all remaining iterations and you will detect it.



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 8 of 12
(3,662 Views)

Yes!!

Finally I was able to make it. 

Thanks a lot. Not just for the plot issue you could solve me, but also for the improvement of the arduino code and the simplification of the VI file . Now I will be able to plot every data I receive from an engine I'm working on.

 

I add the final program, just in case someone needs it.👍

 

Thanks.

Lucas.

Download All
0 Kudos
Message 9 of 12
(3,655 Views)

Hi Lucas,

 

some improvements/cleanup:

 

You should also:

  • use better (more descriptive) labels for controls/indicators
  • use a shift register to hold references (like the VISA reference)
  • use more comments in your code, like subdiagram labels…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 12
(3,647 Views)