[mythtv-users] MythTV Raspberry Pi2 - GPIO IR Remote control [HOWTO]

Kingsley Turner krt at krt.com.au
Wed Jan 6 23:07:48 UTC 2016


G'day,

Based on this web-page: 
http://ozzmaker.com/2013/10/24/how-to-control-the-gpio-on-a-raspberry-pi-with-an-ir-remote/ 
(and stuff I've done previously with IR & Arduino) I managed to get MythTV 
on my RPi2b working with a remote control.  I don't really have much 
experience with RPi hardware though, so errors and omissions could be 
expected.  I'm using the raspbian image, so you'll need to adjust for other 
OSes.

First you need an IR receiver.  They look a bit like an LED or transistor, 
having 3 legs.  The one I used was from here: 
http://yourduino.com/sunshop2/index.php?l=product_detail&p=210 but only 
because I had some lying around.  Probably any sort of 38KHz IR receiver IC 
would be OK.  Maybe you can find one in an old appliance.

You need to check the pinout information for your particular IR IC to 
determine which leg is (+), (-) and signal.  The one I used seems to be like 
a PIC12043S, so looking at the front of it, the legs are signal, (-), (+).  
This page has a diagram of common pinouts: 
http://arduino-info.wikispaces.com/IR-RemoteControl

I soldered some female socketed wires onto the ends of the legs so they 
could easily be connected to the pins of the raspberry pi.
It's possible to buy pre-mounted IR ICs which can just be connected with 
hookup wires.

The legs then need to be connected to the RPi GPIO pins.  There's lots of 
pin diagrams, here's one: 
http://www.keytosmart.com/wp-content/uploads/2014/07/B_Diagram_large.png

The (+) leg goes to GPIO pin #1 = 3.3v power
The (-) leg goes to GPIO pin #6 = Ground (or any other ground)
The signal leg goes to GPIO pin #12 = GPIO18

I only used GPIO18 because it's common, and not assigned to anything else.  
It's what everyone else commonly uses too.

On the software side, you first need to install lirc on raspbian:
    # sudo apt-get install lirc liblircclient-dev

(you probably only need liblircclient-dev) if you want to do some 
programming with it too.

Adding these lines in /etc/modules causes the IR driver to be loaded:
    lirc_dev
    lirc_rpi gpio_in_pin=18

Depending the type of IR IC used you may need to tell the RPi that it's 
"active-low".  The one I used is like this.
Try it without first, and if the "mode2" command (see below) fails, add to 
/boot/config.txt:
    dtoverlay=lirc-rpi,gpio_in_pull=up

And reboot.

So now the rest is software-side configuration.
Create (or edit) /etc/lirc/hardware.conf

    # /etc/lirc/hardware.conf
    # Arguments which will be used when launching lircd
    LIRCD_ARGS="--uinput"

    #Don't start lircmd even if there seems to be a good config file
    #START_LIRCMD=false

    #Don't start irexec, even if a good config file seems to exist.
    #START_IREXEC=false

    #Try to load appropriate kernel modules
    LOAD_MODULES=true

    # Run "lircd --driver=help" for a list of supported drivers.
    DRIVER="default"
    # usually /dev/lirc0 is the correct setting for systems using udev
    DEVICE="/dev/lirc0"
    MODULES="lirc_rpi"

    # Default configuration files for your hardware if any
    LIRCD_CONF="/etc/lirc/lircd.conf"
    LIRCMD_CONF=""

And reboot (make sure you got that DRIVER="default").

To test if the remote is working at all, stop lirc, and run "mode2" which 
basically dumps out whatever the IR module sees:
    # sudo /etc/init.d/lirc stop
    # mode2 -d /dev/lirc0

Point whatever remote control you want to use at the IR IC module, and push 
a few buttons.

If you get some words and numbers output at this point, it should be mostly 
working.  If not, check your IR IC pins are wired correctly, lirc modules 
are loaded OK (lsmod), and maybe add the gpio pull-up codes in 
/boot/config.txt (see above).

Once you have it working to this point, you can (mostly) follow any of the 
lirc guides for mythtv.

I used
    # irrecord -d /dev/lirc0 ~/lircd.conf
    # sudo cp -i ~/lircd.conf /etc/lirc/lircd.conf
to create a config file for my obscure non-brand-name remote control.
And reboot.
Note: I only suggest rebooting, since it ensures a 'clean slate' test.  If 
you just want to stop and start lirc, well that's up to you.

Once this is done, you can test it with irw
# pi at raspberrypi:~ $ irw
00000000807f9867 00 KEY_ENTER noontec_a6
00000000807f58a7 00 KEY_RIGHT noontec_a6


However... however I only have it mostly working myself.
For whatever reason, I keep getting repeated key-presses in mythfrontend.
But I'll post another message about this.

cheers,
-kingsley



More information about the mythtv-users mailing list