Manuel Caballero / HTU21D
Embed: (wiki syntax)

« Back to documentation index

HTU21D Class Reference

HTU21D Class Reference

Example: More...

#include <HTU21D.h>

Public Types

enum  HTU21D_address_t
 

DEFAULT ADDRESSES.

More...
enum  HTU21D_user_register_resolution_t { RESOLUTION_12RH_14TEMP = 0, RESOLUTION_8RH_12TEMP = 1, RESOLUTION_10RH_13TEMP = 2, RESOLUTION_11RH_11TEMP = 3 }
 

RESOLUTION.

More...
enum  HTU21D_user_register_status_t { STATUS_END_BATTERY_HIGH_2V25 = 0, STATUS_END_BATTERY_LOW_2V25 = 1 }
 

STATUS: END OF BATTERY.

More...
enum  HTU21D_user_register_heater_t { HEATER_ENABLED = 0, HEATER_DISABLED = 1 }
 

ON-CHIP HEATER.

More...
enum  HTU21D_user_register_otp_t { OTP_ENABLED = 0, OTP_DISABLED = 1 }
 

OTP RELOAD.

More...
enum  HTU21D_master_mode_t { MODE_HOLD_MASTER = 0, MODE_NO_HOLD_MASTER = 1 }
 

MODE.

More...
enum  HTU21D_status_t { , I2C_SUCCESS = 0 }
 

INTERNAL CONSTANTS.

More...

Public Member Functions

 HTU21D (PinName sda, PinName scl, uint32_t addr, uint32_t freq)
 Create an HTU21D object connected to the specified I2C pins.
 ~HTU21D ()
 Delete HTU21D object.
HTU21D_status_t HTU21D_Init (HTU21D_master_mode_t myMode, HTU21D_user_register_resolution_t myResolution, HTU21D_user_register_heater_t myHeater)
 It configures the device.
HTU21D_status_t HTU21D_SoftReset (void)
 It resets the device by software.
HTU21D_status_t HTU21D_TriggerTemperature (void)
 It triggers a new temperature measurement.
HTU21D_status_t HTU21D_ReadRawTemperature (Vector_raw_temperature_t *myRawTemperature)
 It reads the raw temperature.
HTU21D_status_t HTU21D_ReadTemperature (Vector_temperature_f *myTemperature)
 It reads the temperature.
HTU21D_status_t HTU21D_TriggerHumidity (void)
 It triggers a new humidity measurement.
HTU21D_status_t HTU21D_ReadRawHumidity (Vector_raw_humidity_t *myRawHumidity)
 It reads the raw humidity.
HTU21D_status_t HTU21D_ReadHumidity (Vector_humidity_f *myHumidity)
 It reads the humidity.
HTU21D_status_t HTU21D_BatteryStatus (HTU21D_user_register_status_t *myBattStatus)
 It gets the battery status.

Detailed Description

Example:

include "mbed.h" include "HTU21D.h"

HTU21D myTempRXSensor ( I2C_SDA, I2C_SCL, HTU21D::HTU21D_ADDRESS, 400000 ); Serial pc ( USBTX, USBRX ); // tx, rx

Ticker serial;

DigitalOut myled(LED1);

HTU21D::Vector_temperature_f myTemperature; HTU21D::Vector_humidity_f myHumidity;

void sendDATA ( void ) { HTU21D::HTU21D_user_register_status_t myBatteryStatus;

myled = 1;

Get Temperature myTempRXSensor.HTU21D_TriggerTemperature (); myTempRXSensor.HTU21D_ReadTemperature ( &myTemperature );

Get Humidity myTempRXSensor.HTU21D_TriggerHumidity (); myTempRXSensor.HTU21D_ReadHumidity ( &myHumidity );

Get Battery Status myTempRXSensor.HTU21D_BatteryStatus ( &myBatteryStatus );

Send data through the UART pc.printf( "\nTemperature: %0.01f\nHumidity: %0.01f\n", myTemperature.Temperature, myHumidity.Humidity );

if ( myBatteryStatus == HTU21D::STATUS_END_BATTERY_HIGH_2V25 ) pc.printf( "Battery status higher than 2.25V\r\n" ); else pc.printf( "Battery status lower than 2.25V\r\n" );

myled = 0; }

int main() { pc.baud ( 115200 );

myTempRXSensor.HTU21D_SoftReset (); myTempRXSensor.HTU21D_Init ( HTU21D::MODE_NO_HOLD_MASTER, HTU21D::RESOLUTION_12RH_14TEMP, HTU21D::HEATER_DISABLED );

serial.attach( &sendDATA, 1 ); // the address of the function to be attached ( sendDATA ) and the interval ( 1s )

Let the callbacks take care of everything while(1) sleep(); }

Library for the HTU21D Digital humidity sensor with temperature output.

Definition at line 89 of file HTU21D.h.


Member Enumeration Documentation

DEFAULT ADDRESSES.

Definition at line 95 of file HTU21D.h.

MODE.

Enumerator:
MODE_HOLD_MASTER 

Mode Hold master

MODE_NO_HOLD_MASTER 

Mode No hold master

Definition at line 153 of file HTU21D.h.

INTERNAL CONSTANTS.

Enumerator:
I2C_SUCCESS 

I2C communication was fine

Definition at line 185 of file HTU21D.h.

ON-CHIP HEATER.

Enumerator:
HEATER_ENABLED 

Heater enabled

HEATER_DISABLED 

Heater disabled

Definition at line 134 of file HTU21D.h.

