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 python

    oolean 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;
    }
    

Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.