From f665f78155047838dc924634ebe4128f7add5542 Mon Sep 17 00:00:00 2001 From: ars Date: Wed, 17 Jun 2020 15:59:52 +0100 Subject: Initial commit --- dev_scripts/sen15901anem.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 dev_scripts/sen15901anem.py (limited to 'dev_scripts/sen15901anem.py') diff --git a/dev_scripts/sen15901anem.py b/dev_scripts/sen15901anem.py new file mode 100644 index 0000000..6294ea0 --- /dev/null +++ b/dev_scripts/sen15901anem.py @@ -0,0 +1,49 @@ +from gpiozero import Button +import time +import math +import statistics + +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