From c416d74d8c65f423b4e6625a8243448bb23f5826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Fri, 24 Apr 2026 23:05:00 +0200 Subject: [PATCH] Add support for Grove sensor SHT31 New support for yet another sensor for measuring temperature and humidity. That is another part sold by SeedStudio and provides similar readings to SHT4X. --- platformio.ini | 2 ++ .../sensors/EnvironmentSensorManager.cpp | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/platformio.ini b/platformio.ini index f3ada13386..751e466171 100644 --- a/platformio.ini +++ b/platformio.ini @@ -127,6 +127,7 @@ build_flags = -D ENV_INCLUDE_BME280=1 -D ENV_INCLUDE_BMP280=1 -D ENV_INCLUDE_SHTC3=1 + -D ENV_INCLUDE_SHT31=1 -D ENV_INCLUDE_SHT4X=1 -D ENV_INCLUDE_LPS22HB=1 -D ENV_INCLUDE_INA3221=1 @@ -146,6 +147,7 @@ lib_deps = adafruit/Adafruit BME280 Library @ ^2.3.0 adafruit/Adafruit BMP280 Library @ ^2.6.8 adafruit/Adafruit SHTC3 Library @ ^1.0.1 + adafruit/Adafruit SHT31 Library @ ^2.2.2 sensirion/Sensirion I2C SHT4x @ ^1.1.2 arduino-libraries/Arduino_LPS22HB @ ^1.0.2 adafruit/Adafruit MLX90614 Library @ ^2.1.5 diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index e2f0d33e72..93420bd547 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -83,6 +83,14 @@ static Adafruit_BMP280 BMP280(TELEM_WIRE); static Adafruit_SHTC3 SHTC3; #endif +#if ENV_INCLUDE_SHT31 +#ifndef TELEM_SHT31_ADDRESS +#define TELEM_SHT31_ADDRESS 0x44 // SHT31 environmental sensor I2C address +#endif +#include +static Adafruit_SHT31 SHT31; +#endif + #if ENV_INCLUDE_SHT4X #ifndef TELEM_SHT4X_ADDRESS #define TELEM_SHT4X_ADDRESS 0x44 @@ -331,6 +339,21 @@ static void query_sht4x(uint8_t ch, uint8_t, CayenneLPP& lpp) { } #endif +#if ENV_INCLUDE_SHT31 +static uint8_t init_sht3x(TwoWire* wire, uint8_t addr) { + return SHT31.begin(addr) ? 1 : 0; +} + +static void query_sht3x(uint8_t ch, uint8_t, CayenneLPP& lpp) { + float temp, humidity; + + if (SHT31.readBoth(&temp, &humidity)) { + lpp.addTemperature(ch, temp); + lpp.addRelativeHumidity(ch, humidity); + } +} +#endif + #if ENV_INCLUDE_LPS22HB static uint8_t init_lps22hb(TwoWire*, uint8_t) { // LPS22HBClass is constructed with the wire reference; begin() uses it. @@ -570,9 +593,13 @@ static const SensorDef SENSOR_TABLE[] = { #if ENV_INCLUDE_SHTC3 { 0x70, "SHTC3", init_shtc3, query_shtc3 }, #endif + #if ENV_INCLUDE_SHT4X { TELEM_SHT4X_ADDRESS, "SHT4X", init_sht4x, query_sht4x }, #endif +#if ENV_INCLUDE_SHT31 + { TELEM_SHT31_ADDRESS, "SHT3X", init_sht3x, query_sht3x }, +#endif #if ENV_INCLUDE_LPS22HB { 0x5C, "LPS22HB", init_lps22hb, query_lps22hb }, #endif