summaryrefslogtreecommitdiff
path: root/dev_scripts/sen15901anem.py
diff options
context:
space:
mode:
authorars <asav1410@gmail.com>2020-06-17 15:59:52 +0100
committerars <asav1410@gmail.com>2020-06-17 15:59:52 +0100
commitf665f78155047838dc924634ebe4128f7add5542 (patch)
treefa0b6d2fd4a7b26d7fac2d557066044384d33010 /dev_scripts/sen15901anem.py
Initial commitHEADmaster
Diffstat (limited to 'dev_scripts/sen15901anem.py')
-rw-r--r--dev_scripts/sen15901anem.py49
1 files changed, 49 insertions, 0 deletions
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")