Hi all, just wanted to give a short guide on reading digital inputs using the navigator board. NB: there are most likely easier and more efficient ways to do this, but this is just a method that I found which worked for me based off the suggestion here, so feel free to post suggestions if you feel something can be improved.
Issue: I have a winch connected to my blueboat which has a limit switch producing a digital HIGH/LOW value which needs to be read into a script to tell the pi when to stop the winch.
ADC0 and ADC1 values from the board proved tricky to read according to the posts I’ve read here, but Elliot mentioned the possibility of high-jacking a serial port for personal use.
This turns out to be the solutions which works for me, as referring to the navigator schematic we see the pins of Serial1 (5V, TX1, RX1, /, /, GND) which pass through a logic converter and then connect to RX1_RPI(GPIO14) and TX1_RPI(GPIO15). (Note: need to disable the serial connection connection you’re using beforehand in the BlueOS companion).
I cut 6 pin serial connection cable to expose my 14 and 15 pins (green and white for me). Now, I can run the following code in the BlueOS terminal and see the outputs change when I have the pin at 0 or 5 volts.
script: readpin.py
import RPi.GPIO as GPIO
#Set up the pin.
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
#Choose either pin 14 or 15 to poll in the Serial1 port.
#I'm using 14 here.
#Set the pin to be an input.
GPIO.setup(14, GPIO.IN)
#Choose either pullup or pulldown for the GPIO.
GPIO.setup(GPIO.LOW)
#Record the state of the pin.
state = GPIO.input(14)
#Print the result.
if(state):
print("ON")
else:
print("OFF")
now each time you run the script using the command “sudo python runscript.py” it should out to terminal the value of the pin.
Apologies if this is a janky solution and let me know if you have issues. Cheers!
Related links: Navigator Schematic
Previous discussion: How to read digital input from Navigator and show its value in QGroundControl? - #2 by EliotBR