User avatar
Posts: 65
Joined: Fri May 25, 2012 5:33 am

IR Receiver & OpenElec

Wed Dec 26, 2012 1:23 pm

Disclaimer – As usual I am not responsible if you damage your device so follow this tutorial at your own risk.

My experiences with hooking up an Infra red receiver module,

Firstly the hardware I used,
IR receiver tsop31238
The data sheet is available here

tsop31238 PIN 1 = GROUND = PI P1 PIN6
tsop31238 PIN 2 2.5 – 5.5v = Pi P1 Pin1 (3.3v)
tsop31238PIN 3 =OUTPUT= Pi P1 Pin12 (GPIO18)

Connecting the IR receiver was the easy part

Optionally you could hook up a LED to GPIO23 P1 Pin16 (with a resistor) which would give you visual output of what the lirc module is receiving (i've not tried this)

Once the receiver was hooked up ensure your raspbian firmware is up to date
Check your version

Code: Select all

uname -a
and update if needed

Code: Select all

sudo rpi-update
next install lirc

Code: Select all

apt-get install lirc
Optional X window stuff(this will give you xmode2 which is handy in the GUI) kind of like a IR oscilloscope

Code: Select all

sudo apt-get install lirc-x

Add the lirc module

Code: Select all

sudo nano /etc/modules
And add the following 2 lines to include lirc module
lirc_rpi gpio_in_pin=18 gpio_out_pin=23

I then rebooted and checked the module was working with

Code: Select all

ls -l /dev/lir*
This was my result
crw-rw---T 1 root video 250, 0 Dec 22 21:52 /dev/lirc0

I then restared lirc (just to check it stop and start)

Code: Select all

/etc/init.d/lirc restart

Code: Select all

dmesg | grep lirc

Now test a remote control and your module

Code: Select all

sudo mode2 -d /dev/lirc0
aim a remote and press buttons
You should get some output like this

pulse 591
space 540
pulse 569
space 550
pulse 606
space 1648
pulse 629

Now you know the module is working.

To program a remote you can use
The following command to list the available names

Code: Select all

irrecord --list-namespace 
and to record a remote control

Code: Select all

sudo irrecord -d /dev/lirc0 -f /etc/lirc/own_remote.conf
Once you have your own_remote.conf created you will need this for openelec

Copy own_remote.conf to use later

Now for Openelec
Swap your SD card to your openelec image,
First thing, use the latest Openelec which has lirc already built in.

SSH into openelec
Default username root password is openelec

Next add the module, now since the modules file is mounted on a read only file system, we will use modprobe to modify openelc to load the lirc module using a autostart file
Create the file and set the permissions of the file to execute

Code: Select all

touch /storage/.config/
chmod +x /storage/.config/
Next (using vi)

Code: Select all

vi /storage/.config/
Press i to insert,
type the following (there might be a better way, ?? someone help??)

Code: Select all

#!/no /storage/.config/autostart.shbin/sh
(modprobe lirc_rpi;)&
Then press escape :wq! (to write and quit)
Now copy own_remote.conf (that you created earlier) to

Mine looked like this

Code: Select all

cat lircd.conf
begin remote

  name devinput
  bits           16
  eps            30
  aeps          100

  header       4540  4521
  one           569  1681
  zero          569   556
  ptrail        569
  pre_data_bits   16
  pre_data       0xE0E0
  gap          108475
  toggle_bit_mask 0x0

      begin codes
          KEY_Left                     0xA659
          KEY_Right                    0x46B9
          KEY_Up                       0x06F9
          KEY_Down                     0x8679
          KEY_Ok                       0x16E9
          KEY_1                    0x20DF
          KEY_2                        0xA05F
          KEY_3                        0x609F
          KEY_4                        0x10EF
          KEY_5                        0x906F
          KEY_6                        0x50AF
          KEY_7                        0x30CF
          KEY_8                        0xB04F
          KEY_9                        0x708F
          KEY_0                        0x8877
          KEY_MENU                     0x58A7
          KEY_FORWARD                       0x12ED
          KEY_REWIND                      0xA25D
          KEY_Play                     0xE21D
          KEY_Stop                     0x629D
          KEY_Record                   0x926D
          KEY_VOLUMEUP                     0xE01F
          KEY_VOLUMEDOWN                     0xD02F
          KEY_INFO                     0xF807
          KEY_POWER                0x40BF
          KEY_MUTE                     0xE0E0F00F
          KEY_Pause                    0x52AD
          KEY_VIDEO                    0x36C9
          KEY_AUDIO                    0x28D7
          KEY_EXIT                     0xE0E01AE5
          KEY_CLOSE                    0xE0E01AE5
          Photo                    0xA857
   end codes
Create a xml mapping file to map your keys to XBMC keys
This file is kept in /storage/.xbmc/userdata/lircmap.xml


Code: Select all

cat /storage/.xbmc/userdata/lircmap.xml
<remote device="devinput">
To test within SSH use

Code: Select all

Aim your remote and test

And to record directly in openelec
First make sure no other process is using the driver to check

Code: Select all

ps ax | grep lirc 
Look for the process ID that is running lirc then kill it
EG kill 1102

Then you can record (remember the namespaces)

Code: Select all

irrecord --list-namespace
And to record

Code: Select all

 irrecord -d /dev/lirc0 /storage/.config/MY_lircd.conf 
Look there’s probably 100’s of things I’ve left out, this is how I have it running
Hope it helps someone :-)

Posts: 3
Joined: Mon Dec 10, 2012 1:31 pm

Re: IR Receiver & OpenElec

Fri Jan 11, 2013 5:28 am

Works like a charm!


User avatar
Posts: 65
Joined: Fri May 25, 2012 5:33 am

Re: IR Receiver & OpenElec

Mon Jan 14, 2013 5:37 pm

Just an update to the
mine looks like this

Code: Select all

root ~/.config # cat
(modprobe lirc_rpi;)&

Posts: 14
Joined: Tue Nov 29, 2011 6:44 pm

Re: IR Receiver & OpenElec

Mon Jan 14, 2013 8:31 pm

Very clear and easy to follow guide, thanks for taking the time.

Posts: 1
Joined: Tue Apr 23, 2013 1:52 pm

Re: IR Receiver & OpenElec

Tue Apr 23, 2013 1:55 pm

Thanks Riccardo!

Posts: 1
Joined: Tue Dec 10, 2013 3:47 am

Re: IR Receiver & OpenElec

Tue Dec 10, 2013 4:07 am

BeFunky_IMG_20131209_215640.jpg.jpg (51.75 KiB) Viewed 24826 times
Hi, Thank you for this wonderful tutorial.
I am a new user of Raspberry pi and linux. I am using this for my school project. I tried your code and I had a couple of questions regarding it:
1) the receiver is not reading the signal. when i disconnect the receiver from the circuit, there is a long cascade of pulses and spaces without any input at all. I will attach my circuit here.
2) I did get the receiver to read a couple of pulses a few times. However, I don't know how to terminate/get out of the program after it. For eg: how do I get the $ sign back to type the commands?

I am working in the LXTerminal and I tried just closeing it but when I restart it and try restarting lirc, it just says that it is busy/ being used.

Any help will be greatly appreciated.

Return to “Media centres”