Last active
October 31, 2021 21:22
-
-
Save Biaggio74/5feba93cddffe5d72ef95a46a38a47ba to your computer and use it in GitHub Desktop.
Wind measurements with Davis anemometer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from gpiozero import Button | |
from signal import pause | |
import statistics | |
import pyrebase | |
import Adafruit_DHT as dht | |
#The "black" wire (wind speed) of Davis connected to PIN29 as GPIO05 | |
#the "red" wire (ground) of Davis is connected to PIN39 ground | |
#the "green" wire (wind direction) of davis is connected to PIN31 as GPIO06 | |
#the "yellow" wire is connected to 5V PIN02 | |
DHT_PIN = 4 #for humidity and temperature | |
db_url = 'https://home-iot-wind.firebaseio.com/' | |
config = { | |
"apiKey": "*****************", | |
"authDomain": "home-iot-wind.firebaseapp.com", | |
"databaseURL": db_url, | |
"storageBucket": "home-iot-wind.appspot.com" | |
} | |
firebase = pyrebase.initialize_app(config) | |
db = firebase.database() | |
wind_speed_sensor = Button(5) | |
wind_count = 0 | |
interval = 3 | |
def spin(): | |
global wind_count | |
wind_count = wind_count + 1 | |
#print("spin" + str(wind_count)) | |
#time shall be in seconds | |
def calc_speed(spins, interval): | |
#based on Davis tech document | |
# V = P*(2.25/T) the speed is in MPh | |
# P = no. of pulses per sample period | |
# T = sample period in seconds | |
wind_speed_mph = spins * (2.25 / interval) | |
return wind_speed_mph | |
def reset_wind(): | |
global wind_count | |
wind_count = 0 | |
store_speeds = [] | |
wind_speed_sensor.when_pressed = spin | |
while True: | |
start_time = time.time() | |
print('##### 10-min started #####') | |
while time.time() - start_time <= 600: | |
print('Start 3 second') | |
humidity, temperature = dht.read_retry(dht.AM2302, DHT_PIN) | |
if humidity is not None and temperature is not None: | |
print("Temp={0:0.1f}*C Humidity={1:0.1f}%".format(temperature, humidity)) | |
count_start = wind_count | |
time.sleep(3) | |
count_end = wind_count | |
spins = count_end - count_start | |
bws_3_sec = calc_speed(spins, 3) | |
data_3sec = { | |
"bws-3-sec": bws_3_sec, | |
"temperature": temperature, | |
"humidity": humidity, | |
"timestamp": time.time() | |
} | |
#build some path | |
db.child("home").child("wind").child("3_sec").push(data_3sec) | |
print('Number of spins: ', spins) | |
print('Wind speed (mph): ', bws_3_sec) | |
print('Global count: ', wind_count) | |
#reset_wind() | |
#Measure for 10-min | |
bws_10_min = calc_speed(wind_count, 600) | |
data_10_min = { | |
"bws_10_min": bws_10_min, | |
"temperature": temperature*2, | |
"humidity": humidity, | |
"timestamp": time.time() | |
} | |
db.child("home").child("wind").child("10_min").push(data_10_min) | |
print('###### 10-min data #####') | |
print('Global count: ', wind_count) | |
print('10-min BWS: ', bws_10_min) | |
print('##### 10-min END #####') | |
reset_wind() | |
""" while True: | |
start_time = time.time() | |
while time.time() - start_time <= interval: | |
reset_wind() | |
time.sleep(interval) | |
final_speed = calc_speed(interval) | |
store_speeds.append(final_speed) | |
wind_gust = max(store_speeds) | |
#wind_speed = statistics.mean(store_speeds) | |
#print(wind_speed, wind_gust) """ | |
pause() | |
# Hello from Mender update :) |
Author
Biaggio74
commented
Oct 31, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment