A class for the Texas Instruments HDC2021 digital temperature and humidity sensor. More...
#include <HDC2021.h>
Public Member Functions | |
| void | begin () |
| Initialize the HDC2021 sensor (HDC2021_I2C_ADDRESS — 0x40). | |
| HDC2021 (uint8_t sdaPin, uint8_t sclPin, uint8_t interruptPin) | |
| Construct a new HDC2021 object with specified I2C pins and optional interrupt pin. | |
| float | readHumidity () |
| Read the current relative humidity in percentage. | |
| float | readTemperature () |
| Read the current temperature in degrees Celsius. | |
| void | setHighHumidityThreshold (float humid) |
| Set the high humidity threshold. | |
| void | setHighTempThreshold (float temp) |
| Set the high temperature threshold. | |
| void | setLowHumidityThreshold (float humid) |
| Set the low humidity threshold. | |
| void | setLowTempThreshold (float temp) |
| Set the low temperature threshold. | |
| void | stop () |
| Stop the HDC2021 sensor. | |
A class for the Texas Instruments HDC2021 digital temperature and humidity sensor.
The HDC2021 is a low-power, high-accuracy sensor connected via I2C at address HDC2021_I2C_ADDRESS (0x40). It measures both temperature and relative humidity with 14-bit resolution.
Default connections:
| Signal | I2C Macro | GPIO | Description |
|---|---|---|---|
| SDA | DEFAULT_I2C_SDA_PIN | 12 | I2C data |
| SCL | DEFAULT_I2C_SCL_PIN | 13 | I2C clock |
| Address | HDC2021_I2C_ADDRESS | 0x40 | Sensor I2C address |
| Interrupt | HDC2021_INTERRUPT | 21 | Optional alert pin |
Default thresholds configured by init_hdc2021_():
These thresholds are part of the sensor’s alert system.
| HDC2021::HDC2021 | ( | uint8_t | sdaPin, |
| uint8_t | sclPin, | ||
| uint8_t | interruptPin ) |
Construct a new HDC2021 object with specified I2C pins and optional interrupt pin.
| sdaPin | GPIO pin number for I2C SDA (default: DEFAULT_I2C_SDA_PIN) |
| sclPin | GPIO pin number for I2C SCL (default: DEFAULT_I2C_SCL_PIN) |
| interruptPin | GPIO pin number for optional alert interrupt (default: HDC2021_INTERRUPT) |
| void HDC2021::begin | ( | ) |
Initialize the HDC2021 sensor (HDC2021_I2C_ADDRESS — 0x40).
Performs a soft reset and configures the sensor for continuous measurement mode with default thresholds and 1 Hz sampling rate:
| float HDC2021::readHumidity | ( | ) |
Read the current relative humidity in percentage.
| float HDC2021::readTemperature | ( | ) |
Read the current temperature in degrees Celsius.
| void HDC2021::setHighHumidityThreshold | ( | float | humid | ) |
Set the high humidity threshold.
| humid | Humidity threshold in percentage |
| void HDC2021::setHighTempThreshold | ( | float | temp | ) |
Set the high temperature threshold.
| temp | Temperature threshold in degrees Celsius |
| void HDC2021::setLowHumidityThreshold | ( | float | humid | ) |
Set the low humidity threshold.
| humid | Humidity threshold in percentage |
| void HDC2021::setLowTempThreshold | ( | float | temp | ) |
Set the low temperature threshold.
| temp | Temperature threshold in degrees Celsius |
| void HDC2021::stop | ( | ) |
Stop the HDC2021 sensor.
Puts the sensor into a low-power state and stops measurements.