Simple test
Ensure your device works with this simple test.
examples/sht4x_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2020 ladyada for Adafruit Industries
2#
3# SPDX-License-Identifier: MIT
4
5import time
6
7import board
8
9import adafruit_sht4x
10
11i2c = board.I2C() # uses board.SCL and board.SDA
12# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
13sht = adafruit_sht4x.SHT4x(i2c)
14print("Found SHT4x with serial number", hex(sht.serial_number))
15
16sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION
17# Can also set the mode to enable heater
18# sht.mode = adafruit_sht4x.Mode.LOWHEAT_100MS
19print("Current mode is: ", adafruit_sht4x.Mode.string[sht.mode])
20
21while True:
22 temperature, relative_humidity = sht.measurements
23 print("Temperature: %0.1f C" % temperature)
24 print("Humidity: %0.1f %%" % relative_humidity)
25 print("")
26 time.sleep(1)