-
Notifications
You must be signed in to change notification settings - Fork 15
Hotplug sensor examples #73
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
Conversation
According suggestions of @FoamyGuy, I took out 4 out of the 5 examples I created. I also took out the /images/bgimg4.bmp. This all for the sake of being able to publish a PR in a next step.
…/Adafruit_CircuitPython_DisplayIO_Layout into hotplug_sensor_examples
mod dict pages to use different Tab texts when using a PyPortal model Titano
Index to dictionary pages has to start at 1, not at 0 (which is a 'dummy)
Mods necessary to eliminate global variables as much as possible. Deleted flags: rtc_present, t_sensor_present. Replaces them by tests like: 'if rtc is not None'
Now all globals used before are contained in an added gVars class.
Example using datetime from NTP server, Touch interface. Using gVars class to set/get globally used variables.
bug repair
idem
Added BGimage4.bmp and it's .license file
In gVars class added flag "temp_in_fahrenheit". In second example modified algorithm to display the temperature sensor value in degrees Celsius or in degrees Fahrenheit depending the flag. See lines 211 , 667-670 and 725-726.
As just done with the second example. Added possibility to switch temperature displayed in degrees Celsius or degrees Fahrenheit by setting the gVars flag variable "temp_in_fahrenheit"
Now example adafruit#1 displays the temperature in degrees Celsius while example adafruit#2 displays the temperature in degrees Fahrenheit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change request to make the usage of Arial font optional or if it remains non-optional then we'll need to add the font file and a license for it to the repo.
Beyond that, these changes are looking good to me. Tested successfully on PyPortal Titano.
...ples/hotplug_sensor_examples/displayio_layout_tab_layout_hotplug_ext_rtc_temp_sensor_test.py
Show resolved
Hide resolved
...mples/displayio_layout_tablayout_hotplug_temp_sensor_datetime_fm_NTP_touch_and_gVars_test.py
Show resolved
Hide resolved
...mples/displayio_layout_tablayout_hotplug_temp_sensor_datetime_fm_NTP_touch_and_gVars_test.py
Show resolved
Hide resolved
Added the Arial-16.bdf font and it's license file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Tested successfully on PyPortal Titano. @PaulskPt Thanks again for making this example and working through all of the checks and things to share it in repo.
Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout to 1.19.2 from 1.19.1: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#73 from PaulskPt/hotplug_sensor_examples > Patch .pre-commit-config.yaml
This is my first PR. I was guided all the way towards this PR by @FoamyGuy.
This PR adds two examples that both have a functionality to hotplug external sensors.
Both examples use the new TabLayout class that @FoamyGuy recently has added to the Adafruit_CircuitPython_DisplayIO_Layout library. The second example uses the Touch capabilities of the PyPortal.
The particularities of the in this PR presented 'hotplug sensor' algorithm are:
The first example uses two external devices/sensors:
a) an Adafruit TMP117 sensor;
b) an external RTC module, DS3231.
both connected through I2C.
The second example is an expanded version of the first example.
As the first example also this script is able to read data from an external temperature sensor.
This script is able to use an external RTC. The preferred setting is to use a NTP server.
The script uses the Adafruit TouchScreen library. For the touch of the Tabs to be reliable a calibration is advised. I made use of the calibration script by CedarGrove Studios ( https://github.com/CedarGroveStudios/Touchscreen_Calibrator/blob/main/touch_calibrator_built_in.py).
The calibration results have to be inserted at line 410 ( ts = adafruit_touchscreen.Touchscreen()), replacing what is there at 'calibration=((6815, 60095), (10520, 58007)),'
Both example scripts use a gVars class to set/get globally used variables. This eliminates the need to use global variables.
The gVars class has been created because we were confronted with pylint warnings about using global variables.
Both example scripts show the date and time in the Tab 'Three'.
Both examples have a gVars flag "temp_in_fahrenheit". When set to 'True' the temperature will be displayed in degrees Fahrenheit. When set to 'False' in degrees Celsius. See image #4 below.
They display the temperature from the sensor in Tab 'Four'.
The second example script will notify the user in Tab 'Three' how many mm:ss a next NTP synchronization is due. Current resync is every 5 minutes.
This is done because we experienced that the internal clock runs ahead in time. Resync with NTP is crucial.
The second example, because of connecting to the internet, needs user-filled-in data from the file secrets.py.
A file secrets.py with default, unpersonalized, values is added to this PR.
This example also uses as a background image the image: BGimage4.bmp which is inside the subfolder /images.
About debugging: Both example scripts use a gVars variable "my_debug" which, when set to 'True' will have the script output more info about it's state/situation (I prefer to call it: 'debug information'). In the first example this flag is set in line 146. In the second example in line 172.
Initial clock setting: in both examples the clock will be set at startup by setting the globally used gVars variable "default_dt". In the first example this is in line 149. In the second example in line 175. The second example, when not using an external RTC device (determined by the setting of gVars flag "use_ntp" in line 200), it will use the date and time from an NTP server. The internal clock is set in line 341: "ntp.set_time(tz_offset)". If exists a valid time from NTP then "default_dt" is set in line 363.
About performance: The time for the second example script to become in a 'Ready...' state it takes about 54 seconds from powering up. Tapping on Tab 'Four' to display the temperature value - only the first time - takes about 5 seconds. After this one can tap from one Tab to the other with no significant delays.
ToDo: investigate/experiment how to improve the time from boot to the 'Ready...' moment;
During a recent Deep Dive with @FoamyGuy, viewers of this stream were enthousiastic about this sensor 'hotplug' feature. That is why @FoamyGuy advised me to create this PR.
The images below are taken while running the second example (the one using date and time from an NTP server).