Library for Weather HAT
Project description
Weather HAT Python Library & Examples
Pre-requisites
You must enable:
- i2c:
sudo raspi-config nonint do_i2c 0
- spi:
sudo raspi-config nonint do_spi 0
You can optionally run sudo raspi-config
or the graphical Raspberry Pi Configuration UI to enable interfaces.
Installing
Stable library from PyPi:
- Just run
pip3 install weatherhat
In some cases you may need to use sudo
or install pip with: sudo apt install python3-pip
Latest/development library from GitHub:
git clone https://github.com/pimoroni/weatherhat-python
cd weatherhat-python
sudo ./install.sh
Some of the examples use additional libraries. You can install them with:
pip3 install fonts font-manrope pyyaml adafruit-io
Using The Library
Import the weatherhat
module and create an instance of the WeatherHAT
class.
import weatherhat
sensor = weatherhat.WeatherHAT()
Weather HAT updates the sensors when you call update(interval=5)
.
Temperature, pressure, humidity, light and wind direction are updated continuously.
Rain and Wind measurements are measured over an interval
period. Weather HAT will count ticks of the rain gauge and (half) rotations of the anemometer, calculate rain/wind every interval
seconds and reset the counts for the next pass.
For example the following code will update rain/wind speed every 5 seconds, and all other readings will be updated on demand:
import time
import weatherhat
sensor = weatherhat.WeatherHAT()
while True:
sensor.update(interval=5.0)
time.sleep(1.0)
Averaging Readings
The Weather HAT library supplies set of "history" classes intended to save readings over a period of time and provide access to things like minimum, maximum and average values with unit conversions.
For example WindSpeedHistory
allows you to store wind readings and retrieve them in mp/h or km/h, in addition to determining the "gust" (maximum wind speed) in a given period of time:
import time
import weatherhat
from weatherhat.history import WindSpeedHistory
sensor = weatherhat.WeatherHAT()
wind_speed_history = WindSpeedHistory()
while True:
sensor.update(interval=5.0)
if sensor.updated_wind_rain:
wind_speed_history.append(sensor.wind_speed)
print(f"Average wind speed: {wind_speed_history.average_mph()}mph")
print(f"Wind gust: {wind_speed_history.gust_mph()}mph")
time.sleep(1.0)
Quick Reference
Temperature
Temperature readings are given as degrees celsius and are measured from the Weather HAT's onboard BME280.
Device Temperature
sensor.device_temperature
Device temperature in degrees celsius.
This is the temperature read directly from the BME280 onboard Weather HAT. It's not compensated and tends to read slightly higher than ambient due to heat from the Pi.
Compensated (Air) Temperature
sensor.temperature
Temperature in degrees celsius.
This is the temperature once an offset has been applied. This offset is fixed, and taken from sensor.temperature_offset
.
Pressure
sensor.pressure
Pressure in hectopascals.
Humidity
sensor.humidity
Humidity in %.
Relative Humidity
sensor.relative_humidity
Relative humidity in %.
Relative humidity is the water content of the air compensated for temperature, since warmer air can hold more water.
It's expressed as a percentage from 0 (no moisture) to 100 (fully saturated).
Dew Point
sensor.dewpoint
Dew point in degrees celsius.
Dew point is the temperature at which water - at the current humidity - will condense out of the air.
Light / Lux
sensor.lux
Light is given in lux.
Lux ranges from 0 (complete darkness) to.
Wind
Both wind and rain are updated on an interval, rather than on-demand.
To see if an update()
call has resulted in new wind/rain measurements, check:
sensor.updated_wind_rain
Wind Direction
sensor.wind_direction
Wind direction in degrees.
Wind direction is measured using a potentiometer and uses an analog reading internally. This is converted to degrees for convenience, and will snap to the nearest 45-degree increment with 0 degrees indicating North.
Wind Speed
sensor.wind_speed
Wind speed in meters per second.
Weather HAT counts every half rotation and converts this to cm/s using the anemometer circumference and factor.
It's updated depending on the update interval requested.
Rain
sensor.rain
Rain amount in millimeters per second.
Weather HAT counts every "tick" of the rain gauge (roughly .28mm) over the given update internal and converts this into mm/sec.
Total Rain
sensor.rain_total
Total rain amount in millimeters for the current update period.
Changelog
0.0.1
- Initial Release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file weatherhat-0.0.1.tar.gz
.
File metadata
- Download URL: weatherhat-0.0.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e20d822740a0d701e0a1eb18942c0e217cf89bf63d9933405989f4be8b391498 |
|
MD5 | 88340f78190a97c3ec4692f133dddbb2 |
|
BLAKE2b-256 | 98306ed069f180ed979b8004b3cbbdc686e9d1701291bd27b371f8d34d1c1e74 |
File details
Details for the file weatherhat-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: weatherhat-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1473fa0f2d1ce658c48e7c6e1071953e9fa799730e0d6550290682f2023e2693 |
|
MD5 | f9687bf1b5e3b2bc929b795747797ad4 |
|
BLAKE2b-256 | 1ad5b53800804928b3c5ccafa9ed88d129e36ef25d5ccc0d4fda03445cb387f3 |
File details
Details for the file weatherhat-0.0.1-py2-none-any.whl
.
File metadata
- Download URL: weatherhat-0.0.1-py2-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.21.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7040070ac5791a4c17ba2f2fe77e0fe1178eb39c0d58ee7303378d947d7127ac |
|
MD5 | 88c8e3d56a3469c5475b391c7c0ed2fa |
|
BLAKE2b-256 | e5fd8f861fbd923a2051c23d45253beb1b109192edea380b43f95a3041970110 |