From 283a46eb0b0e382a28e3734675f360dab8363b5e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 10 Mar 2025 17:44:03 +0100 Subject: [PATCH] update --- README.md | 2 +- windMeter/read_wind_speed.py | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 windMeter/read_wind_speed.py diff --git a/README.md b/README.md index 99b3f46..ab0d3c1 100755 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Line by line installation. ``` sudo apt update sudo apt install git gh apache2 php php-sqlite3 python3 python3-pip jq autossh i2c-tools python3-smbus -y -sudo pip3 install pyserial requests RPi.GPIO adafruit-circuitpython-bme280 crcmod psutil ntplib pytz --break-system-packages +sudo pip3 install pyserial requests RPi.GPIO adafruit-circuitpython-bme280 crcmod psutil ntplib pytz gpiozero --break-system-packages sudo mkdir -p /var/www/.ssh sudo ssh-keygen -t rsa -b 4096 -f /var/www/.ssh/id_rsa -N "" sudo ssh-copy-id -i /var/www/.ssh/id_rsa.pub -p 50221 airlab_server1@aircarto.fr diff --git a/windMeter/read_wind_speed.py b/windMeter/read_wind_speed.py new file mode 100644 index 0000000..41b481b --- /dev/null +++ b/windMeter/read_wind_speed.py @@ -0,0 +1,67 @@ +''' + __ _____ _ _ ____ + \ \ / /_ _| \ | | _ \ + \ \ /\ / / | || \| | | | | + \ V V / | || |\ | |_| | + \_/\_/ |___|_| \_|____/ + + +Script to read wind speed from a Davis Anémomètre-girouette Vantage Pro (6410) +https://www.shapemaker.io/blog/wind-speed-measurements-with-anemometer-and-a-raspberry-pi + +Connexion: +black (wind speed ) -> gpio21 +green (wind direction) -> gpio20 +Yellow -> 5v +RED -> GND + +Attention: The Raspberry Pi doesn't have analog inputs, so we need an analog-to-digital converter (ADC) to read the wind direction. + +/usr/bin/python3 /var/www/nebuleair_pro_4g/windMeter/read_wind_speed.py + +''' + + +import time +from gpiozero import Button +from signal import pause + +# Setup wind speed sensor on GPIO pin 21 (instead of 5) +wind_speed_sensor = Button(21) +wind_count = 0 + +def spin(): + global wind_count + wind_count = wind_count + 1 + +def calc_speed(spins, interval): + # Davis anemometer formula: V = P*(2.25/T) in MPH + # P = 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 + +# Register the event handler for the sensor +wind_speed_sensor.when_pressed = spin + +try: + print("Wind speed measurement started. Press Ctrl+C to exit.") + + while True: + # Reset the counter + reset_wind() + + # Wait for 3 seconds and count rotations + print("Measuring for 3 seconds...") + time.sleep(3) + + # Calculate and display wind speed + wind_speed = calc_speed(wind_count, 3) + print(f"Wind count: {wind_count} spins") + print(f"Wind speed: {wind_speed:.2f} mph ({wind_speed * 1.60934:.2f} km/h)") + +except KeyboardInterrupt: + print("\nMeasurement stopped by user") \ No newline at end of file