/// <summary> /// Force the sensor to make a reading and update the relevant properties. /// </summary> public void Update() { _hih6130.WriteByte(0); // // Sensor takes 35ms to make a valid reading. // Thread.Sleep(40); var data = _hih6130.ReadBytes(4); // // Data format: // // Byte 0: S1 S0 H13 H12 H11 H10 H9 H8 // Byte 1: H7 H6 H5 H4 H3 H2 H1 H0 // Byte 2: T13 T12 T11 T10 T9 T8 T7 T6 // Byte 4: T5 T4 T3 T2 T1 T0 XX XX // if ((data[0] & 0xc0) != 0) { throw new Exception("Status indicates readings are invalid."); } var reading = ((data[0] << 8) | data[1]) & 0x3fff; Humidity = ((float)reading / 16383) * 100; reading = ((data[2] << 8) | data[3]) >> 2; Temperature = (((float)reading / 16383) * 165) - 40; }
/// <summary> /// Force the sensor to make a reading and update the relevanyt properties. /// </summary> /// <param name="startAddress">Start address for the read operation.</param> /// <param name="amount">Amount of data to read from the EEPROM.</param> public byte[] Read(ushort startAddress, ushort amount) { CheckAddress(startAddress, amount); var address = new byte[2]; address[0] = (byte)((startAddress >> 8) & 0xff); address[1] = (byte)(startAddress & 0xff); _eeprom.WriteBytes(address); return(_eeprom.ReadBytes(amount)); }
void ReadStatus() { reception_data = _I2CBus.ReadBytes(5); Thread.Sleep(100); }