Skip to content

Commit

Permalink
Merge pull request #497 from tyeth/add-HTU21DF-HTU31D
Browse files Browse the repository at this point in the history
Add HTU21D/DF + HTU31D
  • Loading branch information
tyeth authored Oct 5, 2023
2 parents 709f339 + db59efb commit 74aa016
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 1 deletion.
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 LTR390 Library, 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, ENS160 - Adafruit Fork
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit INA219, Adafruit LTR390 Library, 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 HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork
5 changes: 5 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ lib_deps =
adafruit/Adafruit DPS310
adafruit/Adafruit INA219
adafruit/Adafruit HTS221
adafruit/Adafruit HTU21DF Library
adafruit/Adafruit HTU31D Library
adafruit/Adafruit LTR390 Library
adafruit/Adafruit PCT2075
adafruit/Adafruit SCD30
Expand Down Expand Up @@ -89,13 +91,16 @@ lib_ldf_mode = deep
extends = common:esp32
board = featheresp32
build_flags = -DARDUINO_FEATHER_ESP32
board_build.filesystem = littlefs


; Adafruit ESP32 Feather V2
[env:featheresp32v2]
extends = common:esp32
board = adafruit_feather_esp32_v2
board_build.partitions = default_8MB.csv
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32_V2
board_build.filesystem = littlefs

