-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from brentru/add-sht40
Add SHT4X Support
- Loading branch information
Showing
6 changed files
with
139 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
name=Adafruit WipperSnapper | ||
version=1.0.0-beta.42 | ||
version=1.0.0-beta.43 | ||
author=Adafruit | ||
maintainer=Adafruit <[email protected]> | ||
sentence=Arduino client for Adafruit.io WipperSnapper | ||
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 SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library | ||
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit SHT4x Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/components/i2c/drivers/WipperSnapper_I2C_Driver_SHT4X.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_SHT4X.h | ||
* | ||
* Device driver for the SHT4X Temperature and Humidity 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) Marni Brewster 2022 for Adafruit Industries. | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_SHT4X_H | ||
#define WipperSnapper_I2C_Driver_SHT4X_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_SHT4x.h> | ||
#include <Wire.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a driver interface for the SHT4X sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_SHT4X : public WipperSnapper_I2C_Driver { | ||
|
||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for a SHT4X sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_SHT4X(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the SHT4X sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
_sht4x = new Adafruit_SHT4x(); | ||
if (!_sht4x->begin(_i2c)) | ||
return false; | ||
|
||
// Use HIGH PRECISION | ||
_sht4x->setPrecision(SHT4X_HIGH_PRECISION); | ||
// default, NO HEATER | ||
_sht4x->setHeater(SHT4X_NO_HEATER); | ||
|
||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the SHT4X's current temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAmbientTemperature(sensors_event_t *tempEvent) { | ||
sensors_event_t humidityEvent; | ||
// populate temp and humidity objects with fresh data | ||
if (!_sht4x->getEvent(&humidityEvent, tempEvent)) | ||
return false; | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the SHT4X's current relative humidity reading. | ||
@param humidEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the humidity was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventRelativeHumidity(sensors_event_t *humidEvent) { | ||
sensors_event_t tempEvent; | ||
// populate temp and humidity objects with fresh data | ||
if (!_sht4x->getEvent(humidEvent, &tempEvent)) | ||
return false; | ||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_SHT4x *_sht4x; ///< SHT4X object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_SHT4X |