Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    WiPy -> AM2315 env sensor - I2C interface

    Scheduled Pinned Locked Moved WiPy 2&3
    2 Posts 2 Posters 985 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K Offline
      Kevin Hanna
      last edited by

      Has anyone successfully interfaced to the AM2315 temp / humidity sensor?
      If so what modules did you use?

      Thanks
      kevin Hanna

      1 Reply Last reply Reply Quote 0
      • L Offline
        livius
        last edited by

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

        think about people first, then computers

        1 Reply Last reply Reply Quote 0

        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
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom