adafruit_hts221

Helper library for the HTS221 Humidity and Temperature Sensor

  • Author(s): Bryan Siepert

Implementation Notes

Hardware:

Software and Dependencies:
class adafruit_hts221.HTS221(i2c_bus)

Library for the ST HTS221 Humidity and Temperature Sensor

Parameters:i2c_bus (I2C) – The I2C bus the HTS221 is connected to

Quickstart: Importing and using the HTS221

Here is an example of using the HTS221 class. First you will need to import the libraries to use the sensor

import board
import adafruit_hts221

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
hts = adafruit_hts221.HTS221(i2c)

Now you have access to the temperature and relative_humidity attributes

temperature = hts.temperature
relative_humidity = hts.relative_humidity
data_rate

The rate at which the sensor measures relative_humidity and temperature. data_rate should be set to one of the values of adafruit_hts221.Rate. Note that setting data_rate to Rate.ONE_SHOT will cause relative_humidity and temperature measurements to only update when take_measurements() is called.

enabled

Controls the power down state of the sensor. Setting to False will shut the sensor down

humidity_data_ready

Returns true if a new relative humidity measurement is available to be read

relative_humidity

The current relative humidity measurement in %rH

take_measurements()

Update the value of relative_humidity and temperature by taking a single measurement. Only meaningful if data_rate is set to ONE_SHOT

temperature

The current temperature measurement in degrees Celsius

temperature_data_ready

Returns true if a new temperature measurement is available to be read

class adafruit_hts221.Rate

Options for data_rate

Rate Description
Rate.ONE_SHOT Setting data_rate to Rate.ONE_SHOT takes a single humidity and temperature measurement
Rate.RATE_1_HZ 1 Hz
Rate.RATE_7_HZ 7 Hz
Rate.RATE_12_5_HZ 12.5 Hz