Skip to content

Instantly share code, notes, and snippets.

@sp5wwp

sp5wwp/ptt.py

Last active Feb 25, 2021
Embed
What would you like to do?
PTT python script for RPi
import RPi.GPIO as GPIO
import time
import sys
import os
import signal
import subprocess
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(2,GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(3,GPIO.OUT)
a=0
last_ptt=1
GPIO.output(3, 0)
while True:
ptt = GPIO.input(2)
if ptt==0 and last_ptt==1:
time.sleep(0.05)
if GPIO.input(2)==0:
last_ptt=0
GPIO.output(3, 1)
a = subprocess.Popen('arecord -D plughw:1,0 -c 1 -r 8000 -f S16_LE | sox --buffer 18 -t raw -r 8k -b 16 -e signed -L -c 1 - -r 8k -t raw - | m17-mod -S SP5WWP | aplay -D plughw:1,0 -c 1 -r 48000 -f S16_LE', shell=True, preexec_fn=os.setpgrp)
print("PTT down")
if ptt==1 and last_ptt==0:
time.sleep(0.05)
if GPIO.input(2)==1:
last_ptt=1
time.sleep(0.75)
GPIO.output(3, 0)
os.killpg(os.getpgid(a.pid), signal.SIGTERM)
print("PTT up")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment