From f665f78155047838dc924634ebe4128f7add5542 Mon Sep 17 00:00:00 2001 From: ars Date: Wed, 17 Jun 2020 15:59:52 +0100 Subject: Initial commit --- weather_station.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 weather_station.py (limited to 'weather_station.py') diff --git a/weather_station.py b/weather_station.py new file mode 100644 index 0000000..986d6a5 --- /dev/null +++ b/weather_station.py @@ -0,0 +1,52 @@ +from gpiozero import Button +import time +import math +import statistics +import bme280_sensor +import wind_direction_byo +import ds18b20_therm + +anem = Button(5) # setup GPIO 5 as a button +storeSpeeds = [] +windCount = 0 # counts half-rotations +radius_cm = 9.0 # radius of anemometer +circumference_cm = (2 * math.pi) * radius_cm +windInterval = 5 # how often to report speed +cmInKm = 100000.0 +secsInHour = 3600 +anemFactor = 1.18 # anemometer factor is the result of wind energy lost due to the arms turning + +# every half rotation, add one to count +def spin(): + global windCount + windCount += 1 + +# calculate wind speed +def calculateSpeed(timeSec): + global windCount + global circumference_cm + rotations = windCount / 2.0 + + # calculate distance travelled by anemometer in km + distKm = circumference_cm * rotations / cmInKm + speed = ((distKm / timeSec) * secsInHour) * anemFactor + return speed + +def resetWind(): + global wind_count + wind_count = 0 + +anem.when_pressed = spin + +# Loop to measure wind speed and report at 5 second intervals +while True: + startTime = time.time() + while time.time() - startTime <= windInterval: + resetWind() # reset count for next 5 second run + time.sleep(windInterval) + #finalSpeed = calculateSpeed(windInterval) + storeSpeeds.append(calculate(windInterval)) # store average speed over 5 seconds + + windGust = max(storeSpeeds) # maximum gust + windSpeed = statistics.mean(storeSpeeds) # running average wind speed + print(windSpeed, "km/h", windGust, "km/h") -- cgit v1.2.3