Vero is OSMC's new flagship device. Find out more here.

Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LIRC GPIO driver with Raspbmc
08-18-2012, 01:55 AM
Post: #1
LIRC GPIO driver with Raspbmc
I got Raspbmc working with the Raspberry Pi LIRC GPIO driver, but the process was a bit different that what I've seen documented elsewhere, so I thought I'd document it.

First off, when I ordered my Raspberry Pi from I also picked up a TSOP4838 IR receiver (Newark SKU 60K6999). The RPi LIRC GPIO driver page has some information about how to install it, and the Embedded Linux Wiki section on General Purpose Input/Output (GPIO) on the RPi has a diagram which shows what pin is what. Basically pin 1 on the receiver goes to GPIO18 (which is pin 12 on the RPi), pin 2 goes to ground (pin 6 on the RPi), and pin 3 goes to 3.3V (pin 1). Here is a picture of mine:

[Image: scaled.php?server=88&filename=img201...es=landing]

Once you have the receiver in place, go ahead and boot the RPi. Then, as root, run

Code:
modprobe lirc_rpi
mode2 -d /dev/lirc0

When you push buttons on an IR remote, you should see several lines with starting with either "pulse" or "space", then a number. If you don't, you probably connected the IR receiver incorrectly (hopefully you didn't damage the receiver or, even worse, the RPi).

Assuming you're getting a signal from the remote, it's time to start configuring LIRC. The Debian LIRC package provides a configuration file, /etc/lirc/hardware.conf that we'll be using to make sure the kernel module gets loaded and the right arguments get passed to lircd. Here is a copy of mine:

Code:
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"

#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD=false

#Don't start irexec, even if a good config file seems to exist.
#START_IREXEC=false

#Try to load appropriate kernel modules
LOAD_MODULES=true

# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"

# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""

This will cause the lirc init script (/etc/init.d/lirc) to automatically insert the relevant kernel module (lirc_rpi), and launch lircd with the correct arguments (--driver=default --device=/dev/lirc0 --uinput) every time the RPi boots. If you've been playing around you may want to `reboot` your RPi, otherwise you can just restart the lirc service:

Code:
/etc/init.d/lirc restart

At this point, go ahead and run `irw` and push some buttons on the remote. If you're lucky the remote may already be configured correctly and you can skip this next bit. I don't know about you, but I'm not that lucky, so...

To configure the remote, go ahead and stop lirc and use the irrecord command to generate a configuration file:

Code:
/etc/init.d/lirc stop
irrecord -d /dev/lirc0 ~/lirc.conf

You can get a list of valid button names by running

Code:
irrecord --list-namespace

I just piped that list to grep and guessed names to figure out what to call mine:

Code:
irrecord --list-namespace | grep -i play

Once you're done, go ahead and copy that file over to /etc/lirc/lircd.conf (remember to make a back-up of /etc/lirc/lircd.conf first!).

I'm using an old remote from a Roku, which only has a few buttons, so here is what mine looks like (without the comments at the beginning of the file):

Code:
begin remote

  name  roku
  bits           16
  flags SPACE_ENC|CONST_LENGTH
  eps            30
  aeps          100

  header       9019  4475
  one           636  1597
  zero          636   480
  ptrail        636
  pre_data_bits   16
  pre_data       0x5743
  gap          106385
  toggle_bit_mask 0x0

      begin codes
          KEY_HOME                 0xC03F 0xC13E
          KEY_BACK                 0x6699 0x6798
          KEY_SELECT               0x54AB 0x55AA
          KEY_LEFT                 0x7887 0x7986
          KEY_RIGHT                0xB44B 0xB54A
          KEY_UP                   0x9867 0x9966
          KEY_DOWN                 0xCC33 0xCD32
          KEY_REFRESH              0x1EE1 0x1FE0
          KEY_FASTFORWARD          0xAA55
          KEY_REWIND               0x2CD3 0x2DD2
          KEY_PLAYPAUSE            0x32CD 0x33CC
          KEY_INFO                 0x8679
      end codes

end remote

Notice that third line ("name roku"). You'll want to set yours to something sensible for your system (it will be something like ~/lircd.conf by default).

