diff --git a/library.properties b/library.properties index 91fdb5706..d87d48413 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Arduino client for Adafruit.io WipperSnapper category=Communication url=https://github.com/adafruit/Adafruit_IO_Arduino architectures=* -depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 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 PM25 AQI Sensor, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit PCT2075, hp_BH1750 +depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, 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 PM25 AQI Sensor, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit PCT2075, hp_BH1750 diff --git a/platformio.ini b/platformio.ini index 90452cf3e..b26f9d857 100644 --- a/platformio.ini +++ b/platformio.ini @@ -32,6 +32,7 @@ lib_deps = adafruit/Adafruit PCT2075 adafruit/Adafruit SCD30 adafruit/Adafruit SGP30 Sensor + adafruit/Adafruit SGP40 Sensor adafruit/Adafruit Si7021 Library adafruit/Adafruit MCP9808 Library adafruit/Adafruit MCP9600 Library diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 7e05645a7..884d5cfdd 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -340,6 +340,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _sgp30->configureDriver(msgDeviceInitReq); drivers.push_back(_sgp30); WS_DEBUG_PRINTLN("SGP30 Initialized Successfully!"); + } else if (strcmp("sgp40", msgDeviceInitReq->i2c_device_name) == 0) { + _sgp40 = new WipperSnapper_I2C_Driver_SGP40(this->_i2c, i2cAddress); + if (!_sgp40->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize SGP40!"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _sgp40->configureDriver(msgDeviceInitReq); + drivers.push_back(_sgp40); + WS_DEBUG_PRINTLN("SGP40 Initialized Successfully!"); } else if ((strcmp("sht20", msgDeviceInitReq->i2c_device_name) == 0) || (strcmp("si7021", msgDeviceInitReq->i2c_device_name) == 0)) { _si7021 = new WipperSnapper_I2C_Driver_SI7021(this->_i2c, i2cAddress); diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index fb007336a..f97e455b7 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -45,6 +45,7 @@ #include "drivers/WipperSnapper_I2C_Driver_SCD4X.h" #include "drivers/WipperSnapper_I2C_Driver_SEN5X.h" #include "drivers/WipperSnapper_I2C_Driver_SGP30.h" +#include "drivers/WipperSnapper_I2C_Driver_SGP40.h" #include "drivers/WipperSnapper_I2C_Driver_SHT3X.h" #include "drivers/WipperSnapper_I2C_Driver_SHT4X.h" #include "drivers/WipperSnapper_I2C_Driver_SHTC3.h" @@ -122,6 +123,7 @@ class WipperSnapper_Component_I2C { WipperSnapper_I2C_Driver_SCD4X *_scd40 = nullptr; WipperSnapper_I2C_Driver_SEN5X *_sen5x = nullptr; WipperSnapper_I2C_Driver_SGP30 *_sgp30 = nullptr; + WipperSnapper_I2C_Driver_SGP40 *_sgp40 = nullptr; WipperSnapper_I2C_Driver_PCT2075 *_pct2075 = nullptr; WipperSnapper_I2C_Driver_PM25 *_pm25 = nullptr; WipperSnapper_I2C_Driver_SI7021 *_si7021 = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SGP40.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SGP40.h new file mode 100644 index 000000000..3e201b106 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_SGP40.h @@ -0,0 +1,94 @@ +/*! + * @file WipperSnapper_I2C_Driver_SGP40.h + * + * Device driver for the SGP40 VOC/gas sensor. + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2023 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ + +#ifndef WipperSnapper_I2C_Driver_SGP40_H +#define WipperSnapper_I2C_Driver_SGP40_H + +#include "WipperSnapper_I2C_Driver.h" +#include +#include + +/**************************************************************************/ +/*! + @brief Class that provides a driver interface for the SGP40 sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_SGP40 : public WipperSnapper_I2C_Driver { +public: + /*******************************************************************************/ + /*! + @brief Constructor for a SGP40 sensor. + @param i2c + The I2C interface. + @param sensorAddress + 7-bit device address. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_SGP40(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _i2c = i2c; + _sensorAddress = sensorAddress; + } + + /*******************************************************************************/ + /*! + @brief Initializes the SGP40 sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _sgp40 = new Adafruit_SGP40(); + if (!_sgp40->begin(_i2c)) { + return false; + } + + // TODO: update to use setCalibration() and pass in temp/humidity + + return true; + } + + /*******************************************************************************/ + /*! + @brief Gets the sensor's current raw unprocessed value. + @param rawEvent + Pointer to an Adafruit_Sensor event. + @returns True if the temperature was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventRaw(sensors_event_t *rawEvent) { + rawEvent->data[0] = (float)_sgp40->measureRaw(); + return true; + } + + /*******************************************************************************/ + /*! + @brief Gets the SGP40's current VOC reading. + @param vocIndexEvent + Adafruit Sensor event for VOC Index (1-500, 100 is normal) + @returns True if the sensor value was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventVOCIndex(sensors_event_t *vocIndexEvent) { + vocIndexEvent->voc_index = (float)_sgp40->measureVocIndex(); + return true; + } + +protected: + Adafruit_SGP40 *_sgp40; ///< SEN5X driver object +}; + +#endif // WipperSnapper_I2C_Driver_SEN5X