-
Notifications
You must be signed in to change notification settings - Fork 1
examples: Replace test scripts with practical examples for wsen-hids. #239
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
17 commits
Select commit
Hold shift + click to select a range
649da84
refactor(wsen-hids): remove test from examples
Charly-sketch 8e3ba77
feat(wsen-hids): add simple single read example
Charly-sketch a5f5537
style(wsen-hids): add description for humidity_temp example
Charly-sketch 90b04ca
feat(wsen-hids): add a comfort monitoring example
Charly-sketch d057dbe
feat(wsen-hids): add a data logger example
Charly-sketch 434c4fa
feat(wsen-hids): add dew point example
Charly-sketch 3f7ccd6
style(wsen-hids): remove french comment
Charly-sketch adf4f5e
feat(wsen-hids): add heater to reduce humidity example
Charly-sketch cdbf8cf
feat(wsen-hids): add low power sampling example
Charly-sketch 815ab75
docs(wsen-hids): add new examples to readme.
Charly-sketch 31e73d6
fix(wsen-hids): fix power down issue
Charly-sketch cc384ac
fix(wsen-hids): Add sleep_ms ans forgotten titile line in datalogger …
Charly-sketch 515e28d
fix(wsen-hids): Added sleep_ms in comfort monitor example
Charly-sketch 0db64d1
fix(wsen-hids): add sleep_ms to heater demo example
Charly-sketch 6b5d47d
style(wsen-hids): put docstring on multiple line in the example
Charly-sketch 12ec00e
fix(wsen-hids): added minimum humidity to ensure math
Charly-sketch 97bfc69
fix(wsen-hids): Address review feedback on examples.
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
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
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,30 @@ | ||
| """Loop that reads humidity + temperature every 2s and prints a comfort indicator ("Dry", "Comfortable", "Humid") | ||
| based on humidity thresholds (< 30%, 30-60%, > 60%)""" | ||
|
|
||
| from time import sleep_ms | ||
|
|
||
| from machine import I2C | ||
| from wsen_hids import WSEN_HIDS | ||
|
|
||
| i2c = I2C(1) | ||
| sensor = WSEN_HIDS(i2c) | ||
|
|
||
|
|
||
| def comfort_label(humidity): | ||
| if humidity < 30: | ||
| return "Dry" | ||
| elif humidity <= 60: | ||
| return "Comfortable" | ||
| else: | ||
| return "Humid" | ||
|
|
||
| while True: | ||
| humidity, temperature = sensor.read_one_shot() | ||
| comfort = comfort_label(humidity) | ||
|
|
||
| print("Humidity: {:.2f} %RH".format(humidity)) | ||
| print("Temperature: {:.2f} °C".format(temperature)) | ||
| print("Comfort: {}".format(comfort)) | ||
| print() | ||
|
|
||
| sleep_ms(2000) | ||
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,42 @@ | ||
| """Log humidity and temperature to DAPLink flash and serial console. | ||
|
|
||
| Reads every 5 seconds and writes CSV-formatted output (timestamp, | ||
| humidity, temperature). Data is stored on the DAPLink flash as | ||
| DATA.CSV and also printed to the serial console. | ||
|
|
||
| WARNING: When ERASE_FLASH_ON_START is True, the entire DAPLink flash | ||
| is erased before logging. Make sure you have backed up any important | ||
| data before enabling erasure. | ||
| """ | ||
| from time import sleep_ms, ticks_diff, ticks_ms | ||
|
|
||
| from daplink_flash import DaplinkFlash | ||
| from machine import I2C | ||
| from wsen_hids import WSEN_HIDS | ||
|
|
||
| # Set to True to erase the DAPLink flash on startup (DESTRUCTIVE). | ||
| ERASE_FLASH_ON_START = False | ||
|
|
||
| i2c = I2C(1) | ||
| sensor = WSEN_HIDS(i2c) | ||
| flash = DaplinkFlash(i2c) | ||
|
|
||
| flash.set_filename("DATA", "CSV") | ||
| if ERASE_FLASH_ON_START: | ||
| flash.clear_flash() | ||
| sleep_ms(500) | ||
| print("Flash erased.") | ||
|
|
||
| start_ms = ticks_ms() | ||
|
|
||
| print("timestamp,humidity,temperature") | ||
| flash.write_line("timestamp,humidity,temperature") | ||
|
|
||
| while True: | ||
| humidity, temperature = sensor.read_one_shot() | ||
| elapsed_s = ticks_diff(ticks_ms(), start_ms) // 1000 | ||
|
|
||
| print("{},{:.2f},{:.2f}".format(elapsed_s, humidity, temperature)) | ||
| flash.write_line("{},{:.2f},{:.2f}".format(elapsed_s, humidity, temperature)) | ||
|
|
||
| sleep_ms(5000) |
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,28 @@ | ||
| """Compute and display the dew point temperature from humidity + temperature using the Magnus formula. | ||
| Useful to understand when condensation might occur.""" | ||
| from math import log | ||
|
|
||
| from machine import I2C | ||
| from wsen_hids import WSEN_HIDS | ||
|
|
||
| i2c = I2C(1) | ||
| sensor = WSEN_HIDS(i2c) | ||
|
|
||
|
|
||
| def dew_point_celsius(temperature_c, humidity): | ||
| # Magnus formula | ||
|
Charly-sketch marked this conversation as resolved.
|
||
| a = 17.62 | ||
| b = 243.12 # °C | ||
|
|
||
| # Clamp humidity to a small positive value to avoid log(0) when humidity is 0.0 | ||
| safe_humidity = max(humidity, 0.01) | ||
| gamma = (a * temperature_c / (b + temperature_c)) + log(safe_humidity / 100.0) | ||
| dp = (b * gamma) / (a - gamma) | ||
| return dp | ||
|
|
||
| humidity, temperature = sensor.read_one_shot() | ||
| dew_point = dew_point_celsius(temperature, humidity) | ||
|
|
||
| print("Humidity: {:.2f} %RH".format(humidity)) | ||
| print("Temperature: {:.2f} °C".format(temperature)) | ||
| print("Dew point: {:.2f} °C".format(dew_point)) | ||
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.