Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4107380
chore(wsen-pads): remove test script
Charly-sketch Mar 24, 2026
19b86ba
style(wsen-pads): remove unused Pin import
Charly-sketch Mar 24, 2026
2ccf1da
feat(wsen-pads): add pressure_trend example
Charly-sketch Mar 24, 2026
1d31ac1
feat(wsen-pads): add floor_detector example
Charly-sketch Mar 24, 2026
1b17040
refactor(wsen-pads): improve pressure_trend example
Charly-sketch Mar 24, 2026
4982d5c
feat(wsen-pads): add threshold_alert example
Charly-sketch Mar 24, 2026
7073684
feat(wsen-pads): add temp_pressure_display example
Charly-sketch Mar 24, 2026
bc8f858
feat(wsen-pads): add altitude_calibration example
Charly-sketch Mar 24, 2026
8364a90
style(wsen-pads): fix linter errors in examples
Charly-sketch Mar 24, 2026
08b9938
docs(wsen-pads): add new examples
Charly-sketch Mar 24, 2026
ae5b552
feat(wsen-pads): add weather_station example
Charly-sketch Mar 24, 2026
df71174
docs(wsen-pads): add weather_station example to README
Charly-sketch Mar 24, 2026
c242289
style(wsen-pads): remove unused constant in floor_detector
Charly-sketch Mar 24, 2026
44022e3
refactor(wsen-pads): use a single read in temp_pressure_display
Charly-sketch Mar 24, 2026
8dd7c79
fix(wsen-pads): rename threshold_alert typo
Charly-sketch Mar 24, 2026
6ebc61c
fix(wsen-pads): fix weather_station example
Charly-sketch Mar 24, 2026
f83b080
style(wsen-pads): fix weather_station example formatting
Charly-sketch Mar 24, 2026
fcf7629
test(wsen-pads): add coverage for init errors and status helpers
Charly-sketch Mar 24, 2026
be7caf5
docs(wsen-pads): fix README typo
Charly-sketch Mar 24, 2026
da452d8
chore: gitignore node modules
Charly-sketch Mar 24, 2026
1278ac1
chore: gitignore up to date
Charly-sketch Mar 24, 2026
b55dd55
Merge branch 'main' into wsen-pads-extand-example
Charly-sketch Mar 24, 2026
2de4b1b
style(wsen-pads): fix lint errors
Charly-sketch Mar 24, 2026
a68d764
fix(wsen-pads): fix constant temp_pressure_display
Charly-sketch Mar 24, 2026
1e64953
fix(wsen-pads): fix constant threshold_alert
Charly-sketch Mar 24, 2026
1408362
fix(wsen-pads): Fix f-string in weather_station and floor height cons…
nedseb Mar 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ __pycache__
*.1
78e43b91-b6a2-4e0a-99c2-3f6f74828063_ExportBlock-935e0d48-7286-4b74-aa60-ccd18217ac01
node_modules/
CLAUDE.md
CLAUDE.md
20 changes: 12 additions & 8 deletions lib/wsen-pads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,18 @@ This computes a corrected gain and offset so that the measured temperature bette

Examples are available in the `examples` directory.

| Example | Description |
| ------------- | ----------------------------------- |
| `basic_reader.py` | Basic pressure and temperature read |
| `continuous_reader.py` | Continuous measurement example |
| `one_shot_reader.py` | One-shot measurement example |
| `altitude.py` | Altitude estimation from pressure |
| `test.py` | Driver test script |

| Example | Description |
| -------------------------- | --------------------------------------------------------------------------- |
| `basic_reader.py` | Basic pressure and temperature read |
Comment thread
Charly-sketch marked this conversation as resolved.
| `continuous_reader.py` | Continuous measurement example |
| `one_shot_reader.py` | One-shot measurement example |
| `altitude.py` | Altitude estimation from pressure |
| `altitude_calibration.py` | Calibrate sea-level pressure from known altitude and compute corrected altitude |
| `floor_detector.py` | Detect floor changes based on altitude variations |
| `pressure_trend.py` | Track pressure changes over time to detect trends |
| `temp_pressure_display.py` | Display formatted temperature and pressure with ASCII bar graphs |
| `threshold_alert.py` | Monitor pressure and trigger an alert when a threshold is crossed |
| `weather_station.py` | Monitor weather condition and register them in a CSV file on the board |

---

Expand Down
2 changes: 1 addition & 1 deletion lib/wsen-pads/examples/altitude.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep

from machine import I2C, Pin
from machine import I2C
from wsen_pads import WSEN_PADS

SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation
Expand Down
33 changes: 33 additions & 0 deletions lib/wsen-pads/examples/altitude_calibration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from time import sleep

from machine import I2C
from wsen_pads import WSEN_PADS

# Set your known altitude (in meters) for calibration
KNOWN_ALTITUDE = 12 # Example: your location altitude

i2c = I2C(1)
sensor = WSEN_PADS(i2c)


pressure = sensor.pressure_hpa()

# Compute sea-level pressure based on known altitude
# Formula derived from barometric equation
sea_level_pressure = pressure / (1 - (KNOWN_ALTITUDE / 44330.0)) ** 5.255

print("Calibration:")
print(" Measured pressure: {:.1f} hPa".format(pressure))
print(" Known altitude: {:.1f} m".format(KNOWN_ALTITUDE))
print(" Sea-level pressure: {:.1f} hPa".format(sea_level_pressure))
print("-" * 50)

while True:
pressure = sensor.pressure_hpa()

# Compute altitude using calibrated sea-level pressure
altitude = 44330.0 * (1 - (pressure / sea_level_pressure) ** (1 / 5.255))

print("Altitude: {:6.1f} m | Pressure: {:6.1f} hPa".format(altitude, pressure))

sleep(1)
2 changes: 1 addition & 1 deletion lib/wsen-pads/examples/basic_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep

from machine import I2C, Pin
from machine import I2C
from wsen_pads import WSEN_PADS

# Update the I2C bus number and pins to match your board
Expand Down
2 changes: 1 addition & 1 deletion lib/wsen-pads/examples/continuous_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep

from machine import I2C, Pin
from machine import I2C
from wsen_pads import WSEN_PADS
from wsen_pads.const import ODR_10_HZ

Expand Down
46 changes: 46 additions & 0 deletions lib/wsen-pads/examples/floor_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Measure altitude at startup as baseline, then loop and detect floor changes (each ~3m altitude difference = 1 floor). Print "Floor +1", "Floor -1", etc."""

from time import sleep

from machine import I2C
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)

SAMPLES_FOR_BASELINE = 20
SAMPLES_PER_MEASURE = 10
METERS_PER_FLOOR = 3.0

baseline_pressure_list = []

print("Measuring baseline pressure...")
for _ in range(SAMPLES_FOR_BASELINE):
pressure = sensor.pressure_hpa()
baseline_pressure_list.append(pressure)

sleep(0.5)

baseline_pressure = sum(baseline_pressure_list) / len(baseline_pressure_list)
print("Baseline pressure:", baseline_pressure, "hPa")

while True:
pressure_samples = []

print("Measuring...")
for _ in range(SAMPLES_PER_MEASURE):
pressure = sensor.pressure_hpa()
pressure_samples.append(pressure)

sleep(0.5)

avg_pressure = sum(pressure_samples) / len(pressure_samples)

# Calculate altitude difference from baseline using barometric formula
altitude_diff = 44330 * (1 - (avg_pressure / baseline_pressure) ** (1/5.255))

floor_change = round(altitude_diff / METERS_PER_FLOOR)

print("Avg Pressure:", avg_pressure, "hPa Altitude Diff:", altitude_diff, "m Floor Change:", floor_change)
2 changes: 1 addition & 1 deletion lib/wsen-pads/examples/one_shot_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep

from machine import I2C, Pin
from machine import I2C
from wsen_pads import WSEN_PADS

i2c = I2C(1)
Expand Down
49 changes: 49 additions & 0 deletions lib/wsen-pads/examples/pressure_trend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Read pressure every 10s, keep the last 10 values in a list, print whether pressure is rising, falling, or stable (useful for simple weather prediction)"""

from time import sleep

from machine import I2C
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)

pressure_history = []
MAX_VALUES = 10
THRESHOLD = 0.5 # sensitivity (hPa)

def get_trend(values):
if len(values) < 2:
return "N/A"

half = len(values) // 2
first_half_avg = sum(values[:half]) / len(values[:half])
second_half_avg = sum(values[half:]) / len(values[half:])

diff = second_half_avg - first_half_avg

if abs(diff) < THRESHOLD:
return "stable"
elif diff > 0:
return "rising"
else:
return "falling"

while True:
pressure = sensor.pressure_hpa()

# store value
pressure_history.append(pressure)

# keep only last 10 values
if len(pressure_history) > MAX_VALUES:
pressure_history.pop(0)

trend = get_trend(pressure_history)

print("P:", pressure, "hPa, Pressure is", trend)

sleep(10)
41 changes: 41 additions & 0 deletions lib/wsen-pads/examples/temp_pressure_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Read temperature and pressure, format a nice display with units and a simple bar graph using # characters to visualize pressure (e.g. 1013.2 hPa [##########-----])
"""
from time import sleep

from machine import I2C
from wsen_pads import WSEN_PADS

TEMP_MIN = 15.0
TEMP_MAX = 30.0
PRESS_MIN = 960.0
PRESS_MAX = 1060.0


i2c = I2C(1)
sensor = WSEN_PADS(i2c)

def bar_graph(value, vmin, vmax, width=20):
# Clamp value
if value < vmin:
value = vmin
elif value > vmax:
value = vmax

ratio = (value - vmin) / (vmax - vmin)
filled = int(ratio * width)

return "[" + "#" * filled + "-" * (width - filled) + "]"

while True:
pressure, temp = sensor.read()
temp_bar = bar_graph(temp, TEMP_MIN, TEMP_MAX)
press_bar = bar_graph(pressure, PRESS_MIN, PRESS_MAX)

line = "T:{:5.1f}°C {} | P:{:6.1f}hPa {}".format(
temp, temp_bar, pressure, press_bar
)

print("\r" + line, end="")

sleep(1)
Loading
Loading