The ST HTS221 is a sensor for relative humidity and temperature.
The HTS221Sensor
class provides methods to read and write data, set configuration of HTS221 sensor.
Assembly
HTS221Sensor.h
Summary
Types
DevI2C
Provides functions for multi-register I2C communication.
PinName
Provides the mapping of mbed DIP and LPC Pin Names.
Constructors
HTS221Sensor
HTS221Sensor(DevI2C &i2c)
Parameters
Type | Name | Description |
DevI2C & | i2c | The object of an helper class which handles the I2C peripheral. |
HTS221Sensor
HTS221Sensor(DevI2C &i2c, unsigned char address)
Parameters
Type | Name | Description |
DevI2C & | i2c | The object of an helper class which handles the I2C peripheral. |
unsigned char | address | The address of the component’s instance. |
Methods
init
Initializing the component.
Parameters
Type | Name | Description |
void * | init | Pointer to device specific initalization structure. |
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
enable
Enable HTS221.
Parameters
None.
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
disable
Disable HTS221.
Parameters
None.
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
readId
int readId(unsigned char *id)
Read ID address of HTS221.
Parameters
Type | Name | Description |
unsigned char * | id | The pointer where the ID of the device is stored. |
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
reset
Reboot memory content of HTS221.
Parameters
None.
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
getHumidity
int getHumidity(float *pfData)
Read HTS221 output register, and calculate the humidity.
Parameters
Type | Name | Description |
float * | pfData | The pointer to data output. |
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
getTemperature
int getTemperature(float *pfData)
Read HTS221 output register, and calculate the temperature.
Parameters
Type | Name | Description |
float * | pfData | The pointer to data output. |
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
getOdr
Read HTS221 output register, and calculate the humidity.
Parameters
Type | Name | Description |
float * | odr | The pointer to the output data rate. |
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
setOdr
Set ODR.
Parameters
Type | Name | Description |
float | odr | The output data rate to be set. |
Return value
Type | Description |
int | Result code, 0 in case of success, an error code otherwise. |
Sample code
#include "HTS221Sensor.h" DevI2C *i2c; HTS221Sensor *sensor; float humidity = 0; float temperature = 0; unsigned char id; void setup() { i2c = new DevI2C(D14, D15); sensor = new HTS221Sensor(*i2c); // init the sensor sensor -> init(NULL); } void loop() { // enable sensor -> enable(); // read id sensor -> readId(&id); Serial.printf("ID: %d\r\n", id); // get humidity sensor -> getHumidity(&humidity); Serial.print("Humidity: "); Serial.println(humidity); // get temperature sensor -> getTemperature(&temperature); Serial.print("Temperature: "); Serial.println(temperature); // disable the sensor sensor -> disable(); // reset sensor -> reset(); delay(1000); }