How To Setup LIRC GPIO IR Remote Control On OpenELEC XBMC/Kodi Raspberry Pi 1 and 2

Submitted by administrator on

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:

  1. 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.
  2. OpenELEC. The instructions here will be step by step for OpenELEC setups but should give you a heads up for any other systems.
  3. 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
  4. 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
  5. 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:

  1. 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
    GPIO Wiring Raspberry Pi
    Image thanks to https://learn.adafruit.com/using-an-ir-remote-with-a-raspberry-pi-media-center/hardware
  2. 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:

  1. 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
  2. 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
  3. 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
  4. 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'):
    1. type: ssh root@TYPE IN THE IP ADDRESS YOU JUST FOUND
    2. type: openelec
    3. 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)
    4. 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
    5. RPI2 CONFIG.TXT (Ignore this section if your connection is working)
      1. type: mount -o remount,rw /flash
      2. type: nano /flash/config.txt
      3. Navigate to the very bottom of the file and type: dtoverlay=lirc-rpi
      4. Save and quit
      5. type: mount -o remount,ro /flash
      6. type: reboot (This will reboot the Pi. Once rebooted, make sure that you SSH back in again as above)
      7. 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)
    6. Right, now we will test the remote to make sure that it is speaking with the IR connection
      1. type: killall lircd
      2. 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)
      3. Hold ctrl, type: c
    7. 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
      1. type: cd /storage
      2. type: cd .config/
      3. type: irrecord -list namespace (This will give you a list of available keys)
      4. 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)
      5. When you are finished, simply follow the instructions to exit, then reboot
    8. With a little luck your remote control is now working!
    9. 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

ContextMenu
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.
KEY_TITLE
KEY_EPG

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

Interested in our web, graphic or print design services?
Simply call 07825 091983 to get started today

Content management systems by Drupal

Content Management (CMS)

SEO friendly, technophobe friendly

Having a website needn't be a daunting prospect. You should be able to edit and add to your site quickly and easily. That's why all of our projects are created using a Content Management System. This means that you don't need to swallow a manual to work with your site, everything is designed so that even a novice feels comfortable.

eCommerce solutions using Drupal and uBercart

eCommerce Website Solutions

Easy to manage, safe to sell

If you are looking to sell your products online, an eCommerce solution offers all the ease of use that a CMS brings, along with options for secure transactions. Our eCommerce packages allow integration with a wide range of payment gateways such as PayPal, Worldpay, CardSave, SagePay and many more, allowing you to choose the method that suits you.

Websites which work on all devices and internet browsers

Cross Browser Compatible

Pixel perfect, whatever the device

Looking great on your computer is one thing, but making sure your website looks perfect on everyone elses is what's most important. With a wide selection of browsers and devices, it is easy to over look small imperfections. At Jemford Design, we test your site across a selection of popular platforms to make sure your website always looks its best.

Expand your website as you grow

Bolt On Expansion Made Easy

Integrate new features as you go

Many people worry that they must get everything done in one big push when creating a website and fear the financial outlay it will bring. With Jemford Design, your website can start as small as an acorn and grow with your business by simply 'bolting on' new features as you need them or as finances allow, without worrying about huge extra costs.

Lightning fast, UK based web hosting at Jemford

UK Based Web Hosting

99.9% uptime on fast UK servers

If you decide to work with Jemford Web Design, you are safe in the knowledge that your first years hosting is covered, for free. You will also be comforted by the fact that we only use UK based, lightning fast servers to host your site and email. Our hosting providers offer first class service and excellent uptime reliability meaning your site is in good hands.

Excellent customer service and value for money at Jemford Web Design

Jemford Value & Service

No hidden costs, excellent service

With us, you know there are no hidden monthly fees waiting around the corner to bite you. Our philosophy is simple, you only pay when we work. We are always on hand to offer advice when needed, and always provide a quote before we undertake any project. Jemford has a reputation of excellent results and importantly, customer satisfaction.

"With a 6 month window to sell our seasons stock, Jemford created the best AdWords account to gain maximum return for our advertising budget. In that 6 months, we were able to sell over 60% of our stock. We were delighted with the speed to which our requests were turned around and the helpful advice offered to us 'technophobes'."