-
Notifications
You must be signed in to change notification settings - Fork 1
wsen-pads: Add pressure sensor driver. #3
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
516647e
wsen-pads: Add pressure sensor driver.
Charly-sketch 010072a
wsen-pads: Fix syntax for lint with ruff.
Charly-sketch fe05f51
wsen-pads: Fix ruff new line.
Charly-sketch 97e0c27
wsen-pads: Fix copilots errors.
Charly-sketch 2bd4e04
wsen-pads: Auto-trigger one-shot when reading in power-down mode.
nedseb ad87eb0
wsen-pads: Add test scenario for pressure sensor driver.
nedseb e3b5b1a
tests: Use monotonic clock for utime ticks_ms/ticks_us stubs.
nedseb 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| # WSEN-PADS MicroPython Driver | ||
|
|
||
| MicroPython driver for the **Würth Elektronik WSEN-PADS** absolute pressure sensor. | ||
|
|
||
| This driver provides an easy-to-use API to read **pressure** and **temperature** using the I²C interface. | ||
|
|
||
| The WSEN-PADS is a high-resolution digital pressure sensor with integrated temperature measurement, designed for applications such as weather monitoring, altimetry, and environmental sensing. | ||
|
|
||
| --- | ||
|
|
||
| # Features | ||
|
|
||
| * I²C communication | ||
| * Pressure measurement | ||
| * Temperature measurement | ||
| * One-shot acquisition | ||
| * Continuous measurement mode | ||
| * Configurable Output Data Rate (ODR) | ||
| * Low-noise mode support | ||
| * Optional low-pass filter | ||
| * Soft reset and device reboot | ||
| * Raw data access | ||
|
|
||
| --- | ||
|
|
||
| # Sensor Overview | ||
|
|
||
| | Feature | Value | | ||
| | ----------------------- | ---------------------- | | ||
| | Pressure range | 26 kPa – 126 kPa | | ||
| | Pressure resolution | 24-bit | | ||
| | Temperature resolution | 16-bit | | ||
| | Pressure sensitivity | 1 / 4096 hPa per digit | | ||
| | Temperature sensitivity | 0.01 °C per digit | | ||
| | Interface | I²C / SPI | | ||
| | Maximum ODR | 200 Hz | | ||
|
|
||
| --- | ||
|
|
||
| # Hardware Connection | ||
|
|
||
| The driver currently supports **I²C mode**. | ||
|
|
||
| ## Pins | ||
|
|
||
| | Sensor Pin | Description | | ||
| | ---------- | -------------------- | | ||
| | VDD | Power supply | | ||
| | VDD_IO | Interface supply | | ||
| | GND | Ground | | ||
| | SDA | I²C data | | ||
| | SCL | I²C clock | | ||
| | CS | Must be HIGH for I²C | | ||
| | SAO | Selects I²C address | | ||
|
|
||
| ## I²C Address | ||
|
|
||
| | SAO | Address | | ||
| | ---- | ------- | | ||
| | LOW | `0x5C` | | ||
| | HIGH | `0x5D` | | ||
|
|
||
| Recommended configuration for a single device on the bus: | ||
|
|
||
| ``` | ||
| SAO = HIGH | ||
| I2C address = 0x5D | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # Installation | ||
|
|
||
| Clone the repository and copy the driver to your MicroPython device. | ||
|
|
||
| Example using **mpremote**: | ||
|
|
||
| ```bash | ||
| mpremote mount lib/wsen-pads | ||
| ``` | ||
|
|
||
| The driver will then be available as: | ||
|
|
||
| ```python | ||
| from wsen_pads import WSEN_PADS | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # Basic Usage | ||
|
|
||
| ```python | ||
| from machine import I2C, Pin | ||
| from time import sleep | ||
| from wsen_pads import WSEN_PADS | ||
|
|
||
| i2c = I2C( | ||
| 1, | ||
| scl=Pin(7), | ||
| sda=Pin(6), | ||
| ) | ||
|
|
||
| sensor = WSEN_PADS(i2c) | ||
|
|
||
| while True: | ||
| pressure, temperature = sensor.read() | ||
|
|
||
| print("Pressure:", pressure, "hPa") | ||
| print("Temperature:", temperature, "°C") | ||
| print() | ||
|
|
||
| sleep(1) | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # One-shot Measurement | ||
|
|
||
| ```python | ||
| pressure, temperature = sensor.read_one_shot() | ||
| ``` | ||
|
|
||
| This triggers a single conversion and returns the measurement. | ||
|
|
||
| --- | ||
|
|
||
| # Continuous Mode | ||
|
|
||
| ```python | ||
| from wsen_pads.const import ODR_10_HZ | ||
|
|
||
| sensor.set_continuous(odr=ODR_10_HZ) | ||
|
|
||
| pressure = sensor.pressure() | ||
| temperature = sensor.temperature() | ||
| ``` | ||
|
|
||
| Available ODR values: | ||
|
|
||
| ``` | ||
| ODR_1_HZ | ||
| ODR_10_HZ | ||
| ODR_25_HZ | ||
| ODR_50_HZ | ||
| ODR_75_HZ | ||
| ODR_100_HZ | ||
| ODR_200_HZ | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # Raw Data Access | ||
|
|
||
| Raw values from the sensor can also be read: | ||
|
|
||
| ```python | ||
| raw_pressure = sensor.pressure_raw() | ||
| raw_temperature = sensor.temperature_raw() | ||
| ``` | ||
|
|
||
| Conversions: | ||
|
|
||
| ``` | ||
| pressure_hpa = raw_pressure / 4096 | ||
| temperature_c = raw_temperature * 0.01 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # Status Helpers | ||
|
|
||
| The driver provides helper functions for checking data availability. | ||
|
|
||
| ```python | ||
| sensor.pressure_available() | ||
| sensor.temperature_available() | ||
| sensor.is_ready() | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # Device Control | ||
|
|
||
| ## Soft Reset | ||
|
|
||
| ```python | ||
| sensor.soft_reset() | ||
| ``` | ||
|
|
||
| ## Reboot Sensor | ||
|
|
||
| ```python | ||
| sensor.reboot() | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| # Examples | ||
|
|
||
| Examples are available in the `examples` directory. | ||
|
|
||
| --- | ||
|
|
||
| # Driver Structure | ||
|
|
||
| ``` | ||
| wsen-pads/ | ||
| │ | ||
| ├── README.md | ||
| ├── manifest.py | ||
| ├── examples/ | ||
| │ | ||
| └── wsen_pads/ | ||
| ├── __init__.py | ||
| ├── const.py | ||
| ├── device.py | ||
| └── exceptions.py | ||
| ``` | ||
|
|
||
| --- | ||
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from machine import I2C, Pin | ||
| from time import sleep | ||
| from wsen_pads import WSEN_PADS | ||
|
|
||
| SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation | ||
| EXPONENT = 0.1903 # standard atmosphere exponent for altitude calculation | ||
|
|
||
| i2c = I2C(1) | ||
|
|
||
| sensor = WSEN_PADS(i2c) | ||
|
|
||
| def pressure_to_altitude(p): | ||
| return 44330 * (1 - (p / SEA_LEVEL_PRESSURE) ** EXPONENT) | ||
|
|
||
| for _ in range(10): | ||
| pressure, temp = sensor.read() | ||
|
|
||
| altitude = pressure_to_altitude(pressure) | ||
|
|
||
| print("Pressure:", pressure, "hPa") | ||
| print("Altitude:", altitude, "m") | ||
| print() | ||
|
|
||
| sleep(0.5) |
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from machine import I2C, Pin | ||
| from time import sleep | ||
| from wsen_pads import WSEN_PADS | ||
|
|
||
|
|
||
| # Update the I2C bus number and pins to match your board | ||
| i2c = I2C(1) | ||
|
|
||
| # Create the sensor object | ||
| pads = WSEN_PADS(i2c) | ||
|
|
||
| print("WSEN-PADS found") | ||
| print("Device ID:", hex(pads.device_id())) | ||
|
|
||
| for _ in range(10): | ||
| pressure_hpa, temperature_c = pads.read() | ||
|
|
||
| print("P:", pressure_hpa, "hPa T:", temperature_c, "°C") | ||
|
|
||
| sleep(0.5) |
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from machine import I2C, Pin | ||
| from time import sleep | ||
| from wsen_pads import WSEN_PADS | ||
| from wsen_pads.const import ODR_10_HZ | ||
|
|
||
| i2c = I2C(1) | ||
|
|
||
| sensor = WSEN_PADS(i2c) | ||
|
|
||
| sensor.set_continuous(odr=ODR_10_HZ) | ||
|
|
||
| for _ in range(10): | ||
| pressure = sensor.pressure() | ||
| temperature = sensor.temperature() | ||
|
|
||
| print("P:", pressure, "hPa T:", temperature, "°C") | ||
|
|
||
| sleep(0.5) |
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from machine import I2C, Pin | ||
| from time import sleep | ||
| from wsen_pads import WSEN_PADS | ||
|
|
||
| i2c = I2C(1) | ||
|
|
||
| sensor = WSEN_PADS(i2c) | ||
|
|
||
| for _ in range(10): | ||
| pressure, temperature = sensor.read_one_shot() | ||
|
|
||
| print("P:", pressure, "hPa T:", temperature, "°C") | ||
|
|
||
| sleep(0.5) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.