SHT4x.py is a Python class for interfacing with the Sensirion SHT4x temperature and humidity sensor family via the I²C bus. This library provides methods to control the sensor, retrieve temperature and humidity readings, reset the sensor, and obtain the serial number.
Make sure you have Python 3.x installed. You can install the depending smbus2-library using pip:
foo@bar:~$pip install smbus2
from SHT4x import SHT4x
sensor = SHT4x()
To retrieve temperature and humidity readings from the sensor, call the update() method:
if sensor.update():
temperature = sensor.temperature
humidity = sensor.humidity
print(f"Temperature: {temperature}°C")
print(f"Humidity: {humidity}% RH")
else:
print("Failed to read data from the sensor.")
You can set the measurement mode using the mode property. Valid modes are e.g. "high", "medium", and "low". For example:
sensor.mode = "high"
To reset the sensor to its default state, use the reset() method:
if sensor.reset():
print("Sensor reset successful.")
else:
print("Failed to reset the sensor.")
You can obtain the serial number of the sensor using the serial_number property:
serial_number = sensor.serial_number
print(f"Serial Number: {serial_number}")
When printing a class instance you get a summarized output of the serial number the current temperature and the current humididy:
sensor = SHT4x()
sensor.update()
print(sensor)
serial number: beefbeef | temperature: 20.0°C | humidity: 45.0% RH
Please refer to the inline code comments and the class definition for detailed information about each method and property.
This library is released under the MIT License. See the LICENSE file for more details.
Contributions to the SHT4x class are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
Thorsten Schnebeck
Special thanks to the authors and contributors of the smbus2 library for providing the I2C communication functionality. This documentation was generated by ChatGPT 3.5