upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

API for the HTU21D Temperature & Humidity Sensor. More...

Detailed Description

HTU21D by Measurement Specialties is a digital humidity sensor with temperature output. RH reports between 0 and 100%, and the temperature range is -40 to +125 degC. Note: getCompRH is the preferred function below (passing true to cause a measurement cycle). If actual values used for the compensated ready are necessary, use the getHumidity(false) and getTemperature(false) functions following the getCompRH call. Also note the sensor should not perform more than a couple of measurements per second to limit the heating of the sensor.

htu21d.jpeg
float humidity = 0;
float temperature = 0;
float compRH = 0;
sensor.testSensor();
while (true) {
compRH = sensor.getCompRH();
humidity = sensor.getHumidity();
temperature = sensor.getTemperature();
System.out.println("Humidity: " + humidity + ", Temperature: " + temperature
+ ", compensated RH: " + compRH);
Thread.sleep(5000);
}

Public Member Functions

synchronized void delete ()
 
 HTU21D (int bus, int devAddr)
 
 HTU21D (int bus)
 
int sampleData ()
 
float getHumidity (int bSampleData)
 
float getHumidity ()
 
float getTemperature (int bSampleData)
 
float getTemperature ()
 
float getCompRH (int bSampleData)
 
float getCompRH ()
 
int setHeater (int bEnable)
 
int setHeater ()
 
void resetSensor ()
 
int testSensor ()
 
int i2cWriteReg (short reg, short value)
 
int i2cReadReg_16 (int reg)
 
short i2cReadReg_8 (int reg)
 

Constructor & Destructor Documentation

HTU21D ( int  bus,
int  devAddr 
)

Instantiates an HTU21D object

Parameters
busNumber of the used bus
devAddrAddress of the used I2C device
modeHTU21D oversampling

Member Function Documentation

float getCompRH ( int  bSampleData)

Using the current humidity and temperature, the function calculates the compensated RH using the equation from the datasheet.

float getHumidity ( int  bSampleData)

Gets the current measured humidity [RH]

float getTemperature ( int  bSampleData)

Gets the humidity cell temperature [degC]

int i2cReadReg_16 ( int  reg)

Reads a two-byte register

Parameters
regAddress of the register
short i2cReadReg_8 ( int  reg)

Reads a one-byte register

Parameters
regAddress of the register
int i2cWriteReg ( short  reg,
short  value 
)

Writes to a one-byte register

Parameters
regAddress of the register
valueByte to be written
int setHeater ( int  bEnable)

Sets the heater state. The heater is used to test the sensor functionality since the temperature should increase 0.5 to 1.5 degC, and the humidity should decrease. The testSensor() function below uses the heater.

Parameters
bEnableSets to non-zero to turn the heater on

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