upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
HTU21D Class Reference

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.0;
float temperature = 0.0;
float compRH = 0.0;
sensor = new upm::HTU21D(0, HTU21D_I2C_ADDRESS);
sensor->testSensor();
while (!doWork) {
compRH = sensor->getCompRH(true);
humidity = sensor->getHumidity(false);
temperature = sensor->getTemperature(false);
std::cout << "humidity value = " <<
humidity <<
", temperature value = " <<
temperature <<
", compensated RH value = " <<
compRH << std::endl;
usleep (500000);
}

Public Member Functions

 HTU21D (int bus, int devAddr=HTU21D_I2C_ADDRESS)
 
int sampleData (void)
 
float getHumidity (int bSampleData=false)
 
float getTemperature (int bSampleData=false)
 
float getCompRH (int bSampleData=false)
 
float getDewPoint (int bSampleData=false)
 
int getHumidityData (float *fHum, float *fHumTemp, float *fDewPt)
 
int setHeater (int bEnable=false)
 
void resetSensor (void)
 
int testSensor (void)
 
mraa::Result i2cWriteReg (uint8_t reg, uint8_t value)
 
uint16_t i2cReadReg_16 (int reg)
 
uint8_t i2cReadReg_8 (int reg)
 

Constructor & Destructor Documentation

HTU21D ( int  bus,
int  devAddr = HTU21D_I2C_ADDRESS 
)

Instantiates an HTU21D object

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

Here is the call graph for this function:

Member Function Documentation

int sampleData ( void  )

Initiates a temperature/pressure mesasurement and waits to complete. The humidity and temperature registers can be read after this call.

Here is the call graph for this function:

Here is the caller graph for this function:

float getHumidity ( int  bSampleData = false)

Gets the current measured humidity [RH]

Parameters
bSampleDataFlag to sample sensor (default false)
Returns
Relative humidity in RH

Here is the call graph for this function:

Here is the caller graph for this function:

float getTemperature ( int  bSampleData = false)

Gets the humidity cell temperature [degC]

Parameters
bSampleDataFlag to sample sensor (default false)
Returns
Temperature in degC

Here is the call graph for this function:

Here is the caller graph for this function:

float getCompRH ( int  bSampleData = false)

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

Parameters
bSampleDataFlag to sample sensor (default false)
Returns
Compensated relative humidity in RH

Here is the call graph for this function:

Here is the caller graph for this function:

float getDewPoint ( int  bSampleData = false)

Using the current humidity and temperature the function will calculate the dew point in degreeC based on equation from the datasheet.

Parameters
bSampleDataFlag to sample sensor (default false)
Returns
Dew point in degC

Here is the call graph for this function:

Here is the caller graph for this function:

int getHumidityData ( float *  fHum,
float *  fHumTemp,
float *  fDewPt 
)

Function will attempt to get the best measurement for humidity using the heater in cases where humidity is high to keep the sesnsor dry. The heater setting is returned

Parameters
fHumpointer to float for relative humidity RH
fHumTemppointer to float for temperature degC
fDewPtpointer to float for calculated dew point degC
Returns
0 if success or 1 if sensor is not functioning

Here is the call graph for this function:

int setHeater ( int  bEnable = false)

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
Returns
0 on success

Here is the call graph for this function:

Here is the caller graph for this function:

void resetSensor ( void  )

Performs a soft reset of the MPL3115A2 device to ensure it is in a known state. This function can be used to reset the min/max temperature and pressure values.

Here is the caller graph for this function:

int testSensor ( void  )

Tests the device and verifies it is operating correctly.

Returns
0 on success or error code

Here is the call graph for this function:

mraa::Result i2cWriteReg ( uint8_t  reg,
uint8_t  value 
)

Writes to a one-byte register

Parameters
regAddress of the register
valueByte to be written

Here is the caller graph for this function:

uint16_t i2cReadReg_16 ( int  reg)

Reads a two-byte register. Note: byte ordering is hardware specific.

Parameters
regAddress of the register
Returns
Value returned from register

Here is the caller graph for this function:

uint8_t i2cReadReg_8 ( int  reg)

Reads a one-byte register

Parameters
regAddress of the register
Returns
Value returned from register

Here is the caller graph for this function:


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