Snippet Tag: iot predictive maintenance

Reading I2C

//———-I2CCallback———–// void taskI2CCallback(){ Serial.println("taskI2CStarted"); Serial.print("timeout for this task: t"); Serial.println(tI2C.getTimeout()); unsigned int data[2]; // Start I2C transmission Wire.beginTransmission(Addr); // Send humidity measurement command, NO HOLD master Wire.write(0xF5); // Stop I2C transmission Wire.endTransmission(); delay(500); // Request 2 bytes of data Wire.requestFrom(Addr, 2); // Read 2 bytes of data // humidity msb, humidity lsb if(Wire.available() == 2) { data[0] = Wire.read(); data[1] = Wire.read(); // Convert the data float humidity = (((data[0] * 256.0 + data[1]) * 125.0) / 65536.0) – 6; // Output data to Serial Monitor Serial.print("Relative Humidity :"); Serial.print(humidity); Serial.println(" %RH"); humid = humidity; } // Start I2C transmission

Read More »