-
Notifications
You must be signed in to change notification settings - Fork 1
docs: Expand README for hts221 driver. #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,139 @@ | ||
| # MicroPython Driver for the HTS221 Humidity Sensor | ||
| # HTS221 MicroPython Driver | ||
|
|
||
| This library is a port of the [MicroPython Driver for the HTS221 Humidity Sensor](https://github.com/jposada202020/MicroPython_HTS221/tree/master). | ||
| MicroPython driver for the **STMicroelectronics HTS221** humidity and temperature sensor. | ||
|
|
||
| The examples could be easily tested with [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) with the following command : | ||
| This library is a port of [MicroPython_HTS221](https://github.com/jposada202020/MicroPython_HTS221). | ||
|
|
||
| ```sh | ||
| mpremote mount . run examples/humidity.py | ||
| ## Supported Sensor | ||
|
|
||
| | Parameter | Value | | ||
| | -------------------- | ----------------- | | ||
| | Interface | I²C | | ||
| | Default I²C address | `0x5F` | | ||
| | Device ID | `0xBC` | | ||
| | Humidity range | 0–100 %RH | | ||
| | Humidity accuracy | ±3.5 %RH | | ||
| | Temperature range | −40 to +120 °C | | ||
| | Temperature accuracy | ±0.5 °C | | ||
|
|
||
| ## Features | ||
|
|
||
| * I²C communication | ||
| * Device identification (`WHO_AM_I`) | ||
| * Humidity and temperature measurement | ||
| * One-shot and continuous measurement modes | ||
| * Configurable output data rate (ODR) | ||
| * Configurable averaging | ||
| * Data-ready status flags | ||
| * Power management (on/off, reboot) | ||
| * Factory calibration (automatic) | ||
| * User temperature calibration (offset and two-point) | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ```python | ||
| from machine import I2C | ||
| from hts221 import HTS221 | ||
|
|
||
| i2c = I2C(1) | ||
| sensor = HTS221(i2c) | ||
|
|
||
| humidity = sensor.humidity() | ||
| temperature = sensor.temperature() | ||
|
|
||
| print("Humidity:", humidity, "%") | ||
| print("Temperature:", temperature, "°C") | ||
|
|
||
| # Read both at once | ||
| h, t = sensor.read() | ||
| ``` | ||
|
|
||
| ## API Reference | ||
|
|
||
| ### Initialization | ||
|
|
||
| ```python | ||
| sensor = HTS221(i2c, address=0x5F) | ||
| ``` | ||
|
|
||
| ### Device Information | ||
|
|
||
| ```python | ||
| sensor.device_id() | ||
| ``` | ||
|
|
||
| Returns the sensor device ID (`WHO_AM_I` register, expected `0xBC`). | ||
|
|
||
| ### Measurements | ||
|
|
||
| * `sensor.temperature()` — temperature in °C | ||
| * `sensor.humidity()` — relative humidity in % | ||
| * `sensor.read()` — returns `(humidity, temperature)` | ||
| * `sensor.read_one_shot()` — triggers a one-shot conversion and returns `(humidity, temperature)` after a fixed 15 ms delay | ||
|
|
||
| ### Data Readiness | ||
|
|
||
| * `sensor.data_ready()` — `True` when both humidity and temperature are available | ||
| * `sensor.temperature_ready()` — `True` when temperature is available | ||
| * `sensor.humidity_ready()` — `True` when humidity is available | ||
|
|
||
| ### One-Shot Mode | ||
|
|
||
| ```python | ||
| sensor.trigger_one_shot() | ||
| ``` | ||
|
|
||
| Triggers a single conversion with a 15 ms delay. Used internally by `read_one_shot()`. | ||
|
|
||
| ### Configuration | ||
|
|
||
| * `sensor.get_odr()` — returns current output data rate | ||
| * `sensor.set_odr(odr)` — set ODR (0 = one-shot, 1 = 1 Hz, 2 = 7 Hz, 3 = 12.5 Hz) | ||
| * `sensor.set_continuous(odr)` — enable continuous mode. Raises `ValueError` if `odr=0`. | ||
|
|
||
| ### Averaging | ||
|
|
||
| * `sensor.get_av()` — returns current averaging configuration register | ||
| * `sensor.set_av(av)` — set humidity and temperature averaging (raw register value) | ||
|
|
||
| The AV_CONF register controls internal averaging for both channels. Higher values improve noise but increase conversion time. Refer to the HTS221 datasheet for the register encoding. | ||
|
|
||
| ### Power Management | ||
|
|
||
| * `sensor.power_on()` — enable sensor | ||
| * `sensor.power_off()` — disable sensor | ||
| * `sensor.reboot()` — reload factory calibration data from non-volatile memory | ||
|
|
||
| ### Temperature Calibration | ||
|
|
||
| ```python | ||
| # Simple offset correction | ||
| sensor.set_temp_offset(-1.2) | ||
|
|
||
| # Two-point calibration (gain + offset) | ||
| sensor.calibrate_temperature( | ||
| ref_low=0.0, | ||
| measured_low=0.8, | ||
| ref_high=50.0, | ||
| measured_high=48.7, | ||
| ) | ||
| ``` | ||
|
|
||
| No calibration is required for basic usage — the driver applies factory calibration automatically. | ||
|
|
||
| ## Examples | ||
|
|
||
| | File | Description | | ||
| | ------------- | -------------------------------------- | | ||
| | `humidity.py` | Basic humidity and temperature reading | | ||
|
|
||
| ```bash | ||
| mpremote mount lib/hts221 run lib/hts221/examples/humidity.py | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| * The driver uses factory calibration data stored in the sensor, read automatically at initialization. | ||
| * `temperature()`, `humidity()`, and `read()` poll the sensor's status bits via `_ensure_data()` to wait for fresh data before returning. | ||
| * `read_one_shot()` triggers a conversion and waits a fixed 15 ms delay before reading registers (no status polling). | ||
| * In power-down or one-shot mode, calling a measurement method automatically triggers a new conversion. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the API section, the code blocks list method names without an instance (e.g.,
device_id()/temperature()), which reads like top-level functions. Since these are instance methods onHTS221, document them assensor.device_id(),sensor.temperature(), etc. (consistent with other driver READMEs).