LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question about Arduino & Labview

Solved!
Go to solution

Dear all,

I use Arduino Uno and an ADC shield ( could ask arduino receive minus signal ) as a data acquisition device. My labview version is 2016. It's a two channels signal acquisition device. One channel is the Incentive sin signal, the other channel is the Induction signal. Both Sin and Induction signal is a periodic signal. I could get the signal on oscilloscope like fig.1 below, I check the serial monitor works well and the result looks like good enough, but I could not understand why I couldn't get the same display through Labview.

 

fig01.jpg

 fig.1 oscilloscope display

Always I got the same value to display in a loop. I considered if the connection between VISA read and display was wrong, this part you could found in the below post file ( I use this for loop in order to enhance the sampling numbers, the frequency of my incentive sin signal is 1Hz, without this for loop inside the arduino code the delay will decrease the sampling number so my idea is adding a for loop enhance the sampling number because after reading 300 serials there is only one delay for 1 ms. )

fig02.png

fig.2 Internal for loop structure

The connection especially inside of the for loop may have something wrong, could u help me? Thx.

With best wishes,

Andy

Download All
0 Kudos
Message 1 of 13
(6,481 Views)

Hello Andy,

My guess is your serial communication is not setup correctly and maybe transmitting a bit too much data. Looking at the arduino code, you have setup the baud rate for the serial port to 9600 (that means 9600 bits per second) and you're transmitting every 1 ms a total of approximately 18 bytes. That will give you a data transmission rate of around 18 kBytes per second, being well above the configured baud rate. Even increasing the the baud rate to 115200 will probably not resolve the issue due to the volume of data being transmitted every second. 

My suggestion is for you to send the data through the serial line in binary format instead of string encoded and in labview convert from that to a float. The arduino forum post below can help you on the arduino side: 
http://forum.arduino.cc/index.php?topic=452784.0

 

For the labview conversion, just wait for the serial port to have 8 bytes (2 floats) and convert them using a type cast.

 

Hope it helps!

0 Kudos
Message 2 of 13
(6,434 Views)

What does the display look like in LabVIEW?

 

Don't use Bytes at Port!   You'll get whatever is in the serial port at that moment, and if the messages is incomplete, it will interfere with getting it back to meaningful data.    Does your Arduino send the data with a termination character?  You configured the serial port to enable line feed as a termination character.  If your Arduino is sending that between data packets, then use it.  Read a large number of bytes, longer than the longest message you expect to get.  Then you know you'll get complete messages.  You won't need to do any timing functions inside either of your loops.

 

You have an uninitialized shift register in your inner For Loop.  That means those arrays will keep growing because the data in the shift register after the last iteration of the For Loop will still be there when the outer while loop comes around again and begins the first iteration of the inner For Loop.

 

You are using Waveform charts which maintain their own history.  But you are building your own arrays which means you are building your own history.  So when you send that to a chart, you are effectively repeating past history over and over and over again.

 

If you want to only add new data to the Write to Spreadsheet File functions, you probably want to put a True on the Append File? input so that you only append new data to the file, rather than rewriting the entire history of data to the file over and over and over again.

 

Don't use insert into Array when you are building arrays.  You are putting new data at the beginning of the array which I doubt is what you want.  (Probably want the end.)  Build Array is a much simpler function to use when you want to put the data at the beginning or the end of an array, which is probably 95% of the use cases any way.  Only use Insert into Array, when you might have to put data into the middle.

0 Kudos
Message 3 of 13
(6,431 Views)
Solution
Accepted by topic author Andy_Iris

Hi Andy,

 

beside those other problems: your code can be simplified a lot:

check.png

(Maybe you need to change this format string just a little bit, but according to your sketch it should fit.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 13
(6,421 Views)

Thx, felipe. Up to now I don't know if I should change the float output, I guess there are something wrong inside the for loop because when I remove the for loop part in both arduino and labview part, the result (especially the sin part could display continuously) like the following figure. I could get the sin part but the sampling number is not enough so the noise value becomes more dispersed compared with the results of oscilloscope.

 

0 Kudos
Message 5 of 13
(6,417 Views)

Thanks for your help, RavensFan. The labview display as follows:Labview display.png

 

So I was wondering maybe the connection inside the for loop is wrong. From serial monitor, I use the termination character to send the data like below:serial monitor.pngthe form is  cha1; cha2/ cha1; cha2/......   set  300 group as a cycle

 

I have an uninitialized shift register in my inner For Loop. If I set the initialized shift register, will it be discontinuous display because the next data of a new for loop become different?

 

The function of my project is to record a Images with fixed abscissa values like 300 or some other points.(it depends on the period,normally 2 periods)  so maybe I need a case structure to judge.

Thanks again for your work.

With best wishes,

Andy

 

0 Kudos
Message 6 of 13
(6,411 Views)

Dear GerdW,

Thanks for your work and time, I'll try to change my code to see if it could solve the problem. I'm sorry to disturb, what's the name of following VI, I couldn't find it.

a.png

With best wishes,

Andy

0 Kudos
Message 7 of 13
(6,407 Views)

Scan From String

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 13
(6,401 Views)
Solution
Accepted by topic author Andy_Iris

@Andy_Iris wrote:

Thanks for your help, RavensFan. The labview display as follows:Labview display.png

 

So I was wondering maybe the connection inside the for loop is wrong. From serial monitor, I use the termination character to send the data like below:serial monitor.pngthe form is  cha1; cha2/ cha1; cha2/......   set  300 group as a cycle

 

I have an uninitialized shift register in my inner For Loop. If I set the initialized shift register, will it be discontinuous display because the next data of a new for loop become different?

 

The function of my project is to record a Images with fixed abscissa values like 300 or some other points.(it depends on the period,normally 2 periods)  so maybe I need a case structure to judge.

Thanks again for your work.

With best wishes,

Andy

 


So it looks like the forward slash /  is what separates data packets.  Correct?  In that case, set your terminal character to be a forward slash.  Then read 100 bytes every time you read.  You'll get all the data up through the forward slash and then use the Scan from String to break them into two at the semi-colon.

 

A better scenario would be to change your Arduino code to send a linefeed character after the two data points (decimal 10 or hex 0A) since that is a more common end of message delimiter than a slash.  And would allow you to use the Serial Configure without wiring a end of message character into it since it defaults to line feed.

 

For what you are doing, I wound't build an array at all or use a shift register.  Since you are using charts, just wire the new data points directly to the chart in a single while loop with no inner for loop.

Message 9 of 13
(6,396 Views)

Dear 

I used to use your idea, create and to send a linefeed character after  two data points,the form looks like bilow:

cha01; cha02

cha01; cha02

cha01; cha02

.....

I could get the sin part looks like smoothly, but there is a big difference between the absolute value of noise through labview and oscilloscope. So I was wondering it is because from arduino part, each time when u update data, there is a delay. I set the delay(10), it means 1s I could get no more than 100 points. It's not enough to describe the noise profile and makes noise signal more dispersed like below:fig.01 Oscilloscope displayfig.01 Oscilloscope display

 fig.02 Display the sin and abs value of noisefig.02 Display the sin and abs value of noise

 Then I set the delay(0.1) but I could not found the difference. So I thought to use a for loop inside in order to get a less delay. 

For me, it's better to use a Waveform Graph because I'm interested in period display rather than historical data, I use chart just because when I use graph there is only one point on the screen. So when I want to use the graph to display the results, I guess I need to use the inside for loop to come true, is that correct?

Thanks again for your time.

Andy

 

0 Kudos
Message 10 of 13
(6,384 Views)