Problem reading two sensors with analogRead()

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_bill »

Output from the A0 and A1 readings.
? I don't see the output...

User avatar
txbobs
 
Posts: 22
Joined: Wed Jan 30, 2013 3:11 pm

Re: Problem reading two sensors with analogRead()

Post by txbobs »

adafruit_support_bill wrote:
Output from the A0 and A1 readings.
? I don't see the output...
Helps if actually paste it. :)

A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 148 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147
A0 - 147 A1 - 147

I just checked and the voltage coming in from the sensors is around .67 which seems correct but I am calculating .47 for both of them. I am beginning to think it is just a code problem. Still interesting that changing Arduinos makes a difference.
Last edited by txbobs on Mon Jan 04, 2016 1:56 pm, edited 1 time in total.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_bill »

Are those the raw readings or calculated results? Not sure about the accuracy, but they do seem pretty stable.,

User avatar
txbobs
 
Posts: 22
Joined: Wed Jan 30, 2013 3:11 pm

Re: Problem reading two sensors with analogRead()

Post by txbobs »

adafruit_support_bill wrote:Are those the raw readings or calculated results? Not sure about the accuracy, but they do seem pretty stable.,
They are raw readings. I guess the instability comes only when I had only one sensor connected but was reading both inputs still. Since the open pin was floating, its readings varied greatly. That didn't happen on the raspio though which had me confused.

I guess now I am just left with the puzzle of the two platforms behaving/reporting differently. Thanks for your help, Bill.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_bill »

A floating analog pin makes a pretty good random number generator on an Arduino. I'm not familiar with the internals of the RasPiO or what they may be doing differently. One possible difference might be the analog reference voltage. It is 5v by default on most Arduinos, but the Pi is a 3.3v device.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_rick »

Try the double-read thing. I don't know why the RasPiIO doesn't do it. This is an AVR thing.

User avatar
txbobs
 
Posts: 22
Joined: Wed Jan 30, 2013 3:11 pm

Re: Problem reading two sensors with analogRead()

Post by txbobs »

adafruit_support_bill wrote:A floating analog pin makes a pretty good random number generator on an Arduino. I'm not familiar with the internals of the RasPiO or what they may be doing differently. One possible difference might be the analog reference voltage. It is 5v by default on most Arduinos, but the Pi is a 3.3v device.
I am feeding the sensors with the 3.3v line on the Metro. The .7v on the raspio is returning a raw 220 while the Metro only reports the 148.

I decided to see what the extremes are on the metro. Connecting A0 to ground and A1 to 3.3 I get the following.
A0 - 0 A1 - 692
A0 - 0 A1 - 694
A0 - 0 A1 - 693
A0 - 0 A1 - 693
A0 - 0 A1 - 693

Is the Metro ADC expecting 5v? Sure seems like that is the case.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Problem reading two sensors with analogRead()

Post by adafruit_support_bill »

I am feeding the sensors with the 3.3v line on the Metro.
But the default analog reference is 5v. This can be changed to 3.3v if desired.
https://www.arduino.cc/en/Reference/AnalogReference

User avatar
txbobs
 
Posts: 22
Joined: Wed Jan 30, 2013 3:11 pm

Re: Problem reading two sensors with analogRead()

Post by txbobs »

adafruit_support_bill wrote:
I am feeding the sensors with the 3.3v line on the Metro.
But the default analog reference is 5v. This can be changed to 3.3v if desired.
https://www.arduino.cc/en/Reference/AnalogReference
Thanks, Bill. I added a 3.3v connection to the aref pin and added analogReference(EXTERNAL); to the code. Seems to be working now. Thanks for the newbie interruption. :)

User avatar
WarthogARJ
 
Posts: 2
Joined: Sun Jan 27, 2019 11:51 pm

Re: Problem reading two sensors with analogRead()

Post by WarthogARJ »

Is this person still working at Adafruit?
If so, I really hope they were told that this specific response was a very poor one.

The guy you replied to was doing a good job of looking into a problem, but Adafruit Admin was pretty insulting and derogatory in their reply.

The issue is indeed a general one, and this sort of investigation needs to be encouraged.
I was thinking I should support Adafruit due to their general support, but this sort of reply doesn't dosn't do that.

adafruit wrote:
bswift5528 wrote:Yeah, I just finished that up now. Works great! Still don't know why the bandgap reference isn't stable, or why the 1.05 was in the original calculation,
not sure how else we can say that it wasnt stable because it wasnt stable. maybe they didnt want to spend more money on it? regardless, its not in the tutorial anymore because it didnt work well - which means you should probably stop thinking about it :mrgreen:
Still, Sensor 2 seems to be acting up...this time, reading a few deg higher than the other two, and not just being noisy. Has anyone had problems of this nature with a TMP36 before? Thanks again!
electronic temperature sensors are precise to only about 1 or 2 degrees.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”