MicroPython HTS221 Driver

hts221

MicroPython Driver for the HTS221 Humidity Sensor

  • Author: Jose D. Montoya

class micropython_hts221.hts221.HTS221(i2c, address: int = 0x5F)[source]

Driver for the HTS221 Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the HTS221 is connected to.

address : int

The I2C device address. Defaults to 0x5F

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_hts221 import hts221

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

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
hts221 = hts221.HTS221(i2c)

Now you have access to the attributes

hum = hts.relative_humidity
property block_data_update : str

Sensor block_data_update used to inhibit the output register update between the reading of the upper and lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are updated continuously. it is recommended to set the BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the content of that output register is not updated until the upper (lower) part is read also.

Mode

Value

hts221.BDU_DISABLED

0b0

hts221.BDU_ENABLED

0b1

property data_rate : str

Sensor data_rate

Note that setting data_rate to ONE_SHOT will cause relative_humidity and temperature measurements to only update when take_measurements() is called.

Mode

Value

hts221.ONE_SHOT

0b00

hts221.RATE_1_HZ

0b01

hts221.RATE_7_HZ

0b10

hts221.RATE_12_5_HZ

0b11

enabled

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

property relative_humidity : float

The current relative humidity measurement in %rH

take_measurements() None[source]

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

property temperature : float

The current temperature measurement in Celsius