Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
adafruit_support_bill wrote:Please post a photo of the one that doesn't work. And also post the code you are using to read the sensors.
analogRead(ADCpin); // first ADC reading discarded
delay(20);
reading = 0; // read ADC pin 0 10 times
for (int loop = 0; loop < iterations; loop++)
{
reading += analogRead(ADCpin);
delay(20);
}
analogRead(ADCpin2);
delay(20);
reading1 = 0; // read ADC pin 1 10 times
for (int loop = 0; loop < iterations; loop++)
{
reading1 += analogRead(ADCpin2);
delay(20);
}
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
/* LCD Thermometer Sketch for RasPiO Duino 20x4 i2c LCD
Library version:1.1 from robot-r-us.com
Compatible with the Arduino IDE 1.0 and above
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int ADCpin = 0; // declare variables
int ADCpin2 = 1;
int iterations = 10;
float voltage = 3.3;
float voltage1 = 3.3;
int reading = 0;
int reading1 = 0;
// set LCD i2c address to 0x27 and 20 char x 4 line display
LiquidCrystal_I2C lcd(0x27,20,4);
void setup()
{
lcd.init(); // initialize lcd
lcd.backlight();
lcd.setCursor(0, 0); // go to column 0 row 0
lcd.print(" i2c 20x4 LCD"); // Print txt on LCD
lcd.setCursor(0, 1);
lcd.print(" powered by");
lcd.setCursor(0, 3);
lcd.print(" Bob");
delay(5000);
lcd.clear();
Serial.begin(9600);
}
void loop()
{
analogRead(2); // first ADC reading discarded
delay(20);
reading = 0; // read ADC pin 0 10 times
for (int loop = 0; loop < iterations; loop++)
{
reading += analogRead(ADCpin);
delay(20);
}
analogRead(2);
delay(20);
reading1 = 0; // read ADC pin 1 10 times
for (int loop = 0; loop < iterations; loop++)
{
reading1 += analogRead(ADCpin2);
delay(20);
}
lcd.setCursor(0, 0);
lcd.print(reading / iterations);
lcd.print(" ");
lcd.print(reading1 / iterations);
lcd.print(" AD raw");
voltage = reading / 1023.0 / iterations * 3.3;
voltage1 = reading1 / 1023.0 / iterations * 3.3;
lcd.setCursor(0, 1);
lcd.print(voltage, 3); // print voltage to 3dp
lcd.print(" ");
lcd.print(voltage1, 3);
lcd.print(" Volts");
lcd.setCursor(0, 2);
int temperature = voltage * 100 - 50;
lcd.print(temperature);
lcd.print((char)223); // print degree symbol
lcd.print("C ");
int temperature1 = voltage1 * 100 - 50;
lcd.print(temperature1);
lcd.print((char)223);
lcd.print("C ");
Serial.print("A");
Serial.print(ADCpin);
Serial.print(" - ");
Serial.print(analogRead(ADCpin));
Serial.print(" A");
Serial.print(ADCpin2);
Serial.print(" - ");
Serial.println(analogRead(ADCpin2));
delay(500);
}
Re: Problem reading two sensors with analogRead()
Output from the A0 and A1 readings.
Re: Problem reading two sensors with analogRead()
adafruit_support_bill wrote:Output from the A0 and A1 readings.
? I don't see the output...
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
adafruit_support_bill wrote:Are those the raw readings or calculated results? Not sure about the accuracy, but they do seem pretty stable.,
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
Re: Problem reading two sensors with analogRead()
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.
Re: Problem reading two sensors with analogRead()
I am feeding the sensors with the 3.3v line on the Metro.
Re: Problem reading two sensors with analogRead()
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
Re: Problem reading two sensors with analogRead()
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.