Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SGP40 #487

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
94 changes: 94 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_SGP40.h
Original file line number Diff line number Diff line change
@@ -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 <Adafruit_SGP40.h>
#include <Wire.h>

/**************************************************************************/
/*!
@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