At this point, go ahead and restart your RPi (just run `reboot`). I say this because for some reason, at this point when I just started the lirc service (`/etc/init.d/lirc start`) eventlircd wasn't getting involved yet, but after a reboot it did. If someone using this post to set up their RPi could just start the lirc service without rebooting and check to see if eventlircd is working (just run `irw` and some buttons on your remote--the end of each line shows the source. If eventlircd is working it will be devinput, otherwise it will be the name of your remote) and post the result, I can simplify this a bit for future readers.

Now it's time to configure XBMC--specifically, adding a /home/pi/.xbmc/userdata/Lircmap.xml file. Again, since my remote only has a few buttons mine is pretty small:

Code:
<lircmap>
  <remote device="devinput">
    <back>KEY_BACK</back>
    <menu>KEY_HOME</menu>
    <up>KEY_UP</up>
    <left>KEY_LEFT</left>
    <select>KEY_SELECT</select>
    <right>KEY_RIGHT</right>
    <down>KEY_DOWN</down>
    <stop>KEY_REFRESH</stop>
    <info>KEY_INFO</info>
    <skipminus>KEY_REWIND</skipminus>
    <play>KEY_PLAYPAUSE</play>
    <skipplus>KEY_FASTFORWARD</skipplus>
  </remote>
</lircmap>

A "stop" button is much more useful to me than a "refresh" button, so I ended up re-purposing that button, but everything else is pretty straightforward.

The only other thing to note is the device attribute on the remote element. If eventlircd is running, you'll want it to be "devinput" (like mine is). If not, it should match the remote name we used earlier ("roku" for mine).
Find all posts by this user
Quote this message in a reply
08-18-2012, 03:06 AM
Post: #2
RE: LIRC GPIO driver with Raspbmc
Or you could do it this way http://forum.stmlabs.com/showthread.php?...6#pid15856

Pi problems?? Start here http://forum.stmlabs.com/showthread.php?tid=3918
http://elinux.org/R-Pi_Troubleshooting
http://elinux.org/RPi_config.txt
Find all posts by this user
Quote this message in a reply
08-25-2012, 04:22 PM
Post: #3
RE: LIRC GPIO driver with Raspbmc
Excellent tutorial nemequ!
Works perfectly with an IR receiver I removed from an XBOX 1 dongle. Only programmed 3 buttons so far but I will go through and do them all now Smile

One problem though is it seems to receive all button presses 2 or 3 times unless you press really quick. So a normal button press is no good. Is there anywhere to configure repeat delays or something?
Also, LIRC doesn't seem to start correctly. The remote doesn't work until it issue "/etc/init.d/lirc restart" it then says it fails to stop lirc and then successfully starts it. I guess Lirc is not running to start with? Are there some permissions I need to set on /etc/lirc/hardware.conf ?

Lastly, my IR reciever is hooked up via 5v GPIO pin and from what I can tell, is outputting 5v pack to GPIO18. Is this a problem? I read that GPIO are only 3.3v, but it seems to work, but am i damaging my pi? Can I put a resistor in there somewhere to drop the voltage?
Find all posts by this user
Quote this message in a reply
08-25-2012, 04:44 PM (This post was last modified: 08-25-2012 04:45 PM by Dilligaf.)
Post: #4
RE: LIRC GPIO driver with Raspbmc
(08-25-2012 04:22 PM)nadnerb Wrote:  Excellent tutorial nemequ!
Works perfectly with an IR receiver I removed from an XBOX 1 dongle. Only programmed 3 buttons so far but I will go through and do them all now Smile

One problem though is it seems to receive all button presses 2 or 3 times unless you press really quick. So a normal button press is no good. Is there anywhere to configure repeat delays or something?
Also, LIRC doesn't seem to start correctly. The remote doesn't work until it issue "/etc/init.d/lirc restart" it then says it fails to stop lirc and then successfully starts it. I guess Lirc is not running to start with? Are there some permissions I need to set on /etc/lirc/hardware.conf ?

Lastly, my IR reciever is hooked up via 5v GPIO pin and from what I can tell, is outputting 5v pack to GPIO18. Is this a problem? I read that GPIO are only 3.3v, but it seems to work, but am i damaging my pi? Can I put a resistor in there somewhere to drop the voltage?
They stress that the gpio isn't 5V tolerant, try moving your power to pin 1 the 3.3V pin and see if it still works, otherwise resistors may help, a tsop34138 receiver is only $1.25 and it works on 3.3V, I know the shipping can often be 4X as much.

Pi problems?? Start here http://forum.stmlabs.com/showthread.php?tid=3918
http://elinux.org/R-Pi_Troubleshooting
http://elinux.org/RPi_config.txt
Find all posts by this user
Quote this message in a reply
08-25-2012, 09:24 PM (This post was last modified: 08-25-2012 11:51 PM by nadnerb.)
Post: #5
RE: LIRC GPIO driver with Raspbmc
Doesn't work with 3.3v supply.
I tested it first with a 5v USB supply using this guide:
http://learn.adafruit.com/ir-sensor/test...-ir-sensor

The LED lit when I pressed buttons on the remote and the voltage between Vout on the TSOP and ground was about 1.5v
Put when set up on the pi, the voltage between GPIO18 and GND was about 4.8v :/

Could I use the LED as a resistor to drop the voltage between leaving the TSOP and entering GPIO18 with the added bonus of having it light up with a button press? Or is that not how it would work?

But yes, I could just buy a tsop34138 (theres one on ebay UK, free shipping) but I'm not 100% it would work with my xbox remote. No idea what spec TSOP i have now, besides being 5v
Find all posts by this user
Quote this message in a reply
09-12-2012, 02:15 PM
Post: #6
RE: LIRC GPIO driver with Raspbmc
I just can't get it to work in xbmc.

I run the irw command and get like:
0random number58 00 UP samsung
0random number58 01 UP samsung
and so on when i press the buttons.

in xbmc I've changed so that remotes is supported

the remote.xml file is done accordingly to the guide

What could have gone wrong?
have had the same result in both RC3 and RC4
Find all posts by this user
Quote this message in a reply
09-12-2012, 04:39 PM
Post: #7
RE: LIRC GPIO driver with Raspbmc
Thanks for this useful post. Followed your instructions to the letter.
Worked like a charm using a TSOP4838 from EBay ($2.50 shipped) on the +3.3v rail.

(08-18-2012 01:55 AM)nemequ Wrote:  I got Raspbmc working with the Raspberry Pi LIRC GPIO driver, but the process was a bit different that what I've seen documented elsewhere, so I thought I'd document it.
Find all posts by this user
Quote this message in a reply
09-12-2012, 07:29 PM
Post: #8
RE: LIRC GPIO driver with Raspbmc
props for this!

just ordered so will try it out in a couple of weeks when the sensor makes it over from thailand lol.

I was looking for a way to integrate the IR more than it is currently so this should be perfect.
Find all posts by this user
Quote this message in a reply
09-12-2012, 08:21 PM
Post: #9
RE: LIRC GPIO driver with Raspbmc
I f*ckd up

for others that may miss this

change the default in harware.conf
DRIVER="default"
to whatever you named your device in
lircd.conf

begin remote
name blabla
Find all posts by this user
Quote this message in a reply
09-18-2012, 03:22 PM (This post was last modified: 09-18-2012 03:24 PM by N3m3515.)
Post: #10
RE: LIRC GPIO driver with Raspbmc
hello. i followed your tutorial to configure my raspbmc.

i used a tsop1138 hooked up to the gpio pins. everything worked good but xbmc only recognises my remote control when i :

Code:
sudo /etc/init.d/lirc restart
sudo initctl restart xbmc

i found someone with the same problem over here:

http://forum.stmlabs.com/showthread.php?tid=737&page=4

but i cant get it to work with the informations in the thread. anyone with a solution?

i am using my old playstation 2 remote as it has a good button layout for raspbmc.

i would be happy if someone could give a a howto to make a startup script that restarts lircd and xbmc after startup when there is no other solution for my problem.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Sponsored Advertisement