1 Reply Latest reply on Jun 27, 2016 2:26 PM by Intel Corporation

    AM2315 and JavaScript

    KimLorentz

      I got the AM2315 to work without library in arduino, I only need to make it work on javascript.

       

      Can anyone help me there.

       

      Here is my current arduino code.

      #define AM2315_I2CADDR       0x5C
      #define AM2315_READREG       0x03
      #include <Wire.h>
      
      float humidity, temp;
      
      void setup() 
      {
        Wire.begin();        // join i2c bus (address optional for master)
        Serial.begin(115200);  // start serial for output
        delay(100); 
      }
      
      void readData()
      {
        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);
        }
      
        humidity = reply[2];
        humidity *= 256;
        humidity += reply[3];
        humidity /= 10;
        Serial.print("Humidity: "); Serial.println(humidity);
      
        temp = reply[4] & 0x7F;
        temp *= 256;
        temp += reply[5];
        temp /= 10;
        Serial.print("Temp: "); Serial.println(temp);
      
      }
      
      void loop() 
      {
        readData();
        delay(5000);
      }