MicroPython HTU21DF Driver

htu21df

MicroPython HTU21D-F Temperature & Humidity driver

  • Author(s): ktown, Jose D. Montoya

class micropython_htu21df.htu21df.HTU21DF(i2c, address: int = 0x40)[source]

Driver for the HTU21DF Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the HTU21DF is connected to.

address : int

The I2C device address. Defaults to 0x40

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_htu21df import htu21df

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))
htu21df = htu21df.HTU21DF(i2c)

Now you have access to the attributes

temp = htu.temperature
rh = htu.humidity
property humidity : float

The measured relative humidity in percent.

reset() None[source]

Perform a soft reset of the sensor, resetting all settings to their power-on defaults

property temp_rh_resolution : str

The temperature and relative humidity resolution

Have one of the following values: [1]

value

RH res %

T res C

0

0.04 (12bit)

0.01 (14bit)

1

0.7 (8bit)

0.04 (12bit)

2

0.17 (10bit)

0.02 (13bit)

3

0.08 (11bit)

0.08 (11bit)

property temperature : float

The measured temperature in Celsius.