import sht4x
The sht4x module reads Sensirion SHT40, SHT41, and SHT45 temperature/humidity sensors over I2C. It verifies readings with the Sensirion CRC and returns simple temperature and relative-humidity values for scheduled Studio scripts.
Quick example
import sht4x
if sht4x.begin(21, 22):
reading = sht4x.read()
print(reading["c"])
print(reading["humidity"])
sht4x.configure("medium")
importsht4x
SHT4x temperature and humidity module.
The sht4x module reads Sensirion SHT40, SHT41, and SHT45 temperature/humidity sensors over I2C. It verifies readings with the Sensirion CRC and returns simple temperature and relative-humidity values for scheduled Studio scripts.
sht4x.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> bool
sht4x.begin(sda: int, scl: int, address: int = None, frequency: int = None, port: int = None) -> boolInitialize an SHT4x sensor on I2C.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
sda |
int |
positional or keyword | Yes | GPIO pin used for I2C SDA. |
scl |
int |
positional or keyword | Yes | GPIO pin used for I2C SCL. |
address |
int |
positional or keyword | No | Optional I2C address. Defaults to 0x44. |
frequency |
int |
positional or keyword | No | Optional I2C bus speed in hertz. Defaults to 100000. |
port |
int |
positional or keyword | No | Optional ESP-IDF I2C port number. Defaults to 0. |
bool True when the sensor responds to the serial-number command with valid CRC bytes.
sht4x.configure(precision: str = None) -> bool
sht4x.configure(precision: str = None) -> boolSet the default measurement precision.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
precision |
str |
positional or keyword | No | Optional precision string. Use "high", "medium", or "low". Defaults to "high". |
bool True when the precision is accepted.
sht4x.read(precision: str = None) -> dict
sht4x.read(precision: str = None) -> dictRead temperature and relative humidity.
The command is blocking for the selected precision: about 10 ms for high, 5 ms for medium, and 2 ms for low.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
precision |
str |
positional or keyword | No | Optional precision string for this read only. Use "high", "medium", or "low". |
dict Dict with ``ok``, ``c``, ``f``, ``temperature``, ``humidity``, ``raw_temperature``, ``raw_humidity``, ``precision``, ``address``, and ``serial`` fields.
sht4x.temperature(precision: str = None) -> float
sht4x.temperature(precision: str = None) -> floatRead temperature in Celsius.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
precision |
str |
positional or keyword | No | Optional precision string for this read only. Use "high", "medium", or "low". |
float Float temperature in degrees Celsius.
sht4x.humidity(precision: str = None) -> float
sht4x.humidity(precision: str = None) -> floatRead relative humidity.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
precision |
str |
positional or keyword | No | Optional precision string for this read only. Use "high", "medium", or "low". |
float Float relative humidity percentage, clamped to 0 through 100.
sht4x.heater(power: str = None, duration_ms: int = None) -> dict
sht4x.heater(power: str = None, duration_ms: int = None) -> dictActivate the SHT4x heater and return the following measurement.
Use this sparingly for condensation recovery or diagnostics. The firmware maps duration values at or below 500 ms to the short heater command and larger values to the long heater command.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
power |
str |
positional or keyword | No | Optional heater power string. Use "low", "medium", or "high". Defaults to "low". |
duration_ms |
int |
positional or keyword | No | Optional heater duration. Use about 100 or 1000 ms. Defaults to 100. |
dict Dict with the same fields as ``read()``, plus ``heater_power`` and ``heater_duration_ms``.
sht4x.serial() -> str
sht4x.serial() -> strRead the SHT4x serial number.
str Eight-character hex string.
sht4x.reset() -> bool
sht4x.reset() -> boolSoft-reset the SHT4x sensor.
bool True when reset succeeds and the serial number can be read again.
sht4x.info() -> dict
sht4x.info() -> dictReturn SHT4x module state.
dict Dict with initialization state, I2C pins, address, frequency, port, precision, and serial number.