Hi to all !
Openplotter ver 1.2.0 on RPi 3B+, wind sensor like this :
https://www.argentdata.com/files/80422_datasheet.pdf
I connected the anemometer to the RPI via gpio5 and I can see the switc 1/0 on SignalK panel. I would like to be able to convert the values 1/0 to a speed value that can be displayed on the signalK panel. I would also like to be able to do this with the analog sensor, after appropriate conversion of the signal via ADC MCP3008 to digital signals.
Is this possible?
I am not a programmer and I am getting lost among the various Openplotter manuals, opencpn, SignalK, node red, Kplex, etc..
Could you give me a starting point and which manuals to focus on in order to find a solution?
Even the ready-made solution would be welcome
Thanks in advance
Paolo
My advice: first get your sensors working. With a bit of help from Google you should be able to create a pulse counter and get your ADV working.
Once you have the data you can send it to SK server via udp for example.
This way you can concentrate on what matters: getting the data in so you can do something with it. And forget all the concepts you mentioned for the time being.
Sent from my iPhone using Tapatalk
Thanks for your reply.
The sensors actually work, or rather, the anemometer currently works. I have a program in pyton that, as a function of impulses in time, calculates the distance traveled, so I have speed. The step I miss is how to extract data from the program in python (better traduceing it in NMEA0183 sentence?) and send it via UDP (or better TCP?) so that it is displayed in the dashboard.
I know, I'm so noob, but stubborn .. I will try
Anyway this is "my" code, how could I send
calc_speed ?
Code:
from gpiozero import Button
from time import sleep
import math
count = 0 # Counts how many half-rotations
radius_cm = 7.0 # Radius of your anemometer
interval = 3 # How often (secs) to report speed
ADJUSTMENT = 1.18
CM_IN_A_ML = 185200.0
SECS_IN_AN_HOUR = 3600
store_speeds = [] # Define a list to store last 4 wind speeds
# Every half-rotation, add 1 to count
def spin():
global count
count = count + 1
print( count )
# Calculate the wind speed given the time interval
def calc_speed(time_sec):
global count
global store_speeds
circumference_cm = (2 * math.pi) * radius_cm
rotations = count / 2.0
# Calculate distance travelled by a cup in km
dist_km = (circumference_cm * rotations) / CM_IN_A_ML
# Speed = distance / time
km_per_sec = dist_km / time_sec
km_per_hour = km_per_sec * SECS_IN_AN_HOUR
# Calculate speed
final_speed = km_per_hour * ADJUSTMENT
# Add this speed to the list
store_speeds.append(final_speed)
# If that takes the list over 4 items, chop off the first
if len(store_speeds) > 4:
store_speeds = store_speeds[1:]
# Show what is in the store_speeds list
print( str(store_speeds) )
return final_speed
# Check whether the last 20 seconds of readings had any gusts
def check_for_gusts():
highest = max(store_speeds)
lowest = min(store_speeds)
GUST_ABOVE = 1
GUST_RANGE = 2
if highest > GUST_ABOVE and highest - lowest > GUST_RANGE:
return highest
else:
return 0
wind_speed_sensor = Button(5)
wind_speed_sensor.when_activated = spin
# Loop to measure wind speed and report at 5-second intervals
while True:
count = 0
sleep(interval)
print( calc_speed(interval), "kph")
print("Gust speed " + str(check_for_gusts()) + "kph")
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
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))