From f05470bf81dcb67a4b7cf33f322c2813ba40a922 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:35:24 +0200 Subject: [PATCH] Add HYT I2c bus2 support --- I2CDEVICES.md | 2 +- tasmota/tasmota_xsns_sensor/xsns_97_hyt.ino | 29 +++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/I2CDEVICES.md b/I2CDEVICES.md index 1002223f67e4..e63af6091242 100644 --- a/I2CDEVICES.md +++ b/I2CDEVICES.md @@ -105,7 +105,7 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip 65 | USE_ADE7880 | xnrg_23 | ADE7880 | 0x38 | | Energy monitor 66 | USE_PCF85363 | xsns_99 | PCF85363 | 0x51 | | Real time clock 67 | USE_DS3502 | xdrv_61 | DS3502 | 0x28 - 0x2B | | Digital potentiometer - 68 | USE_HYT | xsns_97 | HYTxxx | 0x28 | | Temperature and Humidity sensor + 68 | USE_HYT | xsns_97 | HYTxxx | 0x28 | Yes | Temperature and Humidity sensor 69 | USE_SGP40 | xsns_98 | SGP40 | 0x59 | | Gas (TVOC) and air quality 70 | USE_LUXV30B | xsns_99 | LUXV30B | 0x4A | | DFRobot SEN0390 V30B lux sensor 71 | USE_QMC5883L | xsns_33 | QMC5883L | 0x0D | | Magnetic Field Sensor diff --git a/tasmota/tasmota_xsns_sensor/xsns_97_hyt.ino b/tasmota/tasmota_xsns_sensor/xsns_97_hyt.ino index 8bdcbe782a68..2064d21a77f3 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_97_hyt.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_97_hyt.ino @@ -36,6 +36,7 @@ struct HYT { float humidity = NAN; float temperature = NAN; + uint8_t bus; uint8_t valid = 0; uint8_t count = 0; char name[6] = "HYT"; @@ -44,14 +45,16 @@ struct HYT { bool HYT_Read(void) { if (HYT.valid) { HYT.valid--; } - Wire.beginTransmission(HYT_ADDR); - Wire.requestFrom(HYT_ADDR, 4); - if (Wire.available() == 4) { - uint8_t data1 = Wire.read(); - uint8_t data2 = Wire.read(); - uint8_t data3 = Wire.read(); - uint8_t data4 = Wire.read(); - Wire.endTransmission(); + TwoWire& myWire = I2cGetWire(HYT.bus); + if (&myWire == nullptr) { return false; } // No valid I2c bus + myWire.beginTransmission(HYT_ADDR); + myWire.requestFrom(HYT_ADDR, 4); + if (myWire.available() == 4) { + uint8_t data1 = myWire.read(); + uint8_t data2 = myWire.read(); + uint8_t data3 = myWire.read(); + uint8_t data4 = myWire.read(); + myWire.endTransmission(); // Convert the data to 14-bits float humidity = ((((data1 & 0x3F) * 256) + data2) * 100.0) / 16383.0; @@ -72,9 +75,13 @@ bool HYT_Read(void) { /********************************************************************************************/ void HYT_Detect(void) { - if (I2cSetDevice(HYT_ADDR)) { - I2cSetActiveFound(HYT_ADDR, "HYT"); - HYT.count = 1; + for (HYT.bus = 0; HYT.bus < 2; HYT.bus++) { + if (!I2cSetDevice(HYT_ADDR, HYT.bus)) { continue; } + if (HYT_Read()) { + I2cSetActiveFound(HYT_ADDR, "HYT", HYT.bus); + HYT.count = 1; + break; + } } }