05-17-2022 09:26 AM
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.
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.
Then writing the readings to a textfile, as well as displaying the readings on a Gauge - all occuring in a single loop.
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.
Solved! Go to Solution.
05-17-2022 09:42 AM
@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
3 : Again, do you need to go that fast ? By the way you have no timer delay when you are going to 20 KHz?
05-17-2022 10:18 AM - edited 05-17-2022 10:24 AM
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.
05-17-2022 11:42 AM
DON"T USE "BYTES AT PORT"
Watch this video on how to properly program serial communications.
VIWeek 2020/Proper way to communicate over serial
05-18-2022 02:23 AM - edited 05-18-2022 03:14 AM
@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
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.
05-18-2022 03:11 AM - edited 05-18-2022 03:15 AM
@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.
Please Explain the Query-Response Type.
05-18-2022 05:01 AM - edited 05-18-2022 05:16 AM
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.
05-18-2022 08:48 AM
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:
The next step would be looping Labview at exactly a 1000 Hz.
Thanks
05-18-2022 09:01 AM
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.
06-12-2022 01:25 PM
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)