Skip to content

Commit

Permalink
Add HYT I2c bus2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
arendst committed Oct 20, 2023
1 parent 2cabbc6 commit f05470b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion I2CDEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 18 additions & 11 deletions tasmota/tasmota_xsns_sensor/xsns_97_hyt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit f05470b

Please sign in to comment.