LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LABVIEW and ARDUINO Realtime Analog Reading, Displaying and Data logging via Serial/VISA

Solved!
Go to solution

Hi everyone.

 

I am attempting preform real-time data logging using Labview and the Arduini Portenta.

 

I am attempting this analog writing  All 7 readings from Arduino (0-255 range) to the serial monito in the Arduino IDE, written in a CSV format/fashion.

 

Capture1.JPG

 

I would then use Labview VISA to read the analog channel, and splitting the reading into an array, showing all 7 analog readings in real time.

 

Capture.JPG

Then writing the readings to a textfile, as well as displaying the readings on a Gauge - all occuring in a single loop.

 

Capture2.JPG

 

Issues.

1. So the loop can run at 20KHz  when using the Arduino Portenta, but the issue is every 40 loops or so, it seems to reset in some way, where the reading dials show zero, then show the correct reading again - the faster I run the loop, the more frequent the UI flickers, making the readings hard to see in real time.

2. I need to figure out a way to log dates and time as well, into the text file next to each reading. for every loop.

3. I have avoided express VI for data logging because they slow down the loop. I have placed a timer to delay the loop for debugging purposes, but the loop can run at 20Khz.

 

Feel free to help me out here, maybe I am missing something.

0 Kudos
Message 1 of 11
(3,888 Views)
Solution
Accepted by topic author Kulani93

@Kulani93  a écrit :

 

Issues.

1. So the loop can run at 20KHz  when using the Arduino Portenta, but the issue is every 40 loops or so, it seems to reset in some way, where the reading dials show zero, then show the correct reading again - the faster I run the loop, the more frequent the UI flickers, making the readings hard to see in real time.

2. I need to figure out a way to log dates and time as well, into the text file next to each reading. for every loop.

3. I have avoided express VI for data logging because they slow down the loop. I have placed a timer to delay the loop for debugging purposes, but the loop can run at 20Khz.

 

Feel free to help me out here, maybe I am missing something.


1 : Do you really need that frequency to show the values in real time? You can filter the outputs, in that way if you read zero you keep the old values.

2 : You can use and convert the time from the LabVIEW function 

time.png

3 : Again, do you need to go that fast ? By the way you have no timer delay when you are going to 20 KHz?

Message 2 of 11
(3,878 Views)
Solution
Accepted by topic author Kulani93

DO NOT USE BYTES AT PORT!

 

I'll come back to that. I think you have some timing issues if I understand correctly what is going on. It looks like the Arduino is streaming those numbers, the rate to me is unknown. If you want to read streaming data like that, set the timeout on the VISA configure port to some value that you should not hit in normal circumstances (5 seconds maybe). Let the VISA read determine the rate of your loop, IE get rid of the wait. And DO NOT USE BYTES AT PORT. If you can control how those numbers are sent, use a termination character (carriage return or line feed are pretty common). The Arduino language Serial.println() will send both. Set the termination character to the last symbol (linefeed 0x10) and the byte to read on the VISA read to something larger than you will ever see in normal communication. The VISA read function will read until it sees the newline character, or it times out.

 

My guess is right now your wait in the loop is causing the serial buffer to fill up and you are reading stale data until the buffer is full and then something resets. If you need to control the rate from the PC/LabVIEW side of things either change your communication schema to be a query-response type, or you still need to read the data on the buffer and just discard what you don't want to use. This assumes that the LabVIEW loop runs faster than the data is being streamed. If it isn't then you might still have this same problem but it might not show up as often, but you could still be reading stale data.

Message 3 of 11
(3,862 Views)

DON"T USE "BYTES AT PORT"

 

Watch this video on how to properly program serial communications.

 

VIWeek 2020/Proper way to communicate over serial

 

 

 

========================
=== Engineer Ambiguously ===
========================
Message 4 of 11
(3,839 Views)

@Defaphe wrote:

@Kulani93  a écrit :

 

Issues.

1. So the loop can run at 20KHz  when using the Arduino Portenta, but the issue is every 40 loops or so, it seems to reset in some way, where the reading dials show zero, then show the correct reading again - the faster I run the loop, the more frequent the UI flickers, making the readings hard to see in real time.

2. I need to figure out a way to log dates and time as well, into the text file next to each reading. for every loop.

3. I have avoided express VI for data logging because they slow down the loop. I have placed a timer to delay the loop for debugging purposes, but the loop can run at 20Khz.

 

Feel free to help me out here, maybe I am missing something.


1 : Do you really need that frequency to show the values in real time? You can filter the outputs, in that way if you read zero you keep the old values.

2 : You can use and convert the time from the LabVIEW function 

time.png

3 : Again, do you need to go that fast ? By the way you have no timer delay when you are going to 20 KHz?


 

1. I am aiming for the loop to run at 1kHz.

2. Thank you a lot for the real-time stamp.

3. The time delay is just for debugging purposes, I won't use it, I will use a scheduler on the Arduino Portenta, then something else clever to loop at 1kHz... Still not sure what.

 

0 Kudos
Message 5 of 11
(3,809 Views)

@StevenD wrote:

DO NOT USE BYTES AT PORT!

 

I'll come back to that. I think you have some timing issues if I understand correctly what is going on. It looks like the Arduino is streaming those numbers, the rate to me is unknown. If you want to read streaming data like that, set the timeout on the VISA configure port to some value that you should not hit in normal circumstances (5 seconds maybe). Let the VISA read determine the rate of your loop, IE get rid of the wait. And DO NOT USE BYTES AT PORT. If you can control how those numbers are sent, use a termination character (carriage return or line feed are pretty common). The Arduino language Serial.println() will send both. Set the termination character to the last symbol (linefeed 0x10) and the byte to read on the VISA read to something larger than you will ever see in normal communication. The VISA read function will read until it sees the newline character, or it times out.

 

My guess is right now your wait in the loop is causing the serial buffer to fill up and you are reading stale data until the buffer is full and then something resets. If you need to control the rate from the PC/LabVIEW side of things either change your communication schema to be a query-response type, or you still need to read the data on the buffer and just discard what you don't want to use. This assumes that the LabVIEW loop runs faster than the data is being streamed. If it isn't then you might still have this same problem but it might not show up as often, but you could still be reading stale data.


 

 

  • Noted. No using "Bytes At Port"
  • The flickering is gone upon using a carriage return of "10" instead of a property node with bytes at port. So that's great.
  • I will figure out a way to show check how fast the Arduino is printing on the serial port.

 

Please Explain the Query-Response Type.

0 Kudos
Message 6 of 11
(3,801 Views)

Please Explain the Query-Response Type.


When the computer wants some data, it sends a query to the Arduino. The Arduino waits until the computer sends the query and then sends the response. The computer knows that either the response will come in a timely fashion or something went wrong along the way. Both machines have a signal to know when the communication is finished. This is a good protocol.

 

Check out the built-in Arduino examples, e.g.: https://docs.arduino.cc/built-in-examples/communication/SerialCallResponseASCII

Note that in the Arduino code, you will be reading

inByte = Serial.read();

and cen then decide what kind of response the Arduino should send back over the line.

 

Labview has the corresponding "Simple Serial" example. Don't get confused by the "Bytes in Port" in that one. It ist just not proper.

Message 7 of 11
(3,785 Views)
Solution
Accepted by topic author Kulani93

UPDATE: No more Flickering, Thanks all for the input. Here's what I have so far, which works (maybe) for the purposes I need it to:

 

3.JPG

 

  • I am using the Arduino Portenta running at 115200 BuadRate, 16 Resolution.
  • So on the Arduino, I am printing the serial readings as before (A0-A6), and added another value (one after the last comma) at the end which shows the microsecond (Microsecond difference from first void loop line code to the end void loop line code) time interval approximation of how long the void loop takes to loop printing the readings to the serial monitor - This will be used later to determine the speed that the Arduino Serial output and internal processing is looping each line in Hz.

 

1.JPG

 

  • I have made changes to the VI above, removed "Bytes On Port" and set a 32 Byte size on the Serial Read (This constant on the VISA Read affects the Labview Loop Rate) - will refine it at the end and I am still open to a detailed suggestion/solution.
  • Concatenated a time stamp as advised (accurate to a millisecond) with the read buffer so that I write with time stamps to a text file.
  • Used the mentioned Arduino time Interval value to approximate the loop rate of Arduino, converted to Hz. I did not want to do this on the Arduino chip because it would slow it down.

 

2.JPG

 

  • The Arduino loop speed can be notice and compared to the Labview loop speed, and the Labview speed seems to depend on the Arduino Loop speed (tried serial printing one value, and noticed increased loop rates on both the Arduino and Labview - down to 70uS).
  • The gauges don't flicker anymore and they display a live reading (sort of) of the data stream and not just stagnant buffer readings. (when varying my voltages, the VI reflects on gauges accurately).

 

4.JPG

 

  •  Above is the data log text file, which is forted as:  "Date and time, A0,...,A6, Time Interval".

 

The next step would be looping Labview at exactly a 1000 Hz.

 

Thanks

0 Kudos
Message 8 of 11
(3,768 Views)
Solution
Accepted by topic author Kulani93

I would increase the bytes to read on the VISA read to some value that you will never see. With the termination character set correctly VISA read will read until one of three conditions is met: the number of bytes is available to read, the timeout on the configure port is exceeded, or the termination character is read. You want the later to always be the case. This ensures you are reading all the data up to the line feed and not leaving anything that could be read on the next read. The termination character essentially frames your data in correct chunks. 

Message 9 of 11
(3,763 Views)

On a side note, here's how some of your code could be simplified (Not sure why you use orange for mostly integers). Don't wire indices if you want the elements in order!

 

Two functions instead of ten! (I would probably even use an array of gauges)

 

altenbach_0-1655058160202.png

 

Message 10 of 11
(3,666 Views)