AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info
//Serial.println(reply[i], HEX);
Re: AM2315 Bad Data after 12 reads- some new info
#include <Wire.h>
#include <Adafruit_AM2315.h>
/***************************************************
This is an example for the AM2315 Humidity + Temp sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> https://www.adafruit.com/products/1293
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
// Connect RED of the AM2315 sensor to 5.0V
// Connect BLACK to Ground
// Connect WHITE to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect YELLOW to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
Adafruit_AM2315 am2315;
void setup() {
Serial.begin(9600);
Serial.println("AM2315 Test!");
if (! am2315.begin()) {
Serial.println("Sensor not found, check wiring & pullups!");
while (1);
}
}
void loop() {
Serial.print("Hum: "); Serial.println(am2315.readHumidity());
delay(2); //<-- ADDED BY ESG TO ELIMINATE BAD DATA PROBLEM, NOT PART OF ORIGINAL EXAMPLE
Serial.print("Temp: "); Serial.println(am2315.readTemperature());
delay(1000);
}
Re: AM2315 Bad Data after 12 reads- some new info
New AM2315 Library- Temp & Humidity in a single function call
/***************************************************
This is a library for the AM2315 Humidity Pressure & Temp Sensor
Designed specifically to work with the AM2315 sensor from Adafruit
----> https://www.adafruit.com/products/1293
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
Additional improvements added by Daniel Sandoval/EasternStarGeek
8 July, 2013. (Parent Library: Adafruit_AM2315)
BSD license, all text above must be included in any redistribution
****************************************************/
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Wire.h"
#define AM2315_I2CADDR 0x5C
#define AM2315_READREG 0x03
class ESG_AM2315 {
public:
ESG_AM2315();
//boolean begin(void);
boolean readData(float *dataArray);
private:
float humidity, temp;
};
/***************************************************
This is a library for the AM2315 Humidity & Temp Sensor
Designed specifically to work with the AM2315 sensor from Adafruit
----> https://www.adafruit.com/products/1293
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
Additional improvements added by Daniel Sandoval/EasternStarGeek
8 July, 2013. (Parent Library: Adafruit_AM2315)
BSD license, all text above must be included in any redistribution
****************************************************/
#include "ESG_AM2315.h"
#include <util/delay.h>
ESG_AM2315::ESG_AM2315() {
}
boolean ESG_AM2315::readData(float *dataArray) {
uint8_t reply[10];
Wire.beginTransmission(AM2315_I2CADDR);
Wire.write(AM2315_READREG);
Wire.write(0x00); // start at address 0x0
Wire.write(4); // request 4 bytes data
Wire.endTransmission();
// for reasons unknown we have to send the data twice :/
// whats the bug here?
Wire.beginTransmission(AM2315_I2CADDR);
Wire.write(AM2315_READREG);
Wire.write(0x00); // start at address 0x0
Wire.write(4); // request 4 bytes data
Wire.endTransmission();
Wire.requestFrom(AM2315_I2CADDR, 8);
for (uint8_t i=0; i<8; i++) {
reply[i] = Wire.read();
//Serial.println(reply[i], HEX);
}
if ((reply[0] == AM2315_READREG) &&
(reply[1] == 4)) {
humidity = reply[2];
humidity *= 256;
humidity += reply[3];
humidity /= 10;
dataArray[0] = humidity;
temp = reply[4];
temp *= 256;
temp += reply[5];
temp /= 10;
dataArray[1] = (temp * 1.8)+32;
return true;
}
else {
dataArray[0] = NAN;
dataArray[1] = NAN;
return false;
}
}
/*********************************************************************/
#include <Wire.h>
#include <ESG_AM2315.h>
/***************************************************
This is an example for the AM2315 Humidity + Temp sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> https://www.adafruit.com/products/1293
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
Additional improvements added by Daniel Sandoval/EasternStarGeek
8 July, 2013. (Parent Library: Adafruit_AM2315)
This version gets the Temperature and Humidity data with a single read, and is
believed to solve some prior timing problems in the original.
Be careful with return data array indexing! Follow this example closely.
BSD license, all text above must be included in any redistribution
****************************************************/
// Connect RED of the AM2315 sensor to 5.0V
// Connect BLACK to Ground
// Connect WHITE to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect YELLOW to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
ESG_AM2315 am2315;
float dataAM2315[2]; //Array to hold data returned by sensor. [0,1] => [Humidity, Temperature]
boolean OK; // 1=successful read
void setup() {
Serial.begin(9600);
Serial.println("AM2315 Test!");
}
void loop() {
OK = am2315.readData(dataAM2315);
if (OK) {
Serial.print("Hum: "); Serial.println(dataAM2315[0]);
Serial.print("TempF: "); Serial.println(dataAM2315[1]);
}
else
Serial.println("Sensor not found, check wiring & pullups!");
delay(1000);
}
Re: AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info
EasternStarGeek wrote:The trick is to not read the sensor too frequently. (like <10mS interval).
Re: AM2315 Bad Data after 12 reads- some new info
#define AM2315_I2CADDR 0x5C
Wire.beginTransmission(AM2315_I2CADDR);
delay(3);
Wire.endTransmission();
Re: AM2315 Bad Data after 12 reads- some new info
Re: AM2315 Bad Data after 12 reads- some new info