Menu

#208 Using add_event_detect() prevents other apps from using the GPIO pins.

New
nobody
None
High
Defect
2022-10-26
2022-10-26
No

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

Discussion

  • Ben Croston

    Ben Croston - 2022-10-26

    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
  • Walter A. Boring IV

    I'm trying to monitor the PTT being set high from python.

     
  • Ben Croston

    Ben Croston - 2022-10-26

    Is the PTT an output from direwolf?

     
  • Walter A. Boring IV

    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.

     
  • Ben Croston

    Ben Croston - 2022-10-26

    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.

     
  • Walter A. Boring IV

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.