LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem reading two sensors with analogReadpin

Solved!
Go to solution

Hi,guys.

I've been having trouble using analogRead() to read values from two separate sensors. If I run a sketch that calls analogReadpin for either one of the sensor inputs I get good results, but if my sketch has two analogReadpin calls for both sensors the values returned are inconsistent and incorrect.

Details:

I connect a LM35 to analogpin A0 and a potentiometer to analog pin A4 to mege 2560.When I  read A0 alone the results is correct.But if I read both A0 and A4,when I adjust the potentiometer,the value read from LM35(A0) change, the larger value of A4,the larger value of A0.

Someone says ,the problem is that the Atmega on the Arduino has one ADC that is multiplexed for all the analog pins.
When you do an analogRead(), a multiplexer connects the pin you are reading to the ADC. This works fine for low impedance voltage sources.

It takes time for a high impedance sensor like your temperature sensor to change the voltage at the ADC after this switch of pins. Temperature sensors must use low power and thus be high impedance to avoid IR heating.

So he suggest to add a delay before each analogRead in Arduino skech like this:

analogRead(5);
delay(10);
nTemp = analogRead(5) * 5000L / 1024L / 10;

But how can I fix it in labview sketch?Here's my sketch.

0 Kudos
Message 1 of 3
(4,039 Views)
Solution
Accepted by topic author hby001

Interesting.  If this is a major problem (which it sounds like it is) I would recommend duplicating the LIFA Analog Read Pin functions to create a special version for this purpose.

However, the above recommendation is not easy for beginners who haven't already done it before so alternatively, (and easier), you can do in LabVIEW exactly what you would do in Arduino.  Read, delay, read, for each value you need.  Not exactly the best solution, IMO.

As an FYI, the output of the Analog Read Pin VI is not dynamic data and is simply a one double which means you shouldn't using the "Convert from dynamic data" VI.  Also, you are taking the average (mean) of a single number (which is just that number) on every loop iteration.

0 Kudos
Message 2 of 3
(3,256 Views)

So I  use read, delay and read,also replace the "Convert from dynamic data" VI and "mean" VI with one "Mean PtbyPt".It works well.Thanks.
QQ截图20121011140909.jpg

            

0 Kudos
Message 3 of 3
(3,256 Views)