LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino analog read pin to frequency

Solved!
Go to solution

Hi.

 

I am trying to convert the digital voltage (read from the analog pin on my arduino mega from an accelerometer) and perform FFT/Spectral analysis to convert it into a Magnitude vs. Frequency output waveform.

 

I am having some issues accomplishing this, with my output from the Arduino Read Pin Vi as a double 64-real 16 precision data, which I convert to a single waveform. The output from the FFT (RMS) from my spectral measurement via is a 1D cluster of 3 elements. When I wire this to a waveform graph it just changes the Y values (magnitude) but frequency is not updating the X axis at all.

 

Please help here is a screen shot of my setup so far:

[IMG]http://i.imgur.com/WrzbX.png[/IMG]

 

I also attached the VI below.

 

0 Kudos
Message 1 of 33
(9,869 Views)

*bump*

0 Kudos
Message 2 of 33
(9,853 Views)

That double 64-real is a single reading of a voltage level. Unfortunately one reading is not enough information to do a meaningful FFT, you will need to build an array of the data and do analysis of that array instead.

 

You also will want to put a "Wait (ms)" function into your loop so that it isn't polling as fast as possible.

 

Hopefully this offers enough guidance to get you started!

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 3 of 33
(9,829 Views)

thanks for your guidance

 

does this make more sense?

 

0 Kudos
Message 4 of 33
(9,826 Views)

You're closer! Look through this example for some information about auto-indexing:

https://decibel.ni.com/content/docs/DOC-20828

 

You should be able to wire each voltage output into the right wall of the while loop. If you right click on the tunnel and choose enable auto indexing the output values of each iteration of the loop will be automatically indexed into an array. Thus after the while has finished you will have an array of all the values that the function read during the loop itself.

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 5 of 33
(9,824 Views)

Hi Craig,

 

Thanks for your continued feedback.

 

I placed outside the while loop and wired the voltage to auto index. I also chose concatenate inputs to keep it as a 1D array rather than 2D.

 

Is this the correct approach?

0 Kudos
Message 6 of 33
(9,818 Views)

You don't need the build array function as the data is already an array (it should work as coded though).

 

Otherwise does it work? Do you see the results that you want to see? I don't see anything that is jumping out at me.

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 7 of 33
(9,812 Views)

Thanks Craig.

 

 I removed those build arrays functions as you suggested.

 

 The FFT seems to be working, but not as I expect it...I think this has to do with the limited bandwidth of 50Hz sampling that the accelerometer itself can handle.

 

 My new question is how can I control the While Loop with say an On/Off type button, which also will clear the values stored in that tunnel so I can use it simultaneously with the rest of my program? What I mean is that I'd like the accelerometer part of my program to have it reusable during the course of the program execution, without affecting the rest of my program which is controlling 8 DC motors. That is to say that while loop should be able to take new readings and data without stopping the rest of my program. 

 

 I've attached my VI to this reply. 

 

 

  Thanks a lot!!!

0 Kudos
Message 8 of 33
(9,787 Views)

I've attached a snippet which should do what you want.

 

I changed the while loop to a for loop which will now run a set number of times (your "window"), and this will determine how many data points that are output in the array.

 

The old structure is now wrapped in a while loop so that it should iterate through aquisition, analysis and display continuously.

 

Hopefully this is the functionality you were looking for!

 arduino_test_snippet.png

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 9 of 33
(9,775 Views)

Thanks a lot Craig!

 

Just out of curiousity though, this is only set to run for X number of samples for 1 trial. But let's say I want to run another data set through FFT without stopping the program. Is this possible?

 

 I've tried by using Case Structures, but for some reason it doesnt seem to properly switch as I intend. I've attached my updated VI below.

 

 

Thanks!!

0 Kudos
Message 10 of 33
(9,771 Views)