https://github.com/2black0/micropython-sht11
sht11 module for micropython
https://github.com/2black0/micropython-sht11
micropython sensor sht11 sht1x
Last synced: 18 days ago
JSON representation
sht11 module for micropython
- Host: GitHub
- URL: https://github.com/2black0/micropython-sht11
- Owner: 2black0
- License: mit
- Created: 2020-06-27T05:26:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-27T05:46:18.000Z (almost 5 years ago)
- Last Synced: 2024-04-22T13:30:46.466Z (about 1 year ago)
- Topics: micropython, sensor, sht11, sht1x
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - micropython-sht11 - Driver for Sensirion SHT11 temperature and humidity sensor. (Libraries / Sensors)
README
# ๐ฑ MicroPython SHT11 Temperature & Humidity Sensor
This project demonstrates how to interface the **SHT11 sensor** with a **MicroPython-compatible ESP32 board (e.g., Lolin32 Lite)** to measure **temperature** and **relative humidity**. It uses **bit-banged communication** and is written fully in MicroPython.
---
## ๐ Project Structure
```
MicroPython-SHT11
โโโ LICENSE # License file (e.g., MIT)
โโโ README.md # This documentation
โโโ project/
โโโ main.py # Main script to read and display sensor values
โโโ sht11.py # SHT11 driver implementation in MicroPython
```---
## ๐ฆ Requirements
* โ๏ธ **MicroPython board**: Tested on Lolin32 Lite (ESP32)
* ๐ก๏ธ **Sensor**: Sensirion SHT11 (Digital Temp & RH sensor)
* ๐ง **Firmware**: MicroPython 1.20 or later
* ๐งฐ **Development tools**:* [Thonny IDE](https://thonny.org/) or [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html)
* USB to Serial connection---
## ๐ Wiring
| SHT11 Pin | Description | ESP32 Pin (Example) |
| --------- | ------------ | ------------------- |
| 1 (SCK) | Clock | GPIO 26 |
| 2 (DATA) | Data | GPIO 33 |
| 3 (GND) | Ground | GND |
| 4 (VCC) | Power (3.3V) | 3.3V |> โ ๏ธ Note: Do **not** power SHT11 with 5V โ it's a 3.3V device.
---
## ๐งช Example Usage
In the `main.py`:
```python
# example code to read SHT11 using MicroPython
# author : Ardy Seto P
# email : [email protected]
# board : Lolin32 Lite (ESP32)from sht11 import SHT11
# Define SCK and DATA GPIO pins
sht = SHT11(sck=26, data=33)# Read temperature and humidity
tempOut = sht.temperature()
humOut = sht.humidity()# Display results
print('Temperature: ', tempOut, '*C')
print('Humidity: ', humOut, '%')
```---
## ๐ง Features of the `SHT11` Driver
* ๐ก Pure MicroPython bit-banged protocol (no I2C)
* ๐ Reads:* Temperature (ยฐC)
* Relative Humidity (%RH)
* โ Includes:* CRC check
* Command protocol implementation
* Adjustable temperature compensation for RH### Key Methods
```python
SHT11(sck, data) # Initialize driver with SCK and DATA pins
.temperature() # Return temperature in ยฐC
.humidity(temp=25) # Return relative humidity (%), with temp compensation
.read_register() # Read status register (raw access)
```---
## โ๏ธ Advanced Notes
* This driver replicates the SHT11 protocol using direct GPIO pin manipulation.
* Built-in CRC-8 validation helps detect communication errors.
* The `.humidity()` method includes temperature compensation if called with custom temperature values.---
## ๐ก Troubleshooting
* โ **CRC or ACK errors**: Make sure your wires are short and well-connected. SHT11 is sensitive to interference.
* ๐ **Slow reads?** SHT11 has \~200โ300 ms measurement latency; this is normal.
* ๐ **Values look wrong?** Double-check power source and resistor pull-up configuration (if needed).---
## ๐ License
This project is open-source under the [MIT License](LICENSE).
---
## ๐ค Author
**Ardy Seto Priambodo**
โ๏ธ [[email protected]](mailto:[email protected])