Skip to content

Commit 18ec28b

Browse files
committed
Fix SHT4x driver
1 parent 09095e5 commit 18ec28b

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, RTClib, StreamUtils, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, SdFat - Adafruit Fork, Adafruit GFX Library
10+
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, RTClib, StreamUtils, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, SdFat - Adafruit Fork, Adafruit GFX Library, Adafruit SHT4x Library

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ lib_deps =
8080
https://github.com/adafruit/RTClib.git
8181
https://github.com/bblanchon/ArduinoStreamUtils.git
8282
https://github.com/Sensirion/arduino-i2c-scd4x.git
83+
Adafruit SHT4x Library
8384

8485
; Common build environment for ESP32 platform
8586
[common:esp32]

src/Wippersnapper_V2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
#endif
128128

129129
#define WS_VERSION \
130-
"1.0.0-offline-beta.1" ///< WipperSnapper app. version (semver-formatted)
130+
"1.0.0-offline-beta.2" ///< WipperSnapper app. version (semver-formatted)
131131

132132
#define WS_WDT_TIMEOUT 60000 ///< WDT timeout
133133
#define WS_MAX_ALT_WIFI_NETWORKS 3 ///< Maximum number of alternative networks

src/components/i2c/controller.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
634634
->i2c_device_description.i2c_bus_sda);
635635
WS_DEBUG_PRINTLN("[i2c] Set driver to use Alt I2C bus");
636636
}
637+
637638
// Configure the driver
638639
drv->EnableSensorReads(
639640
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_sensor_types,

src/components/i2c/drivers/drvSht4x.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
#ifndef DRV_SHT4X_H
1919
#define DRV_SHT4X_H
2020

21+
#include "Adafruit_SHT4x.h"
2122
#include "drvBase.h"
22-
#include <SHTSensor.h>
23-
#include <Wire.h>
2423

2524
/**************************************************************************/
2625
/*!
@@ -56,13 +55,12 @@ class drvSht4x : public drvBase {
5655
*/
5756
/*******************************************************************************/
5857
bool begin() override {
59-
_sht4x = new SHTSensor(SHTSensor::SHT4X);
60-
if (!_sht4x->init(*_i2c))
58+
_sht4x = new Adafruit_SHT4x();
59+
if (!_sht4x->begin(_i2c))
6160
return false;
6261

63-
// configure SHT4x sensor
64-
_sht4x->setAccuracy(SHTSensor::SHT_ACCURACY_HIGH);
65-
62+
_sht4x->setPrecision(SHT4X_HIGH_PRECISION);
63+
_sht4x->setHeater(SHT4X_NO_HEATER);
6664
return true;
6765
}
6866

@@ -76,10 +74,11 @@ class drvSht4x : public drvBase {
7674
*/
7775
/*******************************************************************************/
7876
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
79-
// populate temp and humidity objects with fresh data
80-
if (!_sht4x->readSample())
81-
return false;
82-
tempEvent->temperature = _sht4x->getTemperature();
77+
sensors_event_t humidity;
78+
_sht4x->getEvent(
79+
&humidity,
80+
tempEvent); // populate temp and humidity objects with fresh data
81+
// tempEvent->temperature = tempEvent->temperature;
8382
return true;
8483
}
8584

@@ -93,15 +92,17 @@ class drvSht4x : public drvBase {
9392
*/
9493
/*******************************************************************************/
9594
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
96-
// populate temp and humidity objects with fresh data
97-
if (!_sht4x->readSample())
98-
return false;
99-
humidEvent->relative_humidity = _sht4x->getHumidity();
95+
sensors_event_t temperature;
96+
_sht4x->getEvent(
97+
humidEvent,
98+
&temperature); // populate temp and humidity objects with fresh data
99+
// tempEvent->temperature = tempEvent->temperature;
100+
// humidEvent->relative_humidity = humidEvent->relative_humidity;
100101
return true;
101102
}
102103

103104
protected:
104-
SHTSensor *_sht4x; ///< SHT4X object
105+
Adafruit_SHT4x *_sht4x; ///< Adafruit_SHT4x object
105106
};
106107

107108
#endif // drvSht4x

0 commit comments

Comments
 (0)