MicroPython SHT4X Library

sht4x

MicroPython Driver fot the Sensirion Temperature and Humidity SHT40, SHT41 and SHT45 Sensor

  • Author: Jose D. Montoya

class micropython_sht4x.sht4x.SHT4X(i2c, address: int = 0x44)[source]

Driver for the SHT4X Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the SHT4X is connected to.

address : int

The I2C device address. Defaults to 0x44

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_sht4x import sht4x

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))
sht = sht4x.SHT4X(i2c)

Now you have access to the attributes

temp = sht.temperature
hum = sht.relative_humidity
property heat_time : str

Sensor heat_time The sensor has a heater. Three heating powers and two heating durations are selectable. The sensor executes the following procedure: 1. The heater is enabled, and the timer starts its count-down. 2. Measure is taken after time is up 3. After the measurement is finished the heater is turned off. 4. Temperature and humidity values are now available for readout. The maximum on-time of the heater commands is one second in order to prevent overheating

Mode

Value

sht4x.TEMP_1

0

sht4x.TEMP_0_1

1

property heater_power : str

Sensor heater power The sensor has a heater. Three heating powers and two heating durations are selectable. The sensor executes the following procedure: 1. The heater is enabled, and the timer starts its count-down. 2. Measure is taken after time is up 3. After the measurement is finished the heater is turned off. 4. Temperature and humidity values are now available for readout. The maximum on-time of the heater commands is one second in order to prevent overheating

Mode

Value

sht4x.HEATER200mW

0

sht4x.HEATER110mW

1

sht4x.HEATER20mW

2

property measurements : tuple[float, float]

both temperature and relative_humidity, read simultaneously If you use t the heater function, sensor will be not give a response back. Waiting time is added to the logic to account for this situation

property relative_humidity : float

The current relative humidity in % rH The RH conversion formula (1) allows values to be reported which are outside the range of 0 %RH … 100 %RH. Relative humidity values which are smaller than 0 %RH and larger than 100 %RH are non-physical, however these “uncropped” values might be found beneficial in some cases (e.g. when the distribution of the sensors at the measurement boundaries are of interest)

reset()[source]

Reset the sensor

property temperature : float

The current temperature in Celsius

property temperature_precision : str

Sensor temperature_precision

Mode

Value

sht4x.HIGH_PRECISION

0

sht4x.MEDIUM_PRECISION

1

sht4x.LOW_PRECISION

2