2019-01-20, 11:08 AM
(2018-12-25, 10:52 PM)gypsylyon Wrote: More complicated, you can read the pulses from the speed sensor directly with a GPIO from the Raspberry Pi. As the hall sensor produces, as you said, 12 Volt pulses. This voltage must first be reduced to the 3V input of the Raspberry GPIO, for example by using a voltage divider mounted as a pull down system,
That if, it will be necessary to write a program in Python to read the pulses and to turn them into speed
I connected the paddlewheel sensor (an old VDO sensor) directly to GPIO. But it's a little bit more of quick'n dirty hack: Instead of feeding 12V, it works well even with 5V which I forked off the Pi power supply.
No opto-isolation, but just a voltage division with 1kO-resistance to get 3.3V on pin 24
and then a simple phython script to transform the pulses into NMEA-sentences, which are fed to kplex with a FIFO:
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 = 100
Counter = 100
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 + 100
distance = Counter / 27368
distancer = round(distance,2)
speed = 7.6 / 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 values are experimental, I found it very hard to get documentation on how many pulses the sensor should give for 1 nautical mile.
This worked nicely during our summer cruise last summer, even though it can surely be made better.
Fair winds
Christian