Skip to content

Commit 664cdeb

Browse files
committed
v5.12.0b - Add support for sensor SHTC3
5.12.0b * Add support for sensor SHTC3 (#1967)
1 parent 77be563 commit 664cdeb

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

sonoff/_releasenotes.ino

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Change Sonoff SC JSON format (#1939)
1414
* Fix compile error when define HOME_ASSISTANT_DISCOVERY_ENABLE is not set (#1937)
1515
* Add optional TSL2561 driver using library Joba_Tsl2561 to be enabled in user_config.h with define USE_TSL2561_JOBA (#1951)
16+
* Add support for sensor SHTC3 (#1967)
1617
*
1718
* 5.12.0a
1819
* Change platformio option sonoff-ds18x20 to sonoff-xxl enabling ds18x20 and all other sensors in one image

sonoff/user_config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)
184184
#ifdef USE_I2C
185185
#define USE_SHT // Add I2C emulating code for SHT1X sensor (+1k4 code)
186-
#define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code)
186+
#define USE_SHT3X // Add I2C code for SHT3x or SHTC3 sensor (+0k7 code)
187187
#define USE_HTU // Add I2C code for HTU21/SI7013/SI7020/SI7021 sensor (+1k5 code)
188188
#define USE_BMP // Add I2C code for BMP085/BMP180/BMP280/BME280 sensor (+4k code)
189189
// #define USE_BME680 // Add additional support for BME680 sensor using Adafruit Sensor and BME680 libraries (+6k code)

sonoff/xsns_14_sht3x.ino

+23-9
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020
#ifdef USE_I2C
2121
#ifdef USE_SHT3X
2222
/*********************************************************************************************\
23-
* SHT3X - Temperature and Humidy
23+
* SHT3X and SHTC3 - Temperature and Humidy
2424
*
25-
* I2C Address: 0x44 or 0x45
25+
* I2C Address: 0x44, 0x45 or 0x70 (SHTC3)
2626
\*********************************************************************************************/
2727

2828
#define SHT3X_ADDR_GND 0x44 // address pin low (GND)
2929
#define SHT3X_ADDR_VDD 0x45 // address pin high (VDD)
30+
#define SHTC3_ADDR 0x70 // address for shtc3 sensor
31+
32+
const char kShtTypes[] PROGMEM = "SHT3X|SHT3X|SHTC3";
3033

3134
uint8_t sht3x_type = 0;
3235
uint8_t sht3x_address;
33-
uint8_t sht3x_addresses[] = { SHT3X_ADDR_GND, SHT3X_ADDR_VDD };
36+
uint8_t sht3x_addresses[] = { SHT3X_ADDR_GND, SHT3X_ADDR_VDD, SHTC3_ADDR };
37+
char sht3x_types[6];
3438

3539
bool Sht3xRead(float &t, float &h)
3640
{
@@ -40,8 +44,17 @@ bool Sht3xRead(float &t, float &h)
4044
h = NAN;
4145

4246
Wire.beginTransmission(sht3x_address);
43-
Wire.write(0x2C); // Enable clock stretching
44-
Wire.write(0x06); // High repeatability
47+
if (SHTC3_ADDR == sht3x_address) {
48+
Wire.write(0x35); // Wake from
49+
Wire.write(0x17); // sleep
50+
Wire.endTransmission();
51+
Wire.beginTransmission(sht3x_address);
52+
Wire.write(0x78); // Dissable clock stretching ( I don't think that wire library support clock stretching )
53+
Wire.write(0x66); // High resolution
54+
} else {
55+
Wire.write(0x2C); // Enable clock stretching
56+
Wire.write(0x06); // High repeatability
57+
}
4558
if (Wire.endTransmission() != 0) { // Stop I2C transmission
4659
return false;
4760
}
@@ -69,7 +82,8 @@ void Sht3xDetect()
6982
for (byte i = 0; i < sizeof(sht3x_addresses); i++) {
7083
sht3x_address = sht3x_addresses[i];
7184
if (Sht3xRead(t, h)) {
72-
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "SHT3X", sht3x_address);
85+
GetTextIndexed(sht3x_types, sizeof(sht3x_types), i, kShtTypes);
86+
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, sht3x_types, htu_address);
7387
AddLog(LOG_LEVEL_DEBUG);
7488
return;
7589
}
@@ -89,14 +103,14 @@ void Sht3xShow(boolean json)
89103
dtostrfd(h, Settings.flag2.humidity_resolution, humidity);
90104

91105
if (json) {
92-
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT3X", temperature, humidity);
106+
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, sht3x_types, temperature, humidity);
93107
#ifdef USE_DOMOTICZ
94108
DomoticzTempHumSensor(temperature, humidity);
95109
#endif // USE_DOMOTICZ
96110
#ifdef USE_WEBSERVER
97111
} else {
98-
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, "SHT3X", temperature, TempUnit());
99-
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, "SHT3X", humidity);
112+
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_TEMP, mqtt_data, sht3x_types, temperature, TempUnit());
113+
snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_HUM, mqtt_data, sht3x_types, humidity);
100114
#endif // USE_WEBSERVER
101115
}
102116
}

0 commit comments

Comments
 (0)