Skip to content

Commit

Permalink
Merge pull request #15 from Sensirion/add-support-for-sen66
Browse files Browse the repository at this point in the history
Add support for sen66
  • Loading branch information
psachs authored Jan 16, 2025
2 parents b389cb9 + 594719f commit c0a904c
Show file tree
Hide file tree
Showing 22 changed files with 460 additions and 252 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0]

### Added

- Add support for SEN66

## [0.2.0]

### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Arduino Library for automatic detection of Sensirion sensors on an I2C Bus. It a
- SHT4X
- STC3X
- SVM4X
- SEN66

### Sensor Oddities

Expand Down Expand Up @@ -51,6 +52,7 @@ Search for the `Sensirion UPT I2C Auto Detection` library in the `Filter your se
- [Sensirion I2C SCD30](https://www.arduino.cc/reference/en/libraries/sensirion-i2c-scd30/)
- [Sensirion I2C SGP41](https://www.arduino.cc/reference/en/libraries/sensirion-i2c-sgp41/)
- [Sensirion I2C STC3x](https://www.arduino.cc/reference/en/libraries/sensirion-i2c-stc3x/)
- [Sensirion I2C SEN66](https://www.arduino.cc/reference/en/libraries/sensirion-i2c-sen66/)

Alternatively, the library can also be added manually. To do this, download the latest release from github as a .zip file via

Expand Down Expand Up @@ -120,6 +122,7 @@ This library uses the following dependencies.
- [SHT4X](https://github.com/Sensirion/arduino-i2c-sht4x)
- [SVM40](https://github.com/Sensirion/arduino-i2c-svm40)
- [STC3X](https://github.com/Sensirion/arduino-i2c-stc3x)
- [SEN66](https://github.com/Sensirion/arduino-i2c-sen66)

In case automatic dependency installation doesn't work, you will have to install them manually.

Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Sensirion UPT I2C Auto Detection
version=0.2.0
version=0.3.0
author=Jonas Stolle, Maximilian Paulsen
maintainer=Sensirion AG <sensirion.com>
sentence=Automatically detects Sensirion Sensors on an I2C bus and reads out measurement data.
Expand All @@ -8,4 +8,4 @@ category=Sensors
architectures=esp32
url=https://github.com/Sensirion/arduino-upt-i2c-auto-detection
includes=Sensirion_upt_i2c_auto_detection.h
depends=Sensirion Core, Sensirion UPT Core, Sensirion I2C SCD4x, Sensirion I2C SFA3x, Sensirion I2C SVM4x, Sensirion I2C SHT4x, Sensirion I2C SEN5X, Sensirion I2C SCD30, Sensirion I2C SGP41, Sensirion I2C STC3x
depends=Sensirion Core, Sensirion UPT Core, Sensirion I2C SCD4x, Sensirion I2C SFA3x, Sensirion I2C SVM4x, Sensirion I2C SHT4x, Sensirion I2C SEN5X, Sensirion I2C SCD30, Sensirion I2C SGP41, Sensirion I2C STC3x, Sensirion I2C SEN66
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lib_deps_external =
Sensirion/Sensirion I2C SCD30
Sensirion/Sensirion I2C SGP41
Sensirion/Sensirion I2C STC3x
Sensirion/Sensirion I2C SEN66
basicUsage_srcdir = ${PROJECT_DIR}/examples/basicUsage/
advancedUsage_srcdir = ${PROJECT_DIR}/examples/advancedUsage/
hacksterExample_srcdir = ${PROJECT_DIR}/examples/hacksterExample/
Expand Down
8 changes: 4 additions & 4 deletions src/AutoDetectorErrors.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _AUTO_DETECTOR_ERRORS_H_
#define _AUTO_DETECTOR_ERRORS_H_
#ifndef AUTO_DETECTOR_ERRORS_H
#define AUTO_DETECTOR_ERRORS_H

#include <stdint.h>
#include <cstdint>

enum AutoDetectorError : uint16_t {
NO_ERROR = 0,
Expand All @@ -11,4 +11,4 @@ enum AutoDetectorError : uint16_t {
I2C_ERROR = 4
};

#endif /* _AUTO_DETECTOR_ERRORS_H_ */
#endif /* AUTO_DETECTOR_ERRORS_H */
7 changes: 4 additions & 3 deletions src/DriverConfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _DRIVER_CONFIG_H_
#define _DRIVER_CONFIG_H_
#ifndef DRIVER_CONFIG_H
#define DRIVER_CONFIG_H

// Comment out lines to remove unwanted drivers

Expand All @@ -11,5 +11,6 @@
#define INCLUDE_SHT4X_DRIVER
#define INCLUDE_STC3X_DRIVER
#define INCLUDE_SVM4X_DRIVER
#define INCLUDE_SEN66_DRIVER

#endif /* _DRIVER_CONFIG_H_ */
#endif /* DRIVER_CONFIG_H */
28 changes: 18 additions & 10 deletions src/I2CAutoDetector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "I2CAutoDetector.h"
#include "AutoDetectorErrors.h"
#include "DriverConfig.h"
#include "SensirionCore.h"

Expand Down Expand Up @@ -27,10 +26,13 @@
#ifdef INCLUDE_SVM4X_DRIVER
#include "SensorWrappers/Svm4x.h"
#endif
#ifdef INCLUDE_SEN66_DRIVER
#include "SensorWrappers/Sen66.h"
#endif

void I2CAutoDetector::findSensors(SensorList& sensorList) {
for (byte address = 1; address < 127; address++) {
auto st = probeAddress(address);
const auto st = probeAddress(address);
if (st == SensorType::UNDEFINED) {
continue;
}
Expand All @@ -50,17 +52,18 @@ void I2CAutoDetector::findSensors(SensorList& sensorList) {
* Private methods
*/

SensorType I2CAutoDetector::probeAddress(const byte& address) {
SensorType I2CAutoDetector::probeAddress(const byte& address) const {
_wire.beginTransmission(address);
byte error = _wire.endTransmission();
if (error){
const byte error = _wire.endTransmission();
if (error) {
return SensorType::UNDEFINED;
}
return getSensorTypeFromAddress(address);
}

ISensor* I2CAutoDetector::createSensorFromSensorType(SensorType sensor_type) {
switch (sensor_type) {
ISensor*
I2CAutoDetector::createSensorFromSensorType(const SensorType sensorType) const {
switch (sensorType) {
case (SensorType::SCD30): {
return new Scd30(_wire);
}
Expand All @@ -86,13 +89,15 @@ ISensor* I2CAutoDetector::createSensorFromSensorType(SensorType sensor_type) {
case (SensorType::SVM4X): {
return new Svm4x(_wire);
}
case (SensorType::SEN66): {
return new Sen66(_wire);
}
default: {
return nullptr;
}
}
}


SensorType I2CAutoDetector::getSensorTypeFromAddress(const byte address) {
switch (address) {
#ifdef INCLUDE_SCD30_DRIVER
Expand Down Expand Up @@ -134,11 +139,14 @@ SensorType I2CAutoDetector::getSensorTypeFromAddress(const byte address) {
case (Svm4x::I2C_ADDRESS): {
return SensorType::SVM4X;
}
#endif
#ifdef INCLUDE_SEN66_DRIVER
case (Sen66::I2C_ADDRESS): {
return SensorType::SEN66;
}
#endif
default: {
return SensorType::UNDEFINED;
}
}
}


16 changes: 8 additions & 8 deletions src/I2CAutoDetector.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _I2C_AUTO_DETECTOR_H_
#define _I2C_AUTO_DETECTOR_H_
#ifndef I2C_AUTO_DETECTOR_H
#define I2C_AUTO_DETECTOR_H

#include "IAutoDetector.h"
#include <Wire.h>
Expand All @@ -11,15 +11,15 @@ class I2CAutoDetector : public IAutoDetector {
/**
* @brief scan i2c bus for available sensors
*
* @param SensorList& SensorList to which add the found sensors
* @param sensorList SensorList to which add the found sensors
*/
void findSensors(SensorList& sensorList) override;

private:
TwoWire& _wire;
SensorType probeAddress(const byte& address);
ISensor* createSensorFromSensorType(SensorType sensor_type);
SensorType getSensorTypeFromAddress(const byte address);
SensorType probeAddress(const byte& address) const;
ISensor* createSensorFromSensorType(SensorType sensorType) const;
static SensorType getSensorTypeFromAddress(byte address);
};

#endif /* _I2C_AUTO_DETECTOR_H_ */
#endif /* I2C_AUTO_DETECTOR_H */
7 changes: 4 additions & 3 deletions src/IAutoDetector.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#ifndef _I_AUTO_DETECTOR_
#define _I_AUTO_DETECTOR_
#ifndef I_AUTO_DETECTOR
#define I_AUTO_DETECTOR

#include "SensorList.h"

class IAutoDetector {
public:
virtual ~IAutoDetector() = default;
/**
* @brief Scans bus for Sensirion sensors, initializes them and
* adds them to the passed sensor list.
Expand All @@ -18,4 +19,4 @@ class IAutoDetector {
virtual void findSensors(SensorList& sensorList) = 0;
};

#endif /* _I_AUTO_DETECTOR_ */
#endif /* I_AUTO_DETECTOR */
22 changes: 11 additions & 11 deletions src/ISensor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _I_SENSOR_H_
#define _I_SENSOR_H_
#ifndef I_SENSOR_H
#define I_SENSOR_H

#include "Arduino.h"
#include "Sensirion_UPT_Core.h"
Expand All @@ -8,7 +8,7 @@
* bus */
class ISensor {
private:
static const uint16_t _NUMBER_OF_ALLOWED_CONSECUTIVE_ERRORS = 3;
static constexpr uint16_t NUMBER_OF_ALLOWED_CONSECUTIVE_ERRORS = 3;

public:
virtual ~ISensor() = default;
Expand Down Expand Up @@ -56,7 +56,7 @@ class ISensor {
* SensirionCore, where 0 value corresponds to no error.
*/
virtual uint16_t measureAndWrite(Measurement measurements[],
const unsigned long timeStamp) = 0;
unsigned long timeStamp) = 0;

/**
* @brief Get the minimum measurement interval of the sensor. This must be
Expand All @@ -71,11 +71,11 @@ class ISensor {
*
* Some sensors that require special hardware for the measurement (such as
* heaters) need to regularly be called for measurements, or else the
* conditioning procedure must be exectued again. The time interval within
* conditioning procedure must be executed again. The time interval within
* which the sensor must be called for a reading can be queried with this
* method.
*
* @param[out] long time (in ms) within which the sensor must be called for
* @returns Time (in ms) within which the sensor must be called for
* a measurement, else it decays to the UNINITIALIZED state. Returns -1 if
* no such interval is defined for the sensor (ie. decay time is infinite).
*/
Expand All @@ -100,17 +100,17 @@ class ISensor {
/**
* @brief getter method for _NUMBER_OF_ALLOWED_CONSECUTIVE_ERRORS
*/
uint16_t getNumberOfAllowedConsecutiveErrors() const {
return _NUMBER_OF_ALLOWED_CONSECUTIVE_ERRORS;
static uint16_t getNumberOfAllowedConsecutiveErrors() {
return NUMBER_OF_ALLOWED_CONSECUTIVE_ERRORS;
}

/**
* @brief Get a pointer to the sensordriver, reinterpret_cast-ed into a void
* pointer
* @brief Get a pointer to the sensor driver, reinterpret_cast-ed into a
* void pointer
*
* @return void*
*/
virtual void* getDriver() = 0;
};

#endif /* _I_SENSOR_H_ */
#endif /* I_SENSOR_H */
40 changes: 20 additions & 20 deletions src/MeasurementList.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
#include "MeasurementList.h"

void MeasurementList::init(const size_t& length) {
_length = length;
delete[] _measurements;
_measurements = new Measurement[_length];
mLength = length;
delete[] mMeasurements;
mMeasurements = new Measurement[mLength];
}

size_t MeasurementList::getLength() const {
return _length;
return mLength;
}

MeasurementList::~MeasurementList() {
delete[] _measurements;
delete[] mMeasurements;
}

MeasurementList::MeasurementList(const MeasurementList& other)
: _length(other._length) {
_measurements = new Measurement[_length];
for (size_t i = 0; i < _length; i++) {
_measurements[i] = other._measurements[i];
: mLength(other.mLength) {
mMeasurements = new Measurement[mLength];
for (size_t i = 0; i < mLength; i++) {
mMeasurements[i] = other.mMeasurements[i];
}
}

MeasurementList& MeasurementList::operator=(const MeasurementList& other) {
if (&other != this) {
delete[] _measurements;
delete[] mMeasurements;

_length = other._length;
_measurements = new Measurement[_length];
for (size_t i = 0; i < _length; i++) {
_measurements[i] = other._measurements[i];
mLength = other.mLength;
mMeasurements = new Measurement[mLength];
for (size_t i = 0; i < mLength; i++) {
mMeasurements[i] = other.mMeasurements[i];
}
_writeHead = other._writeHead;
mWriteHead = other.mWriteHead;
}
return *this;
}

void MeasurementList::addMeasurement(const Measurement& m) {
if (_writeHead < _length) {
_measurements[_writeHead] = m;
_writeHead++;
if (mWriteHead < mLength) {
mMeasurements[mWriteHead] = m;
mWriteHead++;
}
}

Measurement MeasurementList::getMeasurement(size_t i) const {
return _measurements[i];
return mMeasurements[i];
}

void MeasurementList::resetWriteHead() {
_writeHead = 0;
mWriteHead = 0;
}
12 changes: 6 additions & 6 deletions src/MeasurementList.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _MEASUREMENT_LIST_H_
#define _MEASUREMENT_LIST_H_
#ifndef MEASUREMENT_LIST_H
#define MEASUREMENT_LIST_H

#include "Sensirion_UPT_Core.h"

Expand Down Expand Up @@ -42,9 +42,9 @@ class MeasurementList {
void resetWriteHead();

private:
size_t _length = 0;
size_t _writeHead = 0;
Measurement* _measurements = nullptr;
size_t mLength = 0;
size_t mWriteHead = 0;
Measurement* mMeasurements = nullptr;
};

#endif /* _MEASUREMENT_LIST_H_ */
#endif /* MEASUREMENT_LIST_H */
6 changes: 3 additions & 3 deletions src/Sensirion_upt_i2c_auto_detection.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _SENSIRION_UPT_I2C_AUTO_DETECTION_H_
#define _SENSIRION_UPT_I2C_AUTO_DETECTION_H_
#ifndef SENSIRION_UPT_I2C_AUTO_DETECTION_H
#define SENSIRION_UPT_I2C_AUTO_DETECTION_H

#include "I2CAutoDetector.h"
#include "Sensirion_UPT_Core.h"
#include "SensorManager.h"
#include <Arduino.h>

#endif /* _SENSIRION_UPT_I2C_AUTO_DETECTION_H_ */
#endif /* SENSIRION_UPT_I2C_AUTO_DETECTION_H */
Loading

0 comments on commit c0a904c

Please sign in to comment.