Simple test

Ensure your device works with this simple test.

examples/htu31d_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2020 ladyada for Adafruit Industries
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import time
 6import board
 7import adafruit_htu31d
 8
 9i2c = board.I2C()  # uses board.SCL and board.SDA
10htu = adafruit_htu31d.HTU31D(i2c)
11print("Found HTU31D with serial number", hex(htu.serial_number))
12
13htu.heater = True
14print("Heater is on?", htu.heater)
15htu.heater = False
16print("Heater is on?", htu.heater)
17
18while True:
19    temperature, relative_humidity = htu.measurements
20    print("Temperature: %0.1f C" % temperature)
21    print("Humidity: %0.1f %%" % relative_humidity)
22    print("")
23    time.sleep(1)

Setting Resolution Example

Show how to setup Relative Humidity and Temperature Sensor Resolutions

examples/htu31d_setting_resolutions.py
 1# SPDX-FileCopyrightText: Copyright (c) 2021 Jose David M.
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import board
 6import adafruit_htu31d
 7
 8
 9# import htu31d_setting_resolutions
10i2c = board.I2C()
11htu = adafruit_htu31d.HTU31D(i2c)
12
13
14print("Temperature Resolution: ", htu.temp_resolution)
15print("Humidity Resolution: ", htu.humidity_resolution)
16
17
18# Setting the temperature resolution.
19# Possible values are "0.040", "0.025", "0.016" and "0.012"
20htu.temp_resolution = "0.016"
21
22# Setting the Relative Humidity resolution.
23# Possible values are "0.020%", "0.014%", "0.010%" and "0.007%"
24htu.humidity_resolution = "0.007%"
25
26
27# Printing the New Values
28print("Temperature Resolution: ", htu.temp_resolution)
29print("Humidity Resolution: ", htu.humidity_resolution)