|
| 1 | +# WSEN-HIDS MicroPython Driver |
| 2 | + |
| 3 | +MicroPython driver for the **Würth Elektronik WSEN-HIDS** humidity and temperature sensor. |
| 4 | + |
| 5 | +The driver provides an easy-to-use API for reading **relative humidity** and **temperature** using the sensor’s **I²C interface**. |
| 6 | + |
| 7 | +The implementation is designed for **MicroPython** and integrates with the **STeaMi ecosystem**. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +# Features |
| 12 | + |
| 13 | +* I²C communication |
| 14 | +* Relative humidity measurement |
| 15 | +* Temperature measurement |
| 16 | +* One-shot measurement mode |
| 17 | +* Continuous measurement mode |
| 18 | +* Configurable internal averaging |
| 19 | +* Heater control |
| 20 | +* Calibration handling |
| 21 | +* Data-ready status helpers |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +# Supported Sensor |
| 26 | + |
| 27 | +This driver targets: |
| 28 | + |
| 29 | +**WSEN-HIDS – 2525020210001** |
| 30 | + |
| 31 | +Main characteristics: |
| 32 | + |
| 33 | +| Parameter | Value | |
| 34 | +| -------------------- | ----------------- | |
| 35 | +| Interface | I²C | |
| 36 | +| Default I²C address | `0x5F` | |
| 37 | +| Humidity range | 0–100 %RH | |
| 38 | +| Temperature range | −40 °C to +120 °C | |
| 39 | +| Humidity accuracy | ±1.8 %RH | |
| 40 | +| Temperature accuracy | ±0.2 °C | |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +# Quick Example |
| 45 | + |
| 46 | +```python |
| 47 | +from machine import I2C, Pin |
| 48 | +from time import sleep |
| 49 | +from wsen_hids import WSEN_HIDS |
| 50 | + |
| 51 | +i2c = I2C( |
| 52 | + 0, |
| 53 | + scl=Pin(9), |
| 54 | + sda=Pin(8), |
| 55 | + freq=100000, |
| 56 | +) |
| 57 | + |
| 58 | +sensor = WSEN_HIDS(i2c) |
| 59 | + |
| 60 | +while True: |
| 61 | + humidity, temperature = sensor.read_one_shot() |
| 62 | + |
| 63 | + print("Humidity: {:.2f} %RH".format(humidity)) |
| 64 | + print("Temperature: {:.2f} °C".format(temperature)) |
| 65 | + |
| 66 | + sleep(1) |
| 67 | +``` |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +# API Overview |
| 72 | + |
| 73 | +## Initialization |
| 74 | + |
| 75 | +```python |
| 76 | +sensor = WSEN_HIDS(i2c) |
| 77 | +``` |
| 78 | + |
| 79 | +Optional parameters: |
| 80 | + |
| 81 | +```python |
| 82 | +sensor = WSEN_HIDS( |
| 83 | + i2c, |
| 84 | + address=0x5F, |
| 85 | + check_device=True, |
| 86 | + enable_bdu=True, |
| 87 | +) |
| 88 | +``` |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +# Reading Measurements |
| 93 | + |
| 94 | +### Combined reading |
| 95 | + |
| 96 | +```python |
| 97 | +humidity, temperature = sensor.read() |
| 98 | +``` |
| 99 | + |
| 100 | +### Humidity only |
| 101 | + |
| 102 | +```python |
| 103 | +humidity = sensor.humidity() |
| 104 | +``` |
| 105 | + |
| 106 | +### Temperature only |
| 107 | + |
| 108 | +```python |
| 109 | +temperature = sensor.temperature() |
| 110 | +``` |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +# One-Shot Measurement |
| 115 | + |
| 116 | +Trigger a single conversion: |
| 117 | + |
| 118 | +```python |
| 119 | +humidity, temperature = sensor.read_one_shot() |
| 120 | +``` |
| 121 | + |
| 122 | +You can specify a timeout: |
| 123 | + |
| 124 | +```python |
| 125 | +sensor.read_one_shot(timeout_ms=500) |
| 126 | +``` |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +# Continuous Measurement Mode |
| 131 | + |
| 132 | +Start continuous measurements: |
| 133 | + |
| 134 | +```python |
| 135 | +sensor.set_continuous_mode(WSEN_HIDS.ODR_1_HZ) |
| 136 | +``` |
| 137 | + |
| 138 | +Available output data rates: |
| 139 | + |
| 140 | +```python |
| 141 | +WSEN_HIDS.ODR_1_HZ |
| 142 | +WSEN_HIDS.ODR_7_HZ |
| 143 | +WSEN_HIDS.ODR_12_5_HZ |
| 144 | +``` |
| 145 | + |
| 146 | +Return to one-shot mode: |
| 147 | + |
| 148 | +```python |
| 149 | +sensor.set_one_shot_mode() |
| 150 | +``` |
| 151 | + |
| 152 | +--- |
| 153 | + |
| 154 | +# Averaging Configuration |
| 155 | + |
| 156 | +Configure internal measurement averaging: |
| 157 | + |
| 158 | +```python |
| 159 | +sensor.set_average(avg_t=WSEN_HIDS.AVG_16, avg_h=WSEN_HIDS.AVG_16) |
| 160 | +``` |
| 161 | + |
| 162 | +Available options: |
| 163 | + |
| 164 | +``` |
| 165 | +AVG_2 |
| 166 | +AVG_4 |
| 167 | +AVG_8 |
| 168 | +AVG_16 |
| 169 | +AVG_32 |
| 170 | +AVG_64 |
| 171 | +AVG_128 |
| 172 | +AVG_256 |
| 173 | +``` |
| 174 | + |
| 175 | +Higher averaging improves noise performance but increases conversion time. |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +# Heater Control |
| 180 | + |
| 181 | +The sensor contains an internal heater to help remove condensation. |
| 182 | + |
| 183 | +Enable heater: |
| 184 | + |
| 185 | +```python |
| 186 | +sensor.enable_heater(True) |
| 187 | +``` |
| 188 | + |
| 189 | +Disable heater: |
| 190 | + |
| 191 | +```python |
| 192 | +sensor.enable_heater(False) |
| 193 | +``` |
| 194 | + |
| 195 | +⚠️ Measurements should **not be taken while the heater is active**. |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +# Status Helpers |
| 200 | + |
| 201 | +Check measurement readiness: |
| 202 | + |
| 203 | +```python |
| 204 | +sensor.status() |
| 205 | +sensor.humidity_ready() |
| 206 | +sensor.temperature_ready() |
| 207 | +sensor.data_ready() |
| 208 | +``` |
| 209 | + |
| 210 | +These helpers read the **STATUS register** and indicate when fresh data is available. |
| 211 | + |
| 212 | +--- |
| 213 | + |
| 214 | +# Calibration |
| 215 | + |
| 216 | +The driver automatically reads the sensor’s **factory calibration coefficients** during initialization and applies the conversion formulas internally. |
| 217 | + |
| 218 | +No user calibration is required. |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +# Examples |
| 223 | + |
| 224 | +Example scripts are located in: |
| 225 | + |
| 226 | +``` |
| 227 | +examples/ |
| 228 | +``` |
| 229 | + |
| 230 | +Examples include: |
| 231 | + |
| 232 | +* basic one-shot measurements |
| 233 | +* continuous measurement mode |
| 234 | +* driver validation tests |
| 235 | + |
| 236 | +Run an example using: |
| 237 | + |
| 238 | +```bash |
| 239 | +mpremote mount lib/wsen-hids run lib/wsen-hids/examples/example1.py |
| 240 | +``` |
0 commit comments