This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I see wind speed (& direction) with digital (& analogic)wind sensor in OP&SK?
#4
I finally succeeded, this is the code I used to send NMEA0183 sentences to SignalK. Now I'm able to display speed in instrument panel.This is just the beginning, now I have to do the same thing with the wind direction, but now I have good hopes  Wink

Code:
from gpiozero import Button
import socket, pynmea2
import time
import math

W_Direction = 35  # To be sostitute with analog...
count = 0         # Counts how many half-rotations
radius_cm = 7.0   # Radius of your anemometer
wind_interval = 1 # How often (secs) to report speed
store_speeds = [] # Empty list

ADJUSTMENT = 1.18
CM_IN_A_ML = 185200.0
SECS_IN_AN_HOUR = 3600

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Every half-rotation, add 1 to count:

def spin():
   global count
   count = count + 1

# Calculate wind speed given the time interval:

def calc_speed(time_sec):
       global count
       circumference_cm = (2 * math.pi) * radius_cm
       rotations = count / 2.0

       # Calculate distance travelled by a cup in mile
       dist_ml = (circumference_cm * rotations) / CM_IN_A_ML

       # Speed = distance / time
       ml_per_sec = dist_ml / time_sec
       ml_per_hour = ml_per_sec * SECS_IN_AN_HOUR

       # Calculate speed
       final_speed = ml_per_hour * ADJUSTMENT

       return final_speed

def reset_wind():
    global count
    count = 0

wind_speed_sensor = Button(5)
wind_speed_sensor.when_activated = spin

# Loop to measure wind speed and report at wind_interval:

while True:
    start_time = time.time()
    while time.time() - start_time <= wind_interval:
           reset_wind()
           time.sleep(wind_interval)
           final_speed = calc_speed(wind_interval)

# NMEA0183 sentences to localhost 10110 to allow data read with Openplotter:

    mwv = pynmea2.MWV('O$', 'MWV', (str(round(W_Direction,1)),'R',str(round(final_speed,1)),'N','A'))
    mwv1=str(mwv)
    mwv2=mwv1+"\r\n"
    time.sleep(0.051)
    sock.sendto(mwv2, ('localhost', 10110))
Reply


Messages In This Thread
RE: How can I see wind speed (& direction) with digital (& analogic)wind sensor in OP&SK? - by pol.bob - 2019-10-26, 04:55 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)