|IR sensor and cable hiding inside PiBow case|
Basically I followed this AdaFruit Tutorial for adding an IR receiver to the Raspberry Pi, but not being in the USA I had to substitute parts which I sourced via eBay instead. Despite much searching, the shortest suitable jumper cables I could find (one pin to one pin, 1P-1P, and female-to-female, F/F) were 10cm long - which is a bit much to coil up inside the Pibow case but easier than soldering.
- 1x TSOP38238 InfraRed receiver (under £2 from eBay with shipping)
- 3x 10cm Dupont Wire 2.54mm 1P-1P Female/Female jumper cable (pack of 40 for £1 on eBay)
The three jumper wires (split off my ribbon of 40 as a triple) connect the three pins of the IR sensor to GPIO18, GND, and 3V3 respectively (pins 12, 6, and 1).
|IR sensor and 10cm jumper leads to Raspberry Pi|
Raspian ConfigurationI just used the following to check the hardware was working:
$ sudo apt-get install lirc
$ sudo modprobe lirc_rpi
$ mode2 -d /dev/lirc0
This showed it received signals from my assorted working IR remote controls. I didn't go any further with this since I'm not actually running XBMC under Raspian at the moment.
OpenELECThen for XBMC under OpenElec, I followed the instructions here via SSH. Under OpenElec LIRC is already installed, we just need to enable it for the current session, add this to the startup script for future use, and then configure the remote control.
$ modprobe lirc_rpi
$ echo "modprobe lirc_rpi" >> /storage/.config/autostart.sh
$ irrecord /storage/.config/lircd.conf
Running irrecord is a bit fiddly, but seems to work nicely. I found it helps to have looked at the output of this command which lists all the KEY_* names that irrecord understands.
$ irrecord --list-namespace
Remote control configuration tips for XBMC (see this HowTo):
- For navigating the menus in place of the cursor keys on a normal keyboard, define KEY_LEFT, KEY_RIGHT, KEY_UP and KEY_DOWN (at least that was easy).
- For navigating the menus in place of 'enter' on a normal keyboard, define KEY_OK rather than KEY_SELECT or KEY_ENTER.
- For navigating the menus in place of 'backspace' on a normal keyboard, use KEY_EXIT, none of KEY_BACKSPACE, KEY_BACK or KEY_CANCEL work.
- For the context menu reached via 'c' on a normal keyboard, none of KEY_C, KEY_MENU or KEY_CONTEXT_MENU work. However, KEY_EPG (electronic program guide) does.
- For media information reached via 'i' on a normal keyboard, defining KEY_INFO works.
- For changing the volume, KEY_VOLUMEUP and KEY_VOLUMEDOWN work fine. However KEY_MUTE appears to have no effect.
- For rapid scrolling through the menus I like to use Page Up/Down on my normal keyboard. Unfortunately KEY_PAGEUP and KEY_PAGEDOWN via the remote have no effect.
When I say things have no effect, they are being detected as you can monitor this live via SSH while running XMBC:
$ irw /var/run/lirc/lircd-lirc0
To rename a key, edit /storage/.config/lircd.conf and reboot.
This was done under OpenElec v2.95.6, which I then updated to v3.2.2 after realising the automatic updates hadn't picked up the major releases. The remote still seems to work (and seems to have fixed a playback glitch too). I may need to fine tune the repeat settings for best results...
Update (April 2015) for Raspberry Pi 2
Eventually, as XBMC/Kodi was updated, my original Raspberry Pi could not keep it - it was getting slow in the menus, and would get stuck while playing videos. I replaced it with the newer Raspberry Pi 2 which has more RAM and a faster CPU. This has worked great with OpenElec 5.0.8 and Kodi, but once again I wanted to setup an IR remote under OpenElec.
I used the same model TSOP38238 InfraRed receiver, and the exact same pins on the new Raspberry Pi. I again opted for the pibow case with its clear lid, this time picking the black "ninja" version rather than the "rainbow". I was a little disappointed though - it looks noticeably taller and less cute as a result. The reason seems to be the new Pi's USB ports are a millimetre or so higher forcing Pimori to add an extra layer to the PiBow case compared to the original. On the rainbow model this new layer is transparent so it is hard to see in the photos.
Anyway, on to the code side of things:
OpenELEC:~ # modprobe lirc_rpi
modprobe: ERROR: could not insert 'lirc_rpi': No such device
It turns out the IR module is now disabled by default, so we need to enable it:
OpenELEC:~ # mount -o remount,rw /flash
OpenELEC:~ # nano /flash/config.txt
Referring to the official documentation, add the line dtoverlay=lirc-rpi to this file and save it, then reboot.
OpenELEC:~ # modprobe lirc_rpi
OpenELEC:~ # killall lircd
OpenELEC:~ # irrecord /storage/.config/lircd.conf
This worked as expected, and I could have gone through the same hassle as before to configure the keys. But I cheated and copied my old lircd.conf file over instead.