OTP RELOAD.

Enumerator:
OTP_ENABLED 

OTP enabled

OTP_DISABLED 

OTP disabled

Definition at line 142 of file HTU21D.h.

RESOLUTION.

Enumerator:
RESOLUTION_12RH_14TEMP 

Resolution: RH 12-bits, T 14-bits

RESOLUTION_8RH_12TEMP 

Resolution: RH 8-bits, T 12-bits

RESOLUTION_10RH_13TEMP 

Resolution: RH 10-bits, T 13-bits

RESOLUTION_11RH_11TEMP 

Resolution: RH 11-bits, T 11-bits

Definition at line 116 of file HTU21D.h.

STATUS: END OF BATTERY.

Enumerator:
STATUS_END_BATTERY_HIGH_2V25 

Status: RH 12-bits, T 14-bits

STATUS_END_BATTERY_LOW_2V25 

Status: RH 8-bits, T 12-bits

Definition at line 126 of file HTU21D.h.


Constructor & Destructor Documentation

HTU21D ( PinName  sda,
PinName  scl,
uint32_t  addr,
uint32_t  freq 
)

Create an HTU21D object connected to the specified I2C pins.

HTU21D.c.

Parameters:
sdaI2C data pin
sclI2C clock pin
addrI2C slave address
freqI2C frequency in Hz.

Digital humidity sensor with temperature output. Functions file.

Returns:
NA
Author:
Manuel Caballero
Date:
4/September/2017
Version:
4/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN
Precondition:
This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).

Definition at line 20 of file HTU21D.cpp.

~HTU21D (  )

Delete HTU21D object.

Definition at line 28 of file HTU21D.cpp.


Member Function Documentation

HTU21D::HTU21D_status_t HTU21D_BatteryStatus ( HTU21D_user_register_status_t battStatus )

It gets the battery status.

HTU21D_BatteryStatus ( HTU21D_user_register_status_t* )

Read the user register to check the battery status.

Parameters:
[in]battStatus,:Variable to store the battery status.
[out]Statusof HTU21D_BatteryStatus.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 442 of file HTU21D.cpp.

It configures the device.

HTU21D_Init ( HTU21D_master_mode_t , HTU21D_user_register_resolution_t , HTU21D_user_register_otp_t )

It initializes the device.

Parameters:
[in]myMode,:Hold/No Hold master mode.
[in]myResolution,:Resolution of the sensor.
[in]myHeater,:Heater enabled or disabled.
[out]NaN.
Returns:
Status of HTU21D_Init.
Author:
Manuel Caballero
Date:
4/September/2017
Version:
4/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 55 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_ReadHumidity ( Vector_humidity_f *  myhumidity )

It reads the humidity.

HTU21D_ReadHumidity ( Vector_humidity_f* )

Read a new humidity measurement.

Parameters:
[in]myhumidity,:Variable to store the humidity.
[out]Statusof HTU21D_ReadHumidity.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
HTU21D_TriggerHumidity MUST be called before.

Definition at line 366 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_ReadRawHumidity ( Vector_raw_humidity_t *  myRawhumidity )

It reads the raw humidity.

HTU21D_ReadRawHumidity ( Vector_raw_humidity_t* )

Read a new raw humidity measurement.

Parameters:
[in]myRawhumidity,:Variable to store the raw humidity.
[out]Statusof HTU21D_ReadHumidity.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
The measuring time depends on the chosen resolution.
HTU21D_TriggerHumidity MUST be called before.

Definition at line 408 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_ReadRawTemperature ( Vector_raw_temperature_t *  myRawtemperature )

It reads the raw temperature.

HTU21D_ReadRawTemperature ( Vector_raw_temperature_t* )

Read a new raw temperature measurement.

Parameters:
[in]myRawtemperature,:Variable to store the temperature.
[out]Statusof HTU21D_ReadTemperature.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
HTU21D_TriggerTemperature MUST be called before.

Definition at line 270 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_ReadTemperature ( Vector_temperature_f *  mytemperature )

It reads the temperature.

HTU21D_ReadTemperature ( Vector_temperature_f* )

Read a new temperature measurement.

Parameters:
[in]mytemperature,:Variable to store the temperature.
[out]Statusof HTU21D_ReadTemperature.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
HTU21D_TriggerTemperature MUST be called before.

Definition at line 229 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_SoftReset ( void   )

It resets the device by software.

HTU21D_SoftReset ( void )

Rebooting the HTU21D sensor switching the power off and on again.

Parameters:
[in]NaN.
[out]Statusof HTU21D_SoftReset.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
The soft reset takes less than 15ms.

Definition at line 130 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_TriggerHumidity ( void   )

It triggers a new humidity measurement.

HTU21D_TriggerHumidity ( void )

Trigger a new humidity measurement.

Parameters:
[in]NaN.
[out]Statusof HTU21D_TriggerHumidity.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
The measuring time depends on the chosen resolution.

Definition at line 302 of file HTU21D.cpp.

HTU21D::HTU21D_status_t HTU21D_TriggerTemperature ( void   )

It triggers a new temperature measurement.

HTU21D_TriggerTemperature ( void )

Trigger a new temperature measurement.

Parameters:
[in]NaN.
[out]Statusof HTU21D_TriggerTemperature.
Returns:
NA
Author:
Manuel Caballero
Date:
5/September/2017
Version:
5/September/2017 The ORIGIN
Precondition:
NaN
Warning:
The measuring time depends on the chosen resolution.

Definition at line 165 of file HTU21D.cpp.