Package: weatherhat
Weather HAT Python Library & ExamplesPre-requisitesThis library requires Python ≥3.6 so we'd recommend using it with Raspberry Pi OS Buster or later.You must enable:i2c:sudo raspi-config nonint do_i2c 0spi:sudo raspi-config nonint do_spi 0You can optionally runsudo raspi-configor the graphical Raspberry Pi Configuration UI to enable interfaces.InstallingStable library from PyPi:Just runpip3 install weatherhatIn some cases you may need to usesudoor install pip with:sudo apt install python3-pipLatest/development library from GitHub:git clone https://github.com/pimoroni/weatherhat-pythoncd weatherhat-python./install.sh --unstableSome of the examples use additional libraries. You can install them with:pip3installfontsfont-manropepyyamladafruit-ionumpyYou may also need to installlibatlas-base-devsudo apt-get install libatlas-base-devUsing The LibraryImport theweatherhatmodule and create an instance of theWeatherHATclass.importweatherhatsensor=weatherhat.WeatherHAT()Weather HAT updates the sensors when you callupdate(interval=5).Temperature, pressure, humidity, light and wind direction are updated continuously.Rain and Wind measurements are measured over anintervalperiod. Weather HAT will count ticks of the rain gauge and (half) rotations of the anemometer, calculate rain/wind everyintervalseconds 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:importtimeimportweatherhatsensor=weatherhat.WeatherHAT()whileTrue:sensor.update(interval=5.0)time.sleep(1.0)Averaging ReadingsThe 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 exampleWindSpeedHistoryallows 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:importtimeimportweatherhatfromweatherhat.historyimportWindSpeedHistorysensor=weatherhat.WeatherHAT()wind_speed_history=WindSpeedHistory()whileTrue:sensor.update(interval=5.0)ifsensor.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 ReferenceTemperatureTemperature readings are given as degrees celsius and are measured from the Weather HAT's onboard BME280.Device Temperaturesensor.device_temperatureDevice 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) Temperaturesensor.temperatureTemperature in degrees celsius.This is the temperature once an offset has been applied. This offset is fixed, and taken fromsensor.temperature_offset.Pressuresensor.pressurePressure in hectopascals.Humiditysensor.humidityHumidity in %.Relative Humiditysensor.relative_humidityRelative 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 Pointsensor.dewpointDew point in degrees celsius.Dew point is the temperature at which water - at the current humidity - will condense out of the air.Light / Luxsensor.luxLight is given in lux.Lux ranges from 0 (complete darkness) to 64,000 (full brightness).WindBoth wind and rain are updated on an interval, rather than on-demand.To see if anupdate()call has resulted in new wind/rain measurements, check:sensor.updated_wind_rainWind Directionsensor.wind_directionWind 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 Speedsensor.wind_speedWind 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.Rainsensor.rainRain 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 Rainsensor.rain_totalTotal rain amount in millimeters for the current update period.0.0.2Values will now always be floatFixed backlight pinFixed latest/average mph0.0.1Initial Release