direwolf icon indicating copy to clipboard operation
direwolf copied to clipboard

Add GPIO LED support when PTT is asserted

Open dranch opened this issue 7 years ago • 14 comments

The Direwolf DCD indicator is very helpful and I wonder if it would be possible to add another output GPIO pin for when PTT is asserted? I realize I could just tap the PTT GPIO pin to get the LED to light up but I think it would be a cleaner design if I could do this via another GPIO pin.

dranch avatar Oct 11 '16 17:10 dranch

Any traction here? I was just going over the source myself. I can't think of an elegant hardware solution (radio's ptt and led hooked up to same gpio). Monitoring the PTT state and applying a copy -cat cpio assertion would be doable. Ideally we add two pins to the PTT line in direwolf.conf.

craigerl avatar Jun 16 '20 21:06 craigerl

@dranch, @craigerl The most elegant solution to connect LED (or 2 LEDs) along with radio's PTT is HARDWARE. It does not make sense to double that functionality in software.

ew1abz avatar Jun 25 '20 05:06 ew1abz

I respectfully disagree. I pulled the source, and I think I can make a branch that has this functionality. vs pulling out the soldering iron, or coming up with two circuits that can somehow use the same gpio pin without affecting each other.

craigerl avatar Jun 25 '20 11:06 craigerl

There is some validity to this request as there is another request for Direwolf to have a pre and post-PTT command as well. I can see where a pre-PTT command might change an antenna relay box to disconnect the antenna from an SDR and connect it to a TX radio's antenna. Direwolf would then transmit it's packet and then the post-PTT command would return things.

dranch avatar Jun 25 '20 17:06 dranch

Sorry, maybe I should've provided more arguments. Functionality, that you are requesting, is very custom and most of users never going to use it. It's just not practical to satisfy every small request. Hardware modification seems harder but it's easy and safe in fact. I can check your schematic if you want.

ew1abz avatar Jul 08 '20 05:07 ew1abz

ok, giving up on a direwolf tweak.. I wrote a gpio mirror script that asserts voltage on a gpio pin (27) whenever direwolf's PTT gpio pin (24) is high. It uses the kernel's inode-notify feature and sysfs, so there's no polling. The LED on gpio 27 lights up as direwolf transmits.

"pip install pyinotify" first

#!/usr/bin/python

import pyinotify
import RPi.GPIO as GPIO

#gpio27 output works
#gpio23 output fails

def handle_change(cb):
   with open('/sys/class/gpio/gpio24/value', 'r') as f:
      #print(f.read())
      status = f.read(1)
      if status == '0':
         #print("OFF")
         GPIO.output(27, GPIO.LOW)
      else:
         #print("ON")
         GPIO.output(27, GPIO.HIGH)
   f.close

def null_function(junk):  # default callback prints tons of debugging info
   return()

GPIO.setmode(GPIO.BCM)    # logical pin numbers, not BOARD
GPIO.setup(27, GPIO.OUT)
GPIO.setwarnings(False)   # suppress pin-is-in-use warning

# Instanciate a new WatchManager (will be used to store watches).
wm = pyinotify.WatchManager()

# Associate this WatchManager with a Notifier
notifier = pyinotify.Notifier(wm, default_proc_fun=null_function)

# Add a new watch
wm.add_watch('/sys/class/gpio/gpio24/value', pyinotify.IN_MODIFY)

# Loop forever and handle events.
notifier.loop(callback=handle_change)

craigerl avatar Sep 02 '20 18:09 craigerl

So @craigerl, you found the third way how to solve it. I even didn't think this direction. It really looks elegant and solderless :) I like it! It also may be useful for other projects. Thank you for sharing it!

ew1abz avatar Sep 03 '20 19:09 ew1abz

I would very much like this feature as well.

hemna avatar Jul 29 '21 17:07 hemna

This keeps coming up. This time, if PTT is accomplished via CAT/USB, there's just no way for us to know if direwolf is transmitting, and no way for us to light up a red indicator LED. I would really like to see a feature that allows for multiple PTT devices on the PTT line of direwolf.conf.

craigerl avatar Aug 18 '21 23:08 craigerl

So is there any way to know if direwolf is transmitting? I'm down to USB sniffing for cat commands at this point. Ultimately, if a raspberry Pi is connected to a USB-based radio, there is no way to light up the red LED on this project, http://craiger.org/digipi/

craigerl avatar Oct 23 '21 19:10 craigerl

There are several ways:

  • Enable PTT debugging when starting direwolf with the "-do" option
  • Wire up a simple LED on the configured PTT GPIO pin so when the radio is keyed up by Direwolf, the LED will also light
  • Use PulseAudio's "monitor" feature and you can listen to the outgoing modem tones when Direwolf plays them
  • if you're using HamLib for CAT control, use rigctld and enable debugging there

dranch avatar Oct 23 '21 21:10 dranch

ok, i'm watching for lines that start with [0H] since they seem to be transmit lines. More specifically "[0[A-Z]]". Does that regex capture all transmit lines in the log file?

It's a hack, but at least I can light up a Red LED when direwolf is keying a transmitter over a USB cable :/

It really would be nice to have direwolf assert voltage on multiple GPIO pins during a transmit...

def red_led_from_logfile_thread():                               ## RED logfile
   f = subprocess.Popen(['tail','-F',logfile], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
   while True:
      line = f.stdout.readline().decode("utf-8", errors="ignore")
      search = re.search("^\[\d[A-Z]\]", line)
      if search is not None:
         draw.ellipse(( width - title_bar_height * 2           , padding,    width - title_bar_height - padding * 2 , title_bar_height - padding), fill=(200,0,0,0))
         with display_lock:
            disp.image(image)
         time.sleep(1)
         draw.ellipse(( width - title_bar_height * 2           , padding,    width - title_bar_height - padding * 2 , title_bar_height - padding), fill=(80,0,0,0))
         with display_lock:
            disp.image(image)

craigerl avatar Dec 10 '21 15:12 craigerl