0

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?

3
  • 1
    I'd try a different Python GPIO module to see if it's related to RPi.GPIO or not. Which version are you using? pydoc RPi.GPIO shows a VERSION of 0.5.11 on my Pi.
    – joan
    Commented Oct 7, 2015 at 8:00
  • I updated yesterday. So that would be 0.5.11 as well. Which GPIO module are you suggesting?
    – Stapper
    Commented Oct 7, 2015 at 8:04
  • 1
    If you have RPIO that should be a direct replacement (but I'm not sure if it works on the Pi2). Any of the other Python GPIO modules would need tweaking to allow for callback differences.
    – joan
    Commented Oct 7, 2015 at 8:06

2 Answers 2

1

After rewriting this in C I faced the same issue. I was able to get it function by reloading the Lirc_rpi module and restarting the lirc Deamon. Lirc_rpi does set default pins if no pin out or pin in is given. So I had to set it explicity since the default pins are already in use by the script.

The script is roughly the same only added

call(["modprobe","lirc_rpi","gpio_in_pin=24","gpio_out_pin=23"])
call(["service","lirc","start"])

After setting up the pins. I also removed lirc_rpi from /etc/modules and disabled lirc deamon on boot.

0

Have you Connected your IR Transmitter with Correct pins? You can Recheck with "http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/"

This article gives a clear cut to use the Lirc Library with pi. Also first try to check with simple IRSEND Commands from Rpi's command line when all seems to be set up. Then Move to Python Scripting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.