https://github.com/schnebeck/sht4x_python
a python class intended for reading Sensirion SHT4x device family through the i²c bus
https://github.com/schnebeck/sht4x_python
humidity i2c python sensirion sensor sht40 sht41 sht45 temperature
Last synced: 8 months ago
JSON representation
a python class intended for reading Sensirion SHT4x device family through the i²c bus
- Host: GitHub
- URL: https://github.com/schnebeck/sht4x_python
- Owner: schnebeck
- License: mit
- Created: 2023-05-29T19:56:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-30T18:01:10.000Z (over 2 years ago)
- Last Synced: 2025-02-06T04:57:48.060Z (11 months ago)
- Topics: humidity, i2c, python, sensirion, sensor, sht40, sht41, sht45, temperature
- Language: Python
- Homepage: https://github.com/schnebeck/SHT4x-python
- Size: 16.6 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SHT4x-python
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.
## Installation
Make sure you have Python 3.x installed. You can install the depending smbus2-library using pip:
```console
foo@bar:~$pip install smbus2
```
## Usage
### Import the `SHT4x` class from the library:
```python
from SHT4x import SHT4x
```
### Create an instance of the SHT4x class:
```python
sensor = SHT4x()
```
### Reading Temperature and Humidity
To retrieve temperature and humidity readings from the sensor, call the update() method:
```python
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.")
```
### Setting the Measurement Mode
You can set the measurement mode using the mode property. Valid modes are e.g. "high", "medium", and "low". For example:
```python
sensor.mode = "high"
```
### Resetting the Sensor
To reset the sensor to its default state, use the reset() method:
```python
if sensor.reset():
print("Sensor reset successful.")
else:
print("Failed to reset the sensor.")
```
### Retrieving the Serial Number
You can obtain the serial number of the sensor using the serial_number property:
```python
serial_number = sensor.serial_number
print(f"Serial Number: {serial_number}")
```
### Printing a class instance
When printing a class instance you get a summarized output of the serial number the current temperature and the current humididy:
```python
sensor = SHT4x()
sensor.update()
print(sensor)
```
```output
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.
## License
This library is released under the MIT License. See the LICENSE file for more details.
## Contributing
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.
## Author
Thorsten Schnebeck
## Acknowledgments
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