From ada2713a6c384b98cd5285a10e82f76524c9c383 Mon Sep 17 00:00:00 2001 From: Quentin Fisch Date: Fri, 26 Apr 2024 11:42:33 +0200 Subject: [PATCH 1/2] Use latest SHT4x driver --- examples/hacksterExample/platformio.ini | 3 +-- platformio.ini | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/hacksterExample/platformio.ini b/examples/hacksterExample/platformio.ini index d451adf..0caed9b 100644 --- a/examples/hacksterExample/platformio.ini +++ b/examples/hacksterExample/platformio.ini @@ -17,8 +17,7 @@ monitor_speed = 115200 lib_deps = Sensirion/Sensirion Core Sensirion/Sensirion UPT Core - ; Depends on version 0.1.0 (Newer versions have incompatible API) - Sensirion/Sensirion I2C SHT4x@0.1.0 + Sensirion/Sensirion I2C SHT4x Sensirion/Sensirion I2C SCD4x Sensirion/Sensirion I2C SFA3x Sensirion/Sensirion I2C SVM4x diff --git a/platformio.ini b/platformio.ini index 5971fdb..9f524f1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,8 +15,7 @@ default_envs = basicUsage lib_deps_external = Sensirion/Sensirion Core Sensirion/Sensirion UPT Core - ; Newer versions of the SHT4X driver have an incompatible API - Sensirion/Sensirion I2C SHT4x@0.1.0 + Sensirion/Sensirion I2C SHT4x Sensirion/Sensirion I2C SCD4x Sensirion/Sensirion I2C SFA3x Sensirion/Sensirion I2C SVM4x From 3eb784be44c9ade0f9faba9ddff19f7582a95a2d Mon Sep 17 00:00:00 2001 From: Quentin Fisch Date: Fri, 26 Apr 2024 11:44:04 +0200 Subject: [PATCH 2/2] Update STC3x and SHT4x wrappers to support latest driver version --- src/SensorWrappers/Sht4x.cpp | 2 +- src/SensorWrappers/Sht4x.h | 4 ++-- src/SensorWrappers/Stc3x.cpp | 33 +++++++++++++-------------------- src/SensorWrappers/Stc3x.h | 4 ++-- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/SensorWrappers/Sht4x.cpp b/src/SensorWrappers/Sht4x.cpp index 6589615..b313278 100644 --- a/src/SensorWrappers/Sht4x.cpp +++ b/src/SensorWrappers/Sht4x.cpp @@ -8,7 +8,7 @@ Sht4x::Sht4x(TwoWire& wire) : _wire(wire) { }; uint16_t Sht4x::start() { - _driver.begin(_wire); + _driver.begin(_wire, I2C_ADDRESS); return HighLevelError::NoError; } diff --git a/src/SensorWrappers/Sht4x.h b/src/SensorWrappers/Sht4x.h index 3bc6f05..d77ba21 100644 --- a/src/SensorWrappers/Sht4x.h +++ b/src/SensorWrappers/Sht4x.h @@ -2,7 +2,7 @@ #define _SHT4X_H_ #include "ISensor.h" -#include "SensirionI2CSht4x.h" +#include "SensirionI2cSht4x.h" #include "Sensirion_UPT_Core.h" class Sht4x : public ISensor { @@ -21,7 +21,7 @@ class Sht4x : public ISensor { private: TwoWire& _wire; - SensirionI2CSht4x _driver; + SensirionI2cSht4x _driver; MetaData _metaData; }; diff --git a/src/SensorWrappers/Stc3x.cpp b/src/SensorWrappers/Stc3x.cpp index 50a8df9..281c286 100644 --- a/src/SensorWrappers/Stc3x.cpp +++ b/src/SensorWrappers/Stc3x.cpp @@ -9,18 +9,18 @@ Stc3x::Stc3x(TwoWire& wire) : _wire(wire) { }; uint16_t Stc3x::start() { - _driver.begin(_wire); + _driver.begin(_wire, I2C_ADDRESS); uint16_t error = _driver.setBinaryGas(0x0001); return error; } uint16_t Stc3x::measureAndWrite(Measurement measurements[], const unsigned long timeStamp) { - uint16_t gasTicks; - uint16_t temperatureTicks; + float gasValue; + float temperatureValue; uint16_t error = - _driver.measureGasConcentration(gasTicks, temperatureTicks); + _driver.measureGasConcentration(gasValue, temperatureValue); if (error) { return error; } @@ -28,14 +28,12 @@ uint16_t Stc3x::measureAndWrite(Measurement measurements[], measurements[0].signalType = SignalType::GAS_CONCENTRATION_VOLUME_PERCENTAGE; measurements[0].dataPoint.t_offset = timeStamp; - measurements[0].dataPoint.value = - 100 * (static_cast(gasTicks) - 16384.0) / 32768.0; + measurements[0].dataPoint.value = gasValue; measurements[0].metaData = _metaData; measurements[1].signalType = SignalType::TEMPERATURE_DEGREES_CELSIUS; measurements[1].dataPoint.t_offset = timeStamp; - measurements[1].dataPoint.value = - static_cast(temperatureTicks) / 200.0; + measurements[1].dataPoint.value = temperatureValue; measurements[1].metaData = _metaData; return HighLevelError::NoError; @@ -48,11 +46,12 @@ uint16_t Stc3x::initializationStep() { } uint32_t productNumber; - uint8_t serialNumberRaw[32]; - uint8_t serialNumberSize = 32; + uint32_t serialNumberRawLow; + uint32_t serialNumberRawHigh; + + error = _driver.readProductIdentifier(productNumber, serialNumberRawHigh, + serialNumberRawLow); - error = _driver.readProductIdentifier(productNumber, serialNumberRaw, - serialNumberSize); if (error) { return error; } @@ -72,14 +71,8 @@ uint16_t Stc3x::initializationStep() { // Sensor Serial No uint64_t sensorID = 0; - sensorID |= (uint64_t)serialNumberRaw[0] << 56 | - (uint64_t)serialNumberRaw[1] << 48 | - (uint64_t)serialNumberRaw[2] << 40 | - (uint64_t)serialNumberRaw[3] << 32 | - (uint64_t)serialNumberRaw[4] << 24 | - (uint64_t)serialNumberRaw[5] << 16 | - (uint64_t)serialNumberRaw[6] << 8 | - (uint64_t)serialNumberRaw[7]; + sensorID |= + (uint64_t)serialNumberRawHigh << 32 | (uint64_t)serialNumberRawLow; _metaData.deviceID = sensorID; // Select gas mode diff --git a/src/SensorWrappers/Stc3x.h b/src/SensorWrappers/Stc3x.h index e87423e..9fbeb8f 100644 --- a/src/SensorWrappers/Stc3x.h +++ b/src/SensorWrappers/Stc3x.h @@ -3,7 +3,7 @@ #include "ISensor.h" #include "Sensirion_UPT_Core.h" -#include +#include class Stc3x : public ISensor { public: @@ -21,7 +21,7 @@ class Stc3x : public ISensor { private: TwoWire& _wire; - SensirionI2CStc3x _driver; + SensirionI2cStc3x _driver; MetaData _metaData; };