In helping people build their own media centers using the ridiculously popular Kodi (formerly XBMC) and Raspberry Pi 1(B and B+) and newer 2 model, one thing that gets asked a lot is, 'How can I set up a proper remote control for it if my TV hasn't got HDMI CEC built in?' Well, it's a fairly complicated process if you don't know how, with many examples and instructions out of date, so I thought I'd put a simple, step by step instruction manual together.
This covers adding an IR remote control to a Raspberry Pi B, B+ and 2 using OpenELEC Kodi/XBMC.
Things you'll need:
- A working, IR remote control. Anything whatsoever, so if you have an old TV that is dead and buried, but still have the remote, this will enable you to pair it all up.
- OpenELEC. The instructions here will be step by step for OpenELEC setups but should give you a heads up for any other systems.
- Raspberry Pi B, B+ or 2. The slower A should work exactly the same, but it might be a little slow running OpenELEC in any case
- TSOP4838 IR receiver. This is what will be added to your Pi board to enable the connection to work. They should be around £2-3 on eBay or any local electronics store. You can either solder it onto the pins directly, or go the fast and easy route, like me, and simply buy female jumper wires at the same time for pennies and connect each pin to the correct pin
- A laptop, PC or Mac. You will need this to SSH into the Pi while it is on and working. Laptops are ideal as you can move the laptop right next to the TV and Pi you are working on which is essential
Preparing the board:
- With the Pi turned off and disconnected, connect your IR receiver to the board using the diagram displayed as an example. Simply connect each end to the corresponding pin by solder or jumper wire
Image thanks to https://learn.adafruit.com/using-an-ir-remote-with-a-raspberry-pi-media-center/hardware - That's it. Now connect your Pi up to your TV as you normally would and turn it on. At this point we don't know if the connections are working, but we will find out when we SSH in
Connecting to Pi and configuring:
- First, we need to make sure that SSH is turned on in your Pi. It isn't by default so chances are it needs turning on. Go into OpenELEC configuration plugin on your Pi and select the option to turn on SSH. Don't add a password, we won't need it
- Now SSH is on, we need the IP address that the Pi is using. Again, in OpenELEC configuration, go to the connections section and note down the IP, such as 10.0.1.40
- We are ready to connect to your Pi. You will need an SSH program for this. Mac and Linux users can use Terminal, Windows users can use something like PuTTY
- Now follow the instructions below and type as described (these are exactly typed through Terminal on a Mac and should be universal. If any errors pop up, you might need to prefix any instruction with 'sudo'):
- type: ssh root@TYPE IN THE IP ADDRESS YOU JUST FOUND
- type: openelec
- type: dmesg (This is to check the IR is connected properly and working. When typed, it will list a whole host of information, but you need to look for a line like: lirc_rpi: auto-detected active low receiver on GPIO pin 18. This should be at the bottom of the output. If you have an RPi2, chances are this will be missing, so don't worry)
- If the line 'lirc_rpi: auto-detected active low receiver on GPIO pin 18' is there, or VERY similar everything is connected properly. If not, follow these:
- Are you using a Raspberry Pi 2? No problem, move onto the section RPI2 CONFIG.TXT
- If you are not using a Raspberry Pi 2, try the RPI2 CONFIG.TXT section, but I would suggest that you might not have the IR connected properly. Turn off the Pi, check the connections with the diagram and try again
- RPI2 CONFIG.TXT (Ignore this section if your connection is working)
- type: mount -o remount,rw /flash
- type: nano /flash/config.txt
- Navigate to the very bottom of the file and type: dtoverlay=lirc-rpi
- Save and quit
- type: mount -o remount,ro /flash
- type: reboot (This will reboot the Pi. Once rebooted, make sure that you SSH back in again as above)
- type: dmesg (lirc_rpi: auto-detected active low receiver on GPIO pin 18 should now be in there. If so success, if not, try checking the physical connections again and retry the RPI2 CONFIG.TXT section)
- Right, now we will test the remote to make sure that it is speaking with the IR connection
- type: killall lircd
- type: mode2 -d /dev/lirc0 (Then start pressing buttons on your remote. You should then see lots of information appear in your SSH window indicating that everything is fine. If not, make sure that the remote actually work, that it is being pointed at the Pi and that its batteries are ok)
- Hold ctrl, type: c
- If you are at this point, everything is connected properly and communicating, we now need to map your buttons so that when you press a button, the Pi knows what to do
- type: cd /storage
- type: cd .config/
- type: irrecord -list namespace (This will give you a list of available keys)
- type: irrecord -d /dev/lirc0 lircd.conf (This will now begin a mapping wizard. Follow the on screen instructions. When you get to the point where you have to add keys, these are the options I would recommend:
KEY_UP
KEY_DOWN
KEY_LEFT
KEY_RIGHT
KEY_OK
KEY_PLAY
KEY_EXIT (BACK)
KEY_STOP
KEY_INFO
KEY_EPG (CONTEXT MENU) - When you are finished, simply follow the instructions to exit, then reboot
- With a little luck your remote control is now working!
- You can turn off SSH now if you want
For extra help, or configuration there are some notes below that might help.
EXTRA HELP:
KEY Name for Context Menu.
For the Actions of Keys check your remote.xml file mine was in:
/usr/share/kodi/system/keymaps/remote.xml
Ok notice the word title
Next step was to look at Lircmap.xml mine was in:
/usr/share/kodi/system/Lircmap.xml
These are the Key Names given to the remote for the selected action.
ContextMenu is KEY_TITLE or KEY_EPG
RESOURCES:
Place I found helpful when compiling this information:
Raspberry Pi GPIO Connections:
https://www.raspberrypi.org/documentation/usage/gpio/
Raspbmc IR Setup:
https://learn.adafruit.com/using-an-ir-remote-with-a-raspberry-pi-media-center/overview
A whole list of pre mapped IR remote files. Check if yours is there:
http://lirc.sourceforge.net/remotes/
RPi Guide To LIRC:
https://www.youtube.com/watch?v=QV_QmDKx0kQ