Using add_event_detect() prevents other apps from using the GPIO pins.
A Python module to control the GPIO on a Raspberry Pi
Brought to you by:
croston
I have direwolf running on my raspi as a ham radio digipeter, which uses GPIO Pin 16 for Push to Talk to send a packet over RF. I want to detect when PTT is raised without affecting direwolf. Unfortunately, when using add_event_detect on the pin, it causes direwolf to raise errors when trying
to use the GPIO pin.
Here is my code
def test(ctx):
console = ctx.obj['console']
pin = 12
def rx_pin(**kwargs):
console.print(f"rx_pin pin {pin}")
console.print_json(data=kwargs)
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN)
GPIO.add_event_detect(pin, GPIO.RISING, callback=lambda x: rx_pin)
loop = asyncio.get_event_loop()
msg = "Checking status of RX LED "
with console.status(msg) as status:
loop.run_forever()
loop.close()
Here is the output of my test app
(.dwm-venv) pi@digipi:~/mine/python-direwolf-monitor/direwolf_monitor/cmds $ dwm test
/home/pi/mine/python-direwolf-monitor/direwolf_monitor/cmds/leds.py:74: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(pin, GPIO.IN)
⠼ Checking status of RX LED
The output of direwolf
PTT 0 = 1
Error setting GPIO 12 for PTT
Operation not permitted
[0L] APPOMX>APDW16,WIDE2-1:!3720.66N107850.98W#PHG7260 WB4BOR tier1 digi, RF & Internet
PTT 0 = 0
Error setting GPIO 12 for PTT
Operation not permitted
Rather than a software fix, would it not be easier in this case to connect your PTT to a second input pin as well and use that?
Last edit: Ben Croston 2022-10-26
I'm trying to monitor the PTT being set high from python.
Is the PTT an output from direwolf?
PTT = push to talk. it raises one of the GPIO pins to high which is connected to my ham radio to key up the mic for transmit out RF.
I'm trying to monitor direwolf when it raises the PTT GPIO pin
There is also an RX GPIO Pin as well that I want to monitor at the same time
Ultimately I'm trying to monitor when my ham radio does a TX and RX via the GPIO pins that direwolf uses.
I would loop back pin 12 to another spare pin on your RPi using a 1k resistor and monitor that pin instead. It isn't possible to set up events for an output channel.
Just seems like a bad bug that I can't even watch for a change while only reading a pin that it causes failures elsewhere.