MicroPython HTU31D Driver

htu31d

MicroPython library for TE HTU31D temperature and humidity sensors

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

class micropython_htu31d.htu31d.HTU31D(i2c, address: int = 0x40)[source]

Driver for the HTU31D Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the HTU31D is connected to.

address : int

The I2C device address. Defaults to 0x40

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_htu31d import htu31d

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))
htu31d = htu31d.HTU31D(i2c)

Now you have access to the temperature and relative_humidity attributes

temperature = htu.temperature
relative_humidity = htu.relative_humidity
property heater : bool

The current sensor heater mode

property humidity_resolution : '0.020%' | '0.014%' | '0.010%' | '0.007%'

The current relative humidity resolution in % rH.

Possibles values:

  • “0.020%”

  • “0.014%”

  • “0.010%”

  • “0.007%”

property measurements : tuple[float, float]

both temperature and relative_humidity, read simultaneously

property relative_humidity : float

The current relative humidity in % rH

reset() None[source]

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

property serial_number : tuple[Any, ...]

The unique 32-bit serial number

property temp_resolution : '0.040' | '0.025' | '0.016' | '0.012'

The current temperature resolution in Celsius.

Possibles values:

  • “0.040”

  • “0.025”

  • “0.016”

  • “0.012”

property temperature : float

The current temperature in Celsius