WiPy -> AM2315 env sensor - I2C interface
-
Has anyone successfully interfaced to the AM2315 temp / humidity sensor?
If so what modules did you use?Thanks
kevin Hanna -
this is really simple sensor I2C
you can change code to pythonoolean Adafruit_AM2315::readData(void) { uint8_t reply[10]; // Wake up the sensor Wire.beginTransmission(AM2315_I2CADDR); delay(2); Wire.endTransmission(); // OK lets ready! Wire.beginTransmission(AM2315_I2CADDR); Wire.write(AM2315_READREG); Wire.write(0x00); // start at address 0x0 Wire.write(4); // request 4 bytes data Wire.endTransmission(); delay(10); // add delay between request and actual read! 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) return false; if (reply[1] != 4) return false; // bytes req'd humidity = reply[2]; humidity *= 256; humidity += reply[3]; humidity /= 10; //Serial.print("H"); Serial.println(humidity); temp = reply[4] & 0x7F; temp *= 256; temp += reply[5]; temp /= 10; //Serial.print("T"); Serial.println(temp); // change sign if (reply[4] >> 7) temp = -temp; return true; } float Adafruit_AM2315::readTemperature(void) { if (! readData()) return NAN; return temp; } float Adafruit_AM2315::readHumidity(void) { if (! readData()) return NAN; return humidity; }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login