From 14044a88565604687d653709036e02f537bbae53 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 12 Mar 2025 17:55:30 +0100 Subject: [PATCH] update --- MPPT/read.py | 12 +++++ README.md | 2 +- windMeter/read_wind_direction.py | 84 ++++++++++++++++++++++++++++++++ windMeter/read_wind_speed.py | 4 +- 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 MPPT/read.py create mode 100644 windMeter/read_wind_direction.py diff --git a/MPPT/read.py b/MPPT/read.py new file mode 100644 index 0000000..45cbf09 --- /dev/null +++ b/MPPT/read.py @@ -0,0 +1,12 @@ +import serial + +def read_vedirect(port='/dev/serial0', baudrate=19200): + ser = serial.Serial(port, baudrate, timeout=1) + + while True: + line = ser.readline().decode('utf-8', errors='ignore').strip() + if line: + print(line) # Raw data from Victron + +if __name__ == "__main__": + read_vedirect() diff --git a/README.md b/README.md index ab0d3c1..7e4426c 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 gpiozero --break-system-packages +sudo pip3 install pyserial requests RPi.GPIO adafruit-circuitpython-bme280 crcmod psutil ntplib pytz gpiozero adafruit-circuitpython-ads1x15 numpy --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_direction.py b/windMeter/read_wind_direction.py new file mode 100644 index 0000000..238b029 --- /dev/null +++ b/windMeter/read_wind_direction.py @@ -0,0 +1,84 @@ +''' + __ _____ _ _ ____ + \ \ / /_ _| \ | | _ \ + \ \ /\ / / | || \| | | | | + \ 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) -> ADS1115 (module I2C) +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. + +sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/windMeter/read_wind_direction.py + +''' +import time +import board +import busio +import adafruit_ads1x15.ads1115 as ADS +from adafruit_ads1x15.analog_in import AnalogIn + +# Create the I2C bus and ADC object +i2c = busio.I2C(board.SCL, board.SDA) +ads = ADS.ADS1115(i2c) + +# Connect to the channel with your Davis wind vane +wind_dir_sensor = AnalogIn(ads, ADS.P0) + +# Check the current voltage range +min_voltage = 9999 +max_voltage = -9999 + +def get_wind_direction(): + """Get wind direction angle from Davis Vantage Pro2 wind vane""" + global min_voltage, max_voltage + + # Read voltage from ADS1115 + voltage = wind_dir_sensor.voltage + + # Update min/max for calibration + if voltage < min_voltage: + min_voltage = voltage + if voltage > max_voltage: + max_voltage = voltage + + # We'll use a safer mapping approach + # Assuming the Davis sensor is linear from 0° to 360° + estimated_max = 3.859 # Initial estimate, will refine + + # Calculate angle with bounds checking + angle = (voltage / estimated_max) * 360.0 + + # Ensure angle is in 0-360 range + angle = angle % 360 + + return voltage, angle + +# Main loop +try: + print("Reading wind direction. Press Ctrl+C to exit.") + print("Voltage, Angle, Min Voltage, Max Voltage") + while True: + voltage, angle = get_wind_direction() + print(f"{voltage:.3f}V, {angle:.1f}°, {min_voltage:.3f}V, {max_voltage:.3f}V") + time.sleep(1) +except KeyboardInterrupt: + print("\nProgram stopped") + print(f"Observed voltage range: {min_voltage:.3f}V to {max_voltage:.3f}V") + + # Suggest calibration if we have enough data + if max_voltage > min_voltage: + print("\nSuggested calibration for your setup:") + print(f"max_voltage = {max_voltage:.3f}") + print(f"def get_wind_direction():") + print(f" voltage = wind_dir_sensor.voltage") + print(f" angle = (voltage / {max_voltage:.3f}) * 360.0") + print(f" return angle % 360") \ No newline at end of file diff --git a/windMeter/read_wind_speed.py b/windMeter/read_wind_speed.py index 41b481b..fdc3ac3 100644 --- a/windMeter/read_wind_speed.py +++ b/windMeter/read_wind_speed.py @@ -11,13 +11,13 @@ https://www.shapemaker.io/blog/wind-speed-measurements-with-anemometer-and-a-ras Connexion: black (wind speed ) -> gpio21 -green (wind direction) -> gpio20 +green (wind direction) -> ADS1115 (module I2C) 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 +sudo /usr/bin/python3 /var/www/nebuleair_pro_4g/windMeter/read_wind_speed.py '''