protected void Initialize() { htu21d.WriteByte(SOFT_RESET); Thread.Sleep(100); SetResolution(SensorResolution.TEMP11_HUM11); }
/// <summary> /// Update the Temperature property. /// </summary> public void Update() { lm75.WriteByte((byte)Register.LM_TEMP); var data = lm75.ReadRegisters((byte)Register.LM_TEMP, 2); // Details in Datasheet P10 double temp = 0; ushort raw = (ushort)((data[0] << 3) | (data[1] >> 5)); if ((data[0] & 0x80) == 0) { // temperature >= 0 temp = raw * 0.125; } else { raw |= 0xF800; raw = (ushort)(~raw + 1); temp = raw * (-1) * 0.125; } //only accurate to +/- 0.1 degrees Conditions.Temperature = (float)Math.Round(temp, 1); }
/// <summary> /// Force the sensor to make a reading and update the relevant properties. /// </summary> public async Task Update() { hih6130.WriteByte(0); // // Sensor takes 35ms to make a valid reading. // await Task.Delay(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; Conditions.Humidity = ((float)reading / 16383) * 100; reading = ((data[2] << 8) | data[3]) >> 2; Conditions.Temperature = (((float)reading / 16383) * 165) - 40; }
protected void Initialize() { si7021.WriteByte(SOFT_RESET); Thread.Sleep(100); // // Get the device ID. // SerialNumber = 0; Span <byte> tx = stackalloc byte[2]; Span <byte> rx = stackalloc byte[8]; Span <byte> rx2 = stackalloc byte[6]; tx[0] = READ_ID_PART1; tx[1] = READ_ID_PART2; si7021.WriteRead(tx, rx); for (var index = 0; index < 4; index++) { SerialNumber <<= 8; SerialNumber += rx[index * 2]; } tx[0] = READ_2ND_ID_PART1; tx[1] = READ_2ND_ID_PART2; si7021.WriteRead(tx, rx2); SerialNumber <<= 8; SerialNumber += rx2[0]; SerialNumber <<= 8; SerialNumber += rx2[1]; SerialNumber <<= 8; SerialNumber += rx2[3]; SerialNumber <<= 8; SerialNumber += rx2[4]; if ((rx2[0] == 0) || (rx2[0] == 0xff)) { SensorType = DeviceType.EngineeringSample; } else { SensorType = (DeviceType)rx2[0]; } SetResolution(SensorResolution.TEMP11_HUM11); }
/// <summary> /// Clear the interrupt flag. /// Se Command Register on page 13 of the datasheet. /// </summary> /// <remarks> /// According to the datasheet, writing a 1 into bit 6 of the command /// register will clear any pending interrupts. /// </remarks> public void ClearInterrupt() { tsl2561.WriteByte(ClearInterruptBit); if (_interruptPin != null) { //Port: TODO - check if needed _interruptPin.ClearInterrupt(); } }
protected void Initialize() { si7021.WriteByte(SOFT_RESET); Thread.Sleep(100); // // Get the device ID. // var part1 = si7021.WriteRead(new[] { READ_ID_PART1, READ_ID_PART2 }, 8); var part2 = si7021.WriteRead(new[] { READ_2ND_ID_PART1, READ_2ND_ID_PART2 }, 6); SerialNumber = 0; for (var index = 0; index < 4; index++) { SerialNumber <<= 8; SerialNumber += part1[index * 2]; } SerialNumber <<= 8; SerialNumber += part2[0]; SerialNumber <<= 8; SerialNumber += part2[1]; SerialNumber <<= 8; SerialNumber += part2[3]; SerialNumber <<= 8; SerialNumber += part2[4]; if ((part2[0] == 0) || (part2[0] == 0xff)) { SensorType = DeviceType.EngineeringSample; } else { SensorType = (DeviceType)part2[0]; } SetResolution(SensorResolution.TEMP11_HUM11); }
/// <summary> /// Read data via I2C (DHT12, etc.) /// </summary> internal virtual void ReadDataI2c() { _sensor.WriteByte(0x00); _readBuffer = _sensor.ReadBytes(5); _lastMeasurement = Environment.TickCount; if ((_readBuffer[4] == ((_readBuffer[0] + _readBuffer[1] + _readBuffer[2] + _readBuffer[3]) & 0xFF))) { WasLastReadSuccessful = (_readBuffer[0] != 0) || (_readBuffer[2] != 0); } else { WasLastReadSuccessful = false; } }
void InitHT16K33() { // SetIsAwake(true); // SetDisplayOn(true); // SetBlinkRate(BlinkRate.Off); i2cPeripheral.WriteByte(0x21); i2cPeripheral.WriteByte(0x81); SetBrightness(Brightness.Maximum); ClearDisplay(); }
private void Write8(byte reg, byte val) { si1145.WriteByte(reg); si1145.WriteByte(val); }
void ExpanderWrite(byte value) { i2cPeripheral.WriteByte((byte)(value | backlightValue)); }