-
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 10 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,28 @@ | ||
| """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 | ||
|
|
||
| from machine import I2C | ||
| from wsen_hids import WSEN_HIDS | ||
|
|
||
| i2c = I2C(1) | ||
| sensor = WSEN_HIDS(i2c) | ||
|
|
||
|
Charly-sketch marked this conversation as resolved.
|
||
| 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(2) | ||
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,29 @@ | ||
| '''Read every 5s and print CSV-formatted output (timestamp, humidity, temperature) suitable for serial capture''' | ||
| from time import sleep, ticks_diff, ticks_ms | ||
|
|
||
| from daplink_flash import DaplinkFlash | ||
| from machine import I2C | ||
| from wsen_hids import WSEN_HIDS | ||
|
|
||
| i2c = I2C(1) | ||
| sensor = WSEN_HIDS(i2c) | ||
| flash = DaplinkFlash(i2c) | ||
|
|
||
| # Set filename and erase | ||
| flash.set_filename("data", "CSV") | ||
| flash.clear_flash() | ||
| sleep(0.5) | ||
| print("Flash erased.") | ||
|
Charly-sketch marked this conversation as resolved.
Outdated
|
||
|
|
||
| start_ms = ticks_ms() | ||
|
|
||
| print("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(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,24 @@ | ||
| """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 | ||
|
|
||
| gamma = (a * temperature_c / (b + temperature_c)) + log(humidity / 100.0) | ||
|
Charly-sketch marked this conversation as resolved.
Outdated
|
||
| 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.