UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

HTU21D Class

Module: htu21d

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

Methods

HTU21D

(
  • bus
  • devAddr
)
Number

Instantiates an HTU21D object

Parameters:

  • bus Number

    Number of the used bus

  • devAddr Number

    Address of the used I2C device

Returns:

Number:

sampleData

() Number

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

Returns:

Number:

getHumidity

(
  • bSampleData
)
Number

Gets the current measured humidity [RH]

Parameters:

  • bSampleData Number

    Flag to sample sensor (default false)

Returns:

Number:

Relative humidity in RH

getTemperature

(
  • bSampleData
)
Number

Gets the humidity cell temperature [degC]

Parameters:

  • bSampleData Number

    Flag to sample sensor (default false)

Returns:

Number:

Temperature in degC

getCompRH

(
  • bSampleData
)
Number

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

Parameters:

  • bSampleData Number

    Flag to sample sensor (default false)

Returns:

Number:

Compensated relative humidity in RH

getDewPoint

(
  • bSampleData
)
Number

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

Parameters:

  • bSampleData Number

    Flag to sample sensor (default false)

Returns:

Number:

Dew point in degC

getHumidityData

(
  • fHum
  • fHumTemp
  • fDewPt
)
Number

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:

  • fHum Float *

    pointer to float for relative humidity RH

  • fHumTemp Float *

    pointer to float for temperature degC

  • fDewPt Float *

    pointer to float for calculated dew point degC

Returns:

Number:

0 if success or 1 if sensor is not functioning

setHeater

(
  • bEnable
)
Number

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:

  • bEnable Number

    Sets to non-zero to turn the heater on

Returns:

Number:

0 on success

resetSensor

()

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.

testSensor

() Number

Tests the device and verifies it is operating correctly.

Returns:

Number:

0 on success or error code

i2cWriteReg

(
  • reg
  • value
)
Mraa::Result

Writes to a one-byte register

Parameters:

  • reg Number

    Address of the register

  • value Number

    Byte to be written

Returns:

Mraa::Result:

i2cReadReg_16

(
  • reg
)
Number

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

Parameters:

  • reg Number

    Address of the register

Returns:

Number:

Value returned from register

i2cReadReg_8

(
  • reg
)
Number

Reads a one-byte register

Parameters:

  • reg Number

    Address of the register

Returns:

Number:

Value returned from register