Skip to content

wsen-hids: Add driver for humdity and temperature.#11

Merged
nedseb merged 6 commits intomainfrom
wsen-hids
Mar 12, 2026
Merged

wsen-hids: Add driver for humdity and temperature.#11
nedseb merged 6 commits intomainfrom
wsen-hids

Conversation

@Charly-sketch
Copy link
Copy Markdown
Contributor

Resolves #6

Add WSEN-HIDS MicroPython Driver

This PR adds a MicroPython driver for the Würth Elektronik WSEN-HIDS humidity and temperature sensor.

The driver provides an easy-to-use interface for reading relative humidity and temperature via I²C and follows the structure used by the other drivers in this repository.

The implementation targets the WSEN-HIDS 2525020210001 sensor.


Features

  • I²C communication
  • Relative humidity measurement
  • Temperature measurement
  • One-shot measurement mode
  • Continuous measurement mode
  • Configurable internal averaging
  • Heater control
  • Status helpers for data-ready detection
  • Automatic loading of factory calibration coefficients
  • Custom exceptions for error handling

Driver Structure

lib/wsen-hids
│
├── manifest.py
├── README.md
├── examples
│   ├── one_shot_mode.py
│   ├── continuous_mode.py
│   └── test.py
│
└── wsen_hids
    ├── __init__.py
    ├── const.py
    ├── device.py
    └── exceptions.py

The structure follows the layout used by other drivers in micropython-steami-lib.


API Overview

Initialization:

sensor = WSEN_HIDS(i2c)

Read humidity and temperature:

humidity, temperature = sensor.read()

One-shot measurement:

humidity, temperature = sensor.read_one_shot()

Continuous mode:

sensor.set_continuous_mode(WSEN_HIDS.ODR_1_HZ)

Additional features:

sensor.humidity()
sensor.temperature()

sensor.enable_heater(True)
sensor.set_average(avg_t, avg_h)

sensor.status()
sensor.humidity_ready()
sensor.temperature_ready()
sensor.data_ready()

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new MicroPython driver package for the Würth Elektronik WSEN-HIDS (2525020210001) humidity/temperature sensor, including a public API, constants, examples, and documentation, following the repository’s driver-per-sensor layout.

Changes:

  • Introduces the wsen_hids driver implementation (I²C register access, calibration reading, one-shot and continuous measurement).
  • Adds package metadata (manifest.py), module exports, and custom exception types.
  • Adds README and multiple example scripts, including a more extensive test.py validation script.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
lib/wsen-hids/wsen_hids/device.py Core driver logic: configuration, status helpers, raw reads, conversions, one-shot and continuous modes
lib/wsen-hids/wsen_hids/const.py Register map and bit definitions, plus averaging/timeout defaults
lib/wsen-hids/wsen_hids/exceptions.py Driver-specific exception hierarchy
lib/wsen-hids/wsen_hids/init.py Public module export for WSEN_HIDS
lib/wsen-hids/manifest.py Package metadata and package declaration
lib/wsen-hids/examples/continuous_mode.py Example for continuous measurement usage
lib/wsen-hids/examples/oneShot_mode.py Example for one-shot measurement usage
lib/wsen-hids/examples/test.py Manual validation/test script for sensor + driver behavior
lib/wsen-hids/README.md Driver documentation and usage overview

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/wsen-hids/wsen_hids/const.py Outdated
Comment thread lib/wsen-hids/wsen_hids/const.py Outdated
Comment thread lib/wsen-hids/examples/oneShot_mode.py Outdated
Comment thread lib/wsen-hids/examples/oneShot_mode.py Outdated
Comment thread lib/wsen-hids/examples/continuous_mode.py Outdated
Comment thread lib/wsen-hids/manifest.py Outdated
Comment thread lib/wsen-hids/examples/test.py Outdated
Comment thread lib/wsen-hids/wsen_hids/device.py Outdated
Comment thread lib/wsen-hids/wsen_hids/device.py Outdated
Comment thread lib/wsen-hids/examples/test.py Outdated
@nedseb nedseb added the enhancement New feature or request label Mar 11, 2026
Copy link
Copy Markdown
Contributor

@nedseb nedseb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Corrections appliquées (39798bd)

  1. const.py : ajout de micropython.const() — Toutes les constantes utilisent maintenant const() pour réduire l'usage RAM sur MicroPython, conformément à la convention du projet.
  2. manifest.py — Description corrigée : "Driver of" → "Driver for the" (cohérence avec les autres drivers).

Points déjà corrigés par Charly (dadcf87)

  • ✅ Renommage oneShot_mode.pyone_shot_mode.py
  • ✅ Suppression imports Pin inutiles dans les 3 exemples
  • ✅ Traduction commentaires français → anglais (device.py, test.py)
  • ✅ README : example1.pycontinuous_mode.py
  • ✅ Suppression _buffer_2 / _buffer_4 inutilisés
  • ✅ Correction commentaire AVG_H_DEFAULT (32 → 16 samples)
  • ✅ Déplacement DEFAULT_ONE_SHOT_TIMEOUT_MS / DEFAULT_BOOT_TIME_MS dans la classe

Remarques (non bloquantes)

  • examples/test.py est un script de test exhaustif (~300 lignes). Un renommage en full_test.py pourrait clarifier son rôle par rapport aux exemples d'usage (one_shot_mode.py, continuous_mode.py).
  • read() en mode power-down : après l'init, le capteur est en mode one-shot et read() lit les registres sans déclencher de conversion. Un utilisateur qui appelle sensor.read() directement après init obtiendra les dernières données en mémoire. Ce comportement est acceptable mais mériterait une note dans le README ou la docstring.

Tests

Tous les tests passent (mock + hardware) :

  • Mock : humidity 50.00 %RH, temperature 25.00 °C ✅
  • Hardware : humidity 36.17 %RH, temperature 20.30 °C ✅

@nedseb
Copy link
Copy Markdown
Contributor

nedseb commented Mar 12, 2026

Complément à la revue : le point sur read() en mode power-down a été formalisé dans l'issue #44 pour traiter le problème de manière uniforme sur tous les drivers.

@nedseb nedseb merged commit c7c7833 into main Mar 12, 2026
3 checks passed
@nedseb nedseb deleted the wsen-hids branch March 12, 2026 10:39
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wsen-hids: Add WSEN-HIDS humidity and temperature sensor driver

3 participants