hts221 — HTS221 humidity/temperature sensor#

Driver for the ST HTS221 capacitive relative humidity and temperature sensor over I2C. The driver reads the factory calibration values from non-volatile memory on construction and uses them to convert the raw register readings into calibrated values.

Example:

import time
from machine import Pin, I2C
from hts221 import HTS221

bus = I2C(1, scl=Pin("P15"), sda=Pin("P14"))
hts = HTS221(bus)

while True:
    print("rH: %.2f%% T: %.2fC" % (hts.humidity(), hts.temperature()))
    time.sleep_ms(100)

Classes#

class hts221.HTS221(bus: machine.I2C, data_rate: int = 1, address: int = 0x5F)#

Construct an HTS221 instance.

bus

A configured machine.I2C bus the sensor is attached to.

data_rate

Output data-rate selector written into the CTRL_REG1 ODR field. Valid values are 0 (one-shot), 1 (1 Hz), 2 (7 Hz) and 3 (12.5 Hz).

address

7-bit I2C address of the device. Defaults to 0x5F, the factory address used by all HTS221 parts.

humidity() float#

Read the humidity output registers and return the relative humidity in percent (%RH), already compensated using the calibration values stored on the device.

temperature() float#

Read the temperature output registers and return the temperature in degrees Celsius, already compensated using the calibration values stored on the device.