mirror of https://github.com/arendst/Tasmota.git
Bugfix: multiple SHT4x sensors at the same bus, support for SHT40-CD1B (#21755)
* fixes multiple SHT3X sensor type bug Important when multiple sensors are present at the same bus. Prior to this fix, multiple SHT3X sensor were detected, but not SHTC3 and SHT4X! * Update xsns_14_sht3x.ino Extends I²C address range to include SHT40-CD1B sensors with address 0x46. * Update I2CDEVICES.md * Show bus when multiple sensors at different busses * Make bus number less intrusive Only show bus number if two sensors or more are active at more than one bus. * variable renamed * cleanup * fix typo * fix another typo * Harmonization and saving code size for ESP8266 Harmonization with xsns_09_bmp driver, saving code size for ESP8266 * fix string for webserver * Display address only if more than one sensor present.
This commit is contained in:
parent
5df51a9365
commit
27083e3664
|
@ -32,7 +32,7 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip
|
|||
13 | USE_ADS1115 | xsns_12 | ADS1115 | 0x48 - 0x4B | Yes | 4-channel 16-bit A/D converter
|
||||
14 | USE_INA219 | xsns_13 | INA219 | 0x40 - 0x41, 0x44 - 0x45 | | Low voltage current sensor
|
||||
15 | USE_SHT3X | xsns_14 | SHT3X | 0x44 - 0x45 | Yes | Temperature and Humidity sensor
|
||||
15 | USE_SHT3X | xsns_14 | SHT4X | 0x44 - 0x45 | Yes | Temperature and Humidity sensor
|
||||
15 | USE_SHT3X | xsns_14 | SHT4X | 0x44 - 0x46 | Yes | Temperature and Humidity sensor
|
||||
15 | USE_SHT3X | xsns_14 | SHTCX | 0x70 | Yes | Temperature and Humidity sensor
|
||||
16 | USE_TSL2561 | xsns_16 | TSL2561 | 0x29, 0x39, 0x49 | | Light intensity sensor
|
||||
17 | USE_MGS | xsns_19 | Grove | 0x04 | | Multichannel gas sensor
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
xsns_14_sht3x.ino - SHT3X, SHT4X and SHTCX temperature and humidity sensor support for Tasmota
|
||||
|
||||
Copyright (C) 2022 Theo Arends, Stefan Tibus
|
||||
Copyright (C) 2024 Theo Arends, Stefan Tibus, Jan-David Förster
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,19 +25,19 @@
|
|||
* This driver supports the following sensors:
|
||||
* - SHT3x series: SHT30, SHT31, SHT35 (addresses: A: 0x44, B: 0x45)
|
||||
* - SHTC series: SHTC1, SHTC3 (address: 0x70)
|
||||
* - SHT4x series: SHT40, SHT41, SHT45 (addresses: A: 0x44, B: 0x45)
|
||||
* - SHT4x series: SHT40, SHT41, SHT45 (addresses: A: 0x44, B: 0x45, C: 0x46)
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define XSNS_14 14
|
||||
#define XI2C_15 15 // See I2CDEVICES.md
|
||||
|
||||
#define SHT3X_TYPES 3 // SHT3X, SHTCX and SHT4X
|
||||
#define SHT3X_ADDRESSES 3 // 0x44, 0x45 and 0x70
|
||||
#define SHT3X_ADDRESSES 4 // 0x44, 0x45, 0x46 and 0x70
|
||||
|
||||
enum SHT3X_Types { SHT3X_TYPE_SHT3X, SHT3X_TYPE_SHTCX, SHT3X_TYPE_SHT4X };
|
||||
const char kSht3xTypes[] PROGMEM = "SHT3X|SHTC3|SHT4X";
|
||||
|
||||
uint8_t sht3x_addresses[] = { 0x44, 0x45, 0x70 };
|
||||
uint8_t sht3x_addresses[] = { 0x44, 0x45, 0x46, 0x70 };
|
||||
|
||||
uint8_t sht3x_count = 0;
|
||||
struct SHT3XSTRUCT {
|
||||
|
@ -121,9 +121,9 @@ void Sht3xDetect(void) {
|
|||
|
||||
for (uint32_t bus = 0; bus < 2; bus++) {
|
||||
for (uint32_t k = 0; k < SHT3X_TYPES; k++) {
|
||||
sht3x_sensors[sht3x_count].type = k;
|
||||
for (uint32_t i = 0; i < SHT3X_ADDRESSES; i++) {
|
||||
if (!I2cSetDevice(sht3x_addresses[i], bus)) { continue; }
|
||||
sht3x_sensors[sht3x_count].type = k;
|
||||
sht3x_sensors[sht3x_count].address = sht3x_addresses[i];
|
||||
sht3x_sensors[sht3x_count].bus = bus;
|
||||
if (Sht3xRead(sht3x_count, t, h)) {
|
||||
|
@ -144,15 +144,25 @@ void Sht3xShow(bool json) {
|
|||
float h;
|
||||
char types[11];
|
||||
|
||||
for (uint32_t i = 0; i < sht3x_count; i++) {
|
||||
if (Sht3xRead(i, t, h)) {
|
||||
for (uint32_t idx = 0; idx < sht3x_count; idx++) {
|
||||
if (Sht3xRead(idx, t, h)) {
|
||||
t = ConvertTemp(t);
|
||||
h = ConvertHumidity(h);
|
||||
strlcpy(types, sht3x_sensors[i].types, sizeof(types));
|
||||
strlcpy(types, sht3x_sensors[idx].types, sizeof(types));
|
||||
if (sht3x_count > 1) {
|
||||
snprintf_P(types, sizeof(types), PSTR("%s%c%02X"), sht3x_sensors[i].types, IndexSeparator(), sht3x_sensors[i].address); // "SHT3X-0xXX"
|
||||
snprintf_P(types, sizeof(types), PSTR("%s%c%02X"), types, IndexSeparator(), sht3x_sensors[idx].address); // "SHT3X-0xXX"
|
||||
#ifdef ESP32
|
||||
if (TasmotaGlobal.i2c_enabled_2) {
|
||||
for (uint32_t i = 1; i < sht3x_count; i++) {
|
||||
if (sht3x_sensors[0].bus != sht3x_sensors[i].bus) {
|
||||
snprintf_P(types, sizeof(types), PSTR("%s%c%d"), types, IndexSeparator(), sht3x_sensors[idx].bus + 1); // "SHT3X-0xXX-X"
|
||||
break;
|
||||
}
|
||||
TempHumDewShow(json, ((0 == TasmotaGlobal.tele_period) && (0 == i)), types, t, h);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
TempHumDewShow(json, ((0 == TasmotaGlobal.tele_period) && (0 == idx)), types, t, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue