I wanted to create a remote for a small tvscreen using Lirc and python. After booting I'm able to send commands from CLI (irsend) and it works. However when I start a Python scripts to read button inputs I receive various errors. "irsend command failed transmission failed" or "Hardware not supported" it depends on wether I start lirc first or python script. lirc is using GPIO 23 (I also tried other pins) Python is using GPIO 17,18,22,27
buttons.py:
import RPi.GPIO as GPIO
from subprocess import call
import uinput
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(22, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN,pull_up_down=GPIO.PUD_UP)
events = (uinput.KEY_ESC,)
device = uinput.Device(events)
def VolUp(channel):
call(["irsend","send_once","Screen","KEY_VOLUMEUP"])
def VolDown(channel):
call(["irsend","send_once","Screen","KEY_VOLUMEDOWN"])
def Input(channel):
call(["irsend","send_once","Screen","KEY_TV"])
def EscButton(): #Send Esc Key (like keyboard)
device.emit(uinput.KEY_ESC, 1) # Press.
time.sleep(.5)
device.emit(uinput.KEY_ESC, 0) # Release.
GPIO.add_event_detect(18, GPIO.RISING, callback=VolUp)
GPIO.add_event_detect(22, GPIO.RISING, callback=VolDown)
GPIO.add_event_detect(27, GPIO.RISING, callback=Input)
while True:
try:
GPIO.wait_for_edge(17, GPIO.FALLING)
EscButton()
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()
Any Ideas why I'm having this behaviour? Can using pyLirc solve this?