17 #ifndef WipperSnapper_I2C_Driver_SCD4X_H 18 #define WipperSnapper_I2C_Driver_SCD4X_H 21 #include <SensirionI2cScd4x.h> 54 _scd =
new SensirionI2cScd4x();
58 if (
_scd->stopPeriodicMeasurement() != 0) {
63 if (
_scd->startPeriodicMeasurement() != 0) {
87 bool isDataReady =
false;
88 for (
int i = 0; i < 2; i++) {
89 uint16_t error =
_scd->getDataReadyStatus(isDataReady);
90 if (error == 0 && isDataReady) {
116 float temperature = 0;
118 int16_t error =
_scd->readMeasurement(co2, temperature, humidity);
119 if (error != 0 || co2 == 0) {
187 SensirionI2cScd4x *
_scd =
nullptr;
194 #endif // WipperSnapper_I2C_Driver_SCD4X_H Class that provides a driver interface for the SCD40 sensor.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:29
SensirionI2cScd4x * _scd
SCD4x driver object.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:187
WipperSnapper_I2C_Driver_SCD4X(TwoWire *i2c, uint16_t sensorAddress)
Constructor for a SCD40 sensor.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:41
sensors_event_t _humidity
Relative Humidity.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:189
bool getEventCO2(sensors_event_t *co2Event)
Gets the SCD40's current CO2 reading.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:176
bool getEventAmbientTemp(sensors_event_t *tempEvent)
Gets the SCD40's current temperature.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:138
bool ReadSensorData()
Reads the sensor.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:104
Base class for I2C Drivers.
Definition: WipperSnapper_I2C_Driver.h:33
uint16_t _sensorAddress
The I2C driver's unique I2C address.
Definition: WipperSnapper_I2C_Driver.h:1340
bool begin()
Initializes the SCD40 sensor and begins I2C.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:53
ulong _lastRead
Last time the sensor was read.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:191
sensors_event_t _temperature
Temperature.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:188
bool HasBeenReadInLastSecond()
Checks if sensor was read within last 1s, or is the first read.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:76
bool getEventRelativeHumidity(sensors_event_t *humidEvent)
Gets the SCD40's current relative humidity reading.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:157
bool IsSensorReady()
Checks if the sensor is ready to be read.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:86
#define ONE_SECOND_IN_MILLIS
Used for period checks.
Definition: WipperSnapper_I2C_Driver.h:26
TwoWire * _i2c
Pointer to the I2C driver's Wire object.
Definition: WipperSnapper_I2C_Driver.h:1339
sensors_event_t _CO2
CO2.
Definition: WipperSnapper_I2C_Driver_SCD4X.h:190