Software source reference
"""
Contains a helper function to measure the wind speed.
:Authors:
Min Tai Yap <Min.Yap2@monash.edu>
"""
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
hall_effect_sensor2_pin = 21 # GPIO21
GPIO.setup(hall_effect_sensor2_pin, GPIO.IN)
cal_count = 0
cal_check = 0
first_triggered_time = 0
last_triggered_time = 0
total_time = 0
flag_1 = 0
flag_2 = 0
flag_3 = 0
time_diff = 0
new_speed = 0
old_speed = 0
calibration_factor = 0
before_time = 0
[docs]
def measure_wind_speed(cal_count, hall_effect_sensor2_pin):
"""
Catches peaks in the voltage of the Hall effect sensor, which corresponds to half a rotation
of the anemometer. Whenever a peak is detected, the number of counted half rotations is
increased by 1.
:param cal_count: Old number of half rotations
:param hall_effect_sensor2_pin: Pin of the hall effect sensor that measures the wind
:returns: Updated number of half rotations
"""
global cal_check
# print("Calibration factor: ", calibration_factor)
if cal_check == 0:
if GPIO.input(hall_effect_sensor2_pin) == 1:
cal_check = 1
cal_count += 1
else:
if GPIO.input(hall_effect_sensor2_pin) == 0:
cal_check = 0
return cal_count
