Arduino TKJHAT
Arduino library for Pico HAT extension board
Loading...
Searching...
No Matches
HDC2021 Class Reference

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.

Detailed Description

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_():

  • Temperature low: -30 °C
  • Temperature high: +50 °C
  • Humidity low: 0 %
  • Humidity high: 100 %

These thresholds are part of the sensor’s alert system.

Precondition
The I2C interface must be initialized (use TKJHAT::begin() or HDC2021::begin()).
See also
Datasheet: https://www.ti.com/lit/ds/symlink/hdc2021.pdf
Usage Guide: https://www.ti.com/lit/ug/snau250/snau250.pdf {@

Constructor & Destructor Documentation

◆ HDC2021()

HDC2021::HDC2021 ( uint8_t sdaPin,
uint8_t sclPin,
uint8_t interruptPin )

Construct a new HDC2021 object with specified I2C pins and optional interrupt pin.

Parameters
sdaPinGPIO pin number for I2C SDA (default: DEFAULT_I2C_SDA_PIN)
sclPinGPIO pin number for I2C SCL (default: DEFAULT_I2C_SCL_PIN)
interruptPinGPIO pin number for optional alert interrupt (default: HDC2021_INTERRUPT)

Member Function Documentation

◆ begin()

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:

  • Resolution: 14 bits (temperature and humidity)
  • Thresholds: -30 °C / +50 °C and 0 % / 100 %

◆ readHumidity()

float HDC2021::readHumidity ( )

Read the current relative humidity in percentage.

Returns
Relative humidity in percentage

◆ readTemperature()

float HDC2021::readTemperature ( )

Read the current temperature in degrees Celsius.

Returns
Temperature in degrees Celsius

◆ setHighHumidityThreshold()

void HDC2021::setHighHumidityThreshold ( float humid)

Set the high humidity threshold.

Parameters
humidHumidity threshold in percentage

◆ setHighTempThreshold()

void HDC2021::setHighTempThreshold ( float temp)

Set the high temperature threshold.

Parameters
tempTemperature threshold in degrees Celsius

◆ setLowHumidityThreshold()

void HDC2021::setLowHumidityThreshold ( float humid)

Set the low humidity threshold.

Parameters
humidHumidity threshold in percentage

◆ setLowTempThreshold()

void HDC2021::setLowTempThreshold ( float temp)

Set the low temperature threshold.

Parameters
tempTemperature threshold in degrees Celsius

◆ stop()

void HDC2021::stop ( )

Stop the HDC2021 sensor.

Puts the sensor into a low-power state and stops measurements.


The documentation for this class was generated from the following file: