You may have seen my blog post about creating a small portable media center that I can easily take on holiday to hook up to the hotel TV. If not, you can find it here;

 

Raspberry Pi powered media center to take on holiday

 

To reduce the amount space it took up, I used a cheap USB keypad which could be used to control the media center. It worked really well & having something hard-wired meant I didn't have to worry about a Bluetooth-paired device needing re-pairing.

 

However, what I then realised was it would be good to be able to use a spare remote control instead. I was using the OpenElec distribution and looked through their documentation for how to do this, but only found references to version 3 of the software (it's on version 7) and how to get LIRC working with it. There were plenty of blog posts on hooking up IR support, but a lot of them were written 2-3 years ago, and the software has moved on somewhat.

 

Hardware Setup

 

What I did first was buy a suitable IR receiver. I chose the Vishay TSOP4838TSOP4838 (which costs less than £1) because of the voltage range (2.5-5.5v) and receiver frequency (38KHz). If you look at the datasheet for the product, you'll see which pins should get wired up to the Pi;

 

 

Simply wire pin 1 to GPIO 18, pin 2 to GND, and pin 3 to a 3.3v power pin, e.g.

 

 

By using some short F-F jumper wires and a small cut in the side of the case, I was able to position the reciever neatly(ish) on the side.. it's still easily removable, but you could integrate it into the case a bit more seamlessly than this

 

 

 

 

Software Setup

 

Before this project I was using OpenElec, but had limited success getting the IR support working properly. I switched to OSMC which I'd read had better IR support through the main UI. I think I was actually on the right track with OpenElec, but I realised later that the old vintage Xbox remote I was trying to use wasn't 100% working.

 

If you're going to use a remote control that's officially recognised, then you can jump this part about learning IR remote control codes.

 

Learning IR remote commands

 

The remote I found in the loft was an old DVD player remote which (unsurprisingly) wasn't in the list of pre-recognised remotes in the OSMC installation. I needed to get the Pi to learn the IR pulses being sent out by the remote and map them to the Kodi functions.

 

1. First off, you need to telnet to the Pi. Username: osmc, Password: osmc.

 

2. Next you need to stop the LIRC service which is being locked/used by Kodi

 

sudo systemctl stop lircd_helper@lirc0

 

3. Now you can run the IR learn mode.. this will record what it finds to the config file you specify;

 

irrecord -d /dev/lirc0 /home/osmc/lircd.conf

 

4. Follow the on-screen instructions which will recognise your remote.

 

One observation I had was that this only worked properly if I stopped after the first prompt to press lots of keys on the remote.. if I completed the second stage, the key mapping didn't work, e.g.

 

If I ignored the second phase & let it abort, the learn process worked

 

 

When it's working, you'll be able to enter the Kodi function (like KEY_UP, KEY_DOWN, etc)  & map it to a key press on your remote;

 

Once you've mapped all the functions you want, we then need to move back to OSMC and tell it to use that config file we've just written.

 

OSMC Settings

 

In OSMC you need to do the following;

 

1. Disable the CEC service (via System Settings > Input > Peripherals > CEC Adapter), which seems to be needed for LIRC to work.

2. Now go into OSMC settings and pick the Raspberry Pi icon

 

 

2. Go into Hardware Support and enabled LIRC GPIO Support. You shouldn't need to change anything if you connected the sensor to GPIO 18.

 

 

3. Now go back and select the Remote Control option;

 

 

4. Ignore the list of pre-installed remotes and select Browse;

 

 

5. Navigate to the folder where LIRC wrote your config file;

 

 

6. Confirm the change & reboot the box;

 

 

That should be it.. your remote should be able to control everything in Kodi.