2018-03-08, 08:49 PM
(2018-03-08, 08:21 AM)CVL Wrote: yep, I felt adventurous and tried to do a bit of python-coding on myself. Not that I am expert - if anybody has a better idea how to transform pulses in speed measurement, I am glad to learn:
Code:#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
path = "/var/run/nmea.fifo"
os.mkfifo(path)
fifo = open(path, "w")
fifo.write('$VWVHW,,,,,0,00,N,,K\r\n')
fifo.close()
impulse_count = 0
NUM_CYCLES = 10
Counter = 10
while 1:
start = time.time()
for impulse_count in range(NUM_CYCLES):
GPIO.wait_for_edge(24, GPIO.FALLING)
duration = time.time() - start
Counter = Counter + 10
distance = Counter / 54737
distancer = round(distance,2)
speed = 15.2047222222 / duration
speedr = round(speed,2)
nmea = '$VWVHW,,,,,' + str(speedr) + ',N,,K\r\n$VWVLW,,N,' + str(distancer) + ',N\r\n'
fifo = open(path, "w")
fifo.write(str(nmea))
fifo.close()
time.sleep(0.5)
GPIO.cleanup()
The code counts 10 pulses and measures the time it takes. The paddlewheel documentation for the VDO says it counts 54737 pulses per 1nm, so this gives a basis for calculating speed in knots.
Then the values are transformed into NMEA-sentences and piped via a FIFO to kplex, which sends the NMEA to the cockpit.
Code:[file]
name=logge
filename=/var/run/nmea.fifo
direction=in
persist=yes
checksum=no
strict=no
The script is started from rc.local so it runs as root. Security concerns are not so high on a standalone-system
Certainly there are ways to do this in a more elegant fashion... but I am not really a programmer.
Hope it helps though.
fair winds
Christian
Thank you for sharing Christian! I may give this a go myself.
Much Appreciated!
Geoff