def initialize_input(self): import adafruit_sht4x from adafruit_extended_bus import ExtendedI2C try: self.sensor = adafruit_sht4x.SHT4x( ExtendedI2C(self.input_dev.i2c_bus), address=int(str(self.input_dev.i2c_location), 16)) except: self.logger.exception("Setting up sensor")
def ensure_sensor(self) -> None: if not self._sensor: log.debug(f"Initializing temp sensor {self._sensor_addr}") self._sensor_init_count += 1 i2c = busio.I2C(board.SCL, board.SDA) self._sensor = adafruit_sht4x.SHT4x(i2c) log.debug( f"Found SHT4x with serial number {hex(self._sensor.serial_number)}" ) self._sensor.mode = adafruit_sht4x.Mode.MEDHEAT_1S log.debug( "SHT4x mode is: {adafruit_sht4x.Mode.string[self._sensor.mode]}" )
def read_sht40(self): """ @brief Read sht40 raspberry pi i2c bus Get temperatue, humidity """ try: with I2C(self._bus) as i2c: sht = adafruit_sht4x.SHT4x(i2c) sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION time.sleep(1) temperature, humidity = sht.measurements if self._debug: print("Temperature: %.3f °c" % temperature) print("Humidity: %.3f %%" % humidity) return temperature, humidity except Exception as e: print("cannot read sht40, An exception occurred: {}".format(e))
# SPDX-FileCopyrightText: Copyright (c) 2020 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT import time import busio import board import adafruit_sht4x i2c = busio.I2C(board.SCL, board.SDA) sht = adafruit_sht4x.SHT4x(i2c) print("Found SHT4x with serial number", hex(sht.serial_number)) sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION # Can also set the mode to enable heater # sht.mode = adafruit_sht4x.Mode.LOWHEAT_100MS print("Current mode is: ", adafruit_sht4x.Mode.string[sht.mode]) while True: temperature, relative_humidity = sht.measurements print("Temperature: %0.1f C" % temperature) print("Humidity: %0.1f %%" % relative_humidity) print("") time.sleep(1)