adafruit_htu21d

This is a breakout for the Adafruit HTU21D-F Temperature & Humidity Sensor Breakout Board

  • Author(s): ktown

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_htu21d.HTU21D(i2c_bus: I2C, address: int = 64)

A driver for the HTU21D-F temperature and humidity sensor.

Parameters:
  • i2c_bus – The I2C bus the device is connected to

  • address (int) – (optional) The I2C address of the device. Defaults to 0x40

Quickstart: Importing and using the HTU21D-F

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

import board
from adafruit_htu21d import HTU21D

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
sensor = HTU21D(i2c)

Now you have access to the temperature and relative_humidity attributes

temperature = sensor.temperature
relative_humidity = sensor.relative_humidity
measurement(what: Literal[245, 243]) float

Starts a measurement. Starts a measurement of either HUMIDITY or TEMPERATURE depending on the what argument. Returns immediately, and the result of the measurement can be retrieved with the temperature and relative_humidity properties. This way it will take much less time. This can be useful if you want to start the measurement, but don’t want the call to block until the measurement is ready – for instance, when you are doing other things at the same time.

Parameters:

what (int) – What to measure, one of (HUMIDITY, TEMPERATURE).

property relative_humidity: float

The measured relative humidity in percent.

property temp_rh_resolution: int

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 degrees Celsius.

adafruit_htu21d.HUMIDITY = 245

Constant command used to measure humidity.

adafruit_htu21d.TEMPERATURE = 243

Constant command used to measure temperature.