User avatar
RiccardoMoretti
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
http://www.vishay.com/docs/81745/tsop312.pdf

Connectivity:
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
Image

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_dev
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
Image

Code: Select all

dmesg | grep lirc
Image

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/autostart.sh
chmod +x /storage/.config/autostart.sh
Next (using vi)

Code: Select all

vi /storage/.config/autostart.sh
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
/storage/.config/lircd.conf

Mine looked like this

Code: Select all

cat lircd.conf
begin remote

  name devinput
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  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
Next
Create a xml mapping file to map your keys to XBMC keys
This file is kept in /storage/.xbmc/userdata/lircmap.xml

The syntax is <XBMC_FUNCTION>REMOTE_FUNCTION</XBMC_FUNCTION>

Code: Select all

cat /storage/.xbmc/userdata/lircmap.xml
<lircmap>
<remote device="devinput">
<left>KEY_LEFT</left>
<right>KEY_RIGHT</right>
<up>KEY_UP</up>
<down>KEY_DOWN</down>
<select>KEY_OK</select>
<display>KEY_MENU</display>
<back>KEY_BACK</back>
<back>KEY_ESC</back>
<back>KEY_EXIT</back>
<back>KEY_CLOSE</back>
<record>KEY_RECORD</record>
<play>KEY_PLAY</play>
<pause>KEY_PAUSE</pause>
<stop>KEY_STOP</stop>
<forward>KEY_FORWARD</forward>
<reverse>KEY_REWIND</reverse>
<volumeplus>KEY_VOLUMEUP</volumeplus>
<volumeminus>KEY_VOLUMEDOWN</volumeminus>
<pageplus>KEY_CHANNELUP</pageplus>
<pageminus>KEY_CHANNELDOWN</pageminus>
<skipplus>KEY_NEXT</skipplus>
<skipminus>KEY_AGAIN</skipminus>
<mute>KEY_MUTE</mute>
<power>KEY_POWER</power>
<myvideo>KEY_VIDEO</myvideo>
<mymusic>KEY_AUDIO</mymusic>
<mytv>LiveTV</mytv>
<one>KEY_1</one>
<two>KEY_2</two>
<three>KEY_3</three>
<four>KEY_4</four>
<five>KEY_5</five>
<six>KEY_6</six>
<seven>KEY_7</seven>
<eight>KEY_8</eight>
<nine>KEY_9</nine>
<zero>KEY_0</zero>
<red>KEY_RED</red>
<green>KEY_GREEN</green>
<yellow>KEY_YELLOW</yellow>
<blue>KEY_BLUE</blue>
<menu>KEY_DVD</menu>
<clear>KEY_CLEAR</clear>
<enter>KEY_ENTER</enter>
</remote>
</lircmap>
To test within SSH use

Code: Select all

irw
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 :-)

Dasgood
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!

Thanks

User avatar
RiccardoMoretti
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 autostart.sh
mine looks like this

Code: Select all

root ~/.config # cat autostart.sh
#!/bin/sh
(modprobe lirc_rpi;)&


GilchristT
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.

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

Re: IR Receiver & OpenElec

Tue Apr 23, 2013 1:55 pm

Thanks Riccardo!

Rpi_user91
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
Circuit
BeFunky_IMG_20131209_215640.jpg.jpg (51.75 KiB) Viewed 24312 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”