Adafruit Reader, version 0.8
DEPRECATED
Please use version 0.9+ instead. This version will be removed from the website in the near future.
Description
This program reads the DHT11 or DHT22 sensor from Adafruit, and provides a display of multiple values and derived values on a Raspberry Pi standard display (800x480). The display consists of the current time, the time the Adafruit sensor was read, the temperature, wet-bulb temperature, dew point temperature, relative humidity, THI, and local station pressure, if available. Beginning with version 0.8, it additionally shows a temperature/relative humidity/THI comparison scale and the equivalent relative humidity if outdoor air were heated to the indoor temperature without adding/removing water vapor. The local station pressure and outdoor air to indoor humidity features require the ability to obtain a weather report (see below).
THI, or Temperature Humidity Index, was used decades ago before the Heat Index was derived. The THI is (T + Tw) * 0.4 + 15, where T is the dry-bulb temperature (or just temperature), and Tw is the wet-bulb temperature. Comfort levels vary from person to person, but 71 is generally considered comfortable, with varying degrees of discomfort with increasing distance from that number.
Station pressure and outdoor dew point temperature (required for the indoor relative humidity equivalent) are available only in the USA and Canada. Locate the closest airport that provides a METAR with altimeter setting, and use the 4-letter identifier (for example, Will Rogers World Airport in Oklahoma City, Oklahoma, USA is "KOKC") to identify your preferred station. Also find the altitude of your sensor above mean sea level in meters. This does not have to be overly accurate, but should be within about 10 m for best accuracy. Edit Configuration.py with these values, and do not update that file with future updates (unless the update specifically instructs you to do this).
System Requirements
- Raspberry Pi with Adafruit temperature/humidity sensor, either DHT11 or DHT22
- Monitor, such as the 7-inch (~18 cm) touchscreen from Raspberry Pi
- Python 3.6+
For setup info, see also this page, at least the section titled, "Installing the CircuitPython-DHT Library", since the library needs to be installed (pip3 and apt-install commands on that page). If you don't already have pytz, you will need to pip install pytz, too. Also, the (current version) of this program requires user customization (Configuration class—see below).
Installation
Copy the provided files into the directory of your choice (ensuring that main.py is in this directory, and the other files are in a subdirectory called adafruit_reader). Ideally, create a desktop icon set to run the following script (pointing to the main.py file—you may need to include a directory change (cd) in the script, depending on your directory structure):
python3 -m main.py
Alternatively, you can navigate to the directory with main.py, and double-click the icon for that file, then run this program from the Python editor/IDE that is associated with Python programs/scripts.
Components
You can download the files individually below, or get the Zip archive here.
- "Main" file: main.py
- Python init file (or make your own): __init__.py
- Configuration file: Configuration.py
- Controller file: Controller.py
- I/O file: Io.py
- Main GUI file: MainView.py
- Observation data file: Observation.py
- Temperature/Relative Humidity scale: RhCanvas.py
- Individual display items file: WxDisplay.py
- Temperature/humidity classes file: WxElement.py
- Temperature/humidity calculations file: WxMath.py
Additional setup
Edit the Configuration.py file under class Configuration: as follows:
- change altitude: int = to equal the altitude of the sensor, in meters (m) above mean sea level (within about 10 m)
- change default_units: str = to "USCS" (with the quotes), if you prefer USCS units instead of international units...the temperature/relative humidity comparison scale will use these units exclusively, regardless of the units button setting
- change dht_device = to your device/pin number (see the comment in the Python file for help)
- change minimum_temperature, maximum_temperature, and interval_temperature to your preference for the range of the temperature/RH/THI scale. Ideally, the scale should cover the typical range of temperatures that the sensor will be exposed to in a year, perhaps a little more or less. Also, it is important that the interval is an even divisor of the difference between maximum and minimum values. For example, 15 °C to 31 °C with an interval of 2 °C should be fine (31 - 15 is 16, and 2 is an even factor of 16). Use the appropriate temperature units according to your setting for default_units, above.
- if you really want to modify colors or fonts, you can do so in the remaining parts of the file.
Copy this file to a safe place, and copy it back to the adafruit_reader directory whenever the Configuration.py file is overwritten by an update...or just make the same changes each time this file is updated. Note: In this version, the Configuration.py file requires a small update: see the RH COMPARISON SCALE section at the top of the file, and instructions in the list above.
Usage notes
If the program shuts down unexpectedly (not by pressing the Quit button or the window-close button), you may have to restart the Raspberry Pi in order to restart this program. If you see a response such as "unable to start input on line 4" (or something similar), try a restart.
The readings should update about every two to three seconds, and the pressure and remote dew point temperature (if these are available from a nearby airport) should update about every hour. If the pressure/dew point temperature observation becomes more than six hours old, the value will revert to standard pressure (101.32 kPa), adjusted to the provided altitude, and the outdoor-to-indoor relative humidity will become N/A.
The units button (on bottom left) is a toggle. Its label will change when it is clicked. Similarly, the precision button cycles between 0.1, 0.5, and 1 (in that order), indicating the level of rounding. If you have a DHT11, the temperature and relative humidity are limited to integer values, so normally, the precision button should be set to 1. For the DHT22, all three settings are appropriate, according to your preference.
Known Issues
(From version 0.7.1, fixed in version 0.8):
- When units are set to USCS (°F and inches of mercury), and rounding to 0.5, the pressure is rounded to the nearest full inch of mercury.
- When there is no Internet connection, or the NWS website is otherwise unavailable, the program hangs or crashes.
- When no NWS-derived pressure is available, the standard pressure value is not adjusted to the altitude of the sensor.
- When units are set to USCS, the altitude is still shown in meters (m), not feet.
- The pressure does not update (should update hourly).
- The pressure does not expire (should expire after 6 hours).
- Closing the program with the window-close button required a restart to get the sensor reader working correctly again.
Unresolved:
- The relative humidity "ticks" and labels are spaced too widely on the temperature/relative humidity/THI graphic. (Can be improved by changing lines 93-97 in RhCanvas.py to your liking. Definitely increase the if max_rh.rh(Units.PERCENT) < 50: line (93) to use at least 60 instead of 50.)
License
This program is free and open-source software by Cheryl M. Sharpe. The author grants you, the user, free access to the software component(s) listed above, with the understanding that your use of the software is completely at your own risk. Although I have attempted to create a bug-free program, I am not a software corporation, and have neither the time nor the ability to debug this software thoroughly. In addition, misuse of the program, or entry of nonsense data, may provide meaningless or inaccurate results without warning. You are responsible for knowing what data are reasonable and what results are reasonable.
You are permitted to modify the code to suit your purposes. However, you are not permitted to redistribute altered code without notifying the author in advance (use the email link on the left). Sale (for any fee, for any reason) of this program is absolutely prohibited.
Finally, the author does not guarantee technical support of any kind (beyond the scope of this documentation and in-code comments) for this, or any other program - except as noted in the "About" menu item, if one is provided.