; Adafruit Feather ESP32-S2
[env:featheresp32s2]
Expand Down
22 changes: 22 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,28 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_hts221->configureDriver(msgDeviceInitReq);
drivers.push_back(_hts221);
WS_DEBUG_PRINTLN("HTS221 Initialized Successfully!");
} else if (strcmp("htu21d", msgDeviceInitReq->i2c_device_name) == 0) {
_htu21d = new WipperSnapper_I2C_Driver_HTU21D(this->_i2c, i2cAddress);
if (!_htu21d->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize HTU21D!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_htu21d->configureDriver(msgDeviceInitReq);
drivers.push_back(_htu21d);
WS_DEBUG_PRINTLN("HTU21D Initialized Successfully!");
} else if (strcmp("htu31d", msgDeviceInitReq->i2c_device_name) == 0) {
_htu31d = new WipperSnapper_I2C_Driver_HTU31D(this->_i2c, i2cAddress);
if (!_htu31d->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize HTU31D!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_htu31d->configureDriver(msgDeviceInitReq);
drivers.push_back(_htu31d);
WS_DEBUG_PRINTLN("HTU31D Initialized Successfully!");
} else if (strcmp("scd30", msgDeviceInitReq->i2c_device_name) == 0) {
_scd30 = new WipperSnapper_I2C_Driver_SCD30(this->_i2c, i2cAddress);
if (!_scd30->begin()) {
Expand Down
4 changes: 4 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "drivers/WipperSnapper_I2C_Driver_DPS310.h"
#include "drivers/WipperSnapper_I2C_Driver_ENS160.h"
#include "drivers/WipperSnapper_I2C_Driver_HTS221.h"
#include "drivers/WipperSnapper_I2C_Driver_HTU21D.h"
#include "drivers/WipperSnapper_I2C_Driver_HTU31D.h"
#include "drivers/WipperSnapper_I2C_Driver_INA219.h"
#include "drivers/WipperSnapper_I2C_Driver_LC709203F.h"
#include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h"
Expand Down Expand Up @@ -115,6 +117,8 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_BMP3XX *_bmp3xx = nullptr;
WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
WipperSnapper_I2C_Driver_HTU21D *_htu21d = nullptr;
WipperSnapper_I2C_Driver_HTU31D *_htu31d = nullptr;
WipperSnapper_I2C_Driver_INA219 *_ina219 = nullptr;
WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
Expand Down
89 changes: 89 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_HTU21D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*!
* @file WipperSnapper_I2C_Driver_HTU21D.h
*
* Device driver for an HTU21D Humidity and Temperature sensor.
*/

#ifndef WipperSnapper_I2C_Driver_HTU21D_H
#define WipperSnapper_I2C_Driver_HTU21D_H

#include "WipperSnapper_I2C_Driver.h"
#include <Adafruit_HTU21DF.h>

/**************************************************************************/
/*!
@brief Class that provides a sensor driver for the HTU21D humidity and
temperature sensor.
*/
/**************************************************************************/
class WipperSnapper_I2C_Driver_HTU21D : public WipperSnapper_I2C_Driver {

public:
/*******************************************************************************/
/*!
@brief Constructor for an HTU21D sensor.
@param i2c
The I2C interface.
@param sensorAddress
7-bit device address.
*/
/*******************************************************************************/
WipperSnapper_I2C_Driver_HTU21D(TwoWire *i2c, uint16_t sensorAddress)
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
_i2c = i2c;
_sensorAddress = sensorAddress;
}

/*******************************************************************************/
/*!
@brief Destructor for an HTU21D sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_HTU21D() { delete _htu21d; }

/*******************************************************************************/
/*!
@brief Initializes the HTU21D sensor and begins I2C.
@returns True if initialized successfully, False otherwise.
*/
/*******************************************************************************/
bool begin() {
// attempt to initialize the HTU21D using the I2C interface
_htu21d = new Adafruit_HTU21DF();
return _htu21d->begin(_i2c);
}

/*******************************************************************************/
/*!
@brief Gets the HTU21D's current temperature.
@param tempEvent
Pointer to an Adafruit_Sensor event.
@returns True if the temperature was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
tempEvent->temperature = _htu21d->readTemperature();
return true;
}

/*******************************************************************************/
/*!
@brief Gets the HTU21D's current humidity.
@param humidEvent
Pointer to an Adafruit_Sensor event.
@returns True if the humidity was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
humidEvent->relative_humidity = _htu21d->readHumidity();
return true;
}

protected:
Adafruit_HTU21DF *_htu21d; ///< Pointer to an HTU21D object
};

#endif // WipperSnapper_I2C_Driver_HTU21D
87 changes: 87 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_HTU31D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*!
* @file WipperSnapper_I2C_Driver_HTU31D.h
*
* Device driver for an HTU31D Humidity and Temperature sensor.
*/

#ifndef WipperSnapper_I2C_Driver_HTU31D_H
#define WipperSnapper_I2C_Driver_HTU31D_H

#include "WipperSnapper_I2C_Driver.h"
#include <Adafruit_HTU31D.h>

/**************************************************************************/
/*!
@brief Class that provides a sensor driver for the HTU31D humidity and
temperature sensor.
*/
/**************************************************************************/
class WipperSnapper_I2C_Driver_HTU31D : public WipperSnapper_I2C_Driver {

public:
/*******************************************************************************/
/*!
@brief Constructor for an HTU31D sensor.
@param i2c
The I2C interface.
@param sensorAddress
7-bit device address.
*/
/*******************************************************************************/
WipperSnapper_I2C_Driver_HTU31D(TwoWire *i2c, uint16_t sensorAddress)
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
_i2c = i2c;
_sensorAddress = sensorAddress;
}

/*******************************************************************************/
/*!
@brief Destructor for an HTU31D sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_HTU31D() { delete _htu31d; }

/*******************************************************************************/
/*!
@brief Initializes the HTU31D sensor and begins I2C.
@returns True if initialized successfully, False otherwise.
*/
/*******************************************************************************/
bool begin() {
// attempt to initialize the HTU31D using the I2C interface
_htu31d = new Adafruit_HTU31D();
return _htu31d->begin(_sensorAddress, _i2c);
}

/*******************************************************************************/
/*!
@brief Gets the HTU31D's current temperature.
@param tempEvent
Pointer to an Adafruit_Sensor event.
@returns True if the temperature was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
return _htu31d->getEvent(nullptr, tempEvent);
}

/*******************************************************************************/
/*!
@brief Gets the HTU31D's current humidity.
@param humidEvent
Pointer to an Adafruit_Sensor event.
@returns True if the humidity was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
return _htu31d->getEvent(humidEvent, nullptr);
}

protected:
Adafruit_HTU31D *_htu31d; ///< Pointer to an HTU31D object
};

#endif // WipperSnapper_I2C_Driver_HTU31D

0 comments on commit 74aa016

Please sign in to comment.