How To: Configure Any Remote Control With LIRC

 

My LIRC / remote control adventures continue (see the two previous posts). I bought a StreamZap, and configured a .lircrc file to control Banshee, the mouse pointer, and the screensaver on my computer, to allow listening of music from across the room.

I had for some reason blindly assumed that the IR receiver that came with the StreamZap was specialized – but lying in bed last night I realized that it should of course work with any remote that I care to click at it. And, indeed, that’s the case. To prevent remote control proliferation in your house, therefore, you could just buy a USB IR Receiver, and configure an existing remote control to work with LIRC. Alternatively you may wish to configure multiple remote controls to work with your PC; e.g. one could control Mplayer, one could control Banshee, etc (I have not yet found a way to switch command configurations without switching remotes.)

The following HowTo assumes that you are using Ubuntu, although should be more or less applicable to other distributions.

Recording The Remote

First, you need to shut down lirc, since it maintains an exclusive lock on the the IR device (typically /dev/lirc0); to do this, simply run sudo /etc/init.d/lirc stop.

Now, make sure that the remote that you’re going to record actually sends intelligible signals to the receiver. Run sudo mode2 -d /dev/lirc0, press some buttons, and ensure that you see some events streaming by.

Once that’s set, it’s time to create a new lirc.conf for the remote. In one terminal, enter irrecord --list-namespace | less to see the list of standardized button codes; not all lirc configurations out there use these, but standardization is benefecial, as it makes lircrc mappings more shareable. In a second terminal, enter sudo irrecord -d /dev/lirc0 lirc.conf.myremote, where myremote is whatever arbitrary name you like. (By the way, I’m assuming that you’ve checked the already available configurations; no sense in repeating somebody’s good work.) irrecord functions as a wizard, walking you through mapping each of the buttons on the remote; in the initial phase where it asks you to complete two rows of dots, it doesn’t matter too much which buttons you press, in which order, or how often – it just wants to get a range of values from your remote.

Completing the Configuration

Once you have your configuration, create a new directory for it (/usr/share/lirc/remotes/myremote) and move your configuration there. You may wish to edit the configuration to fix the name value, but otherwise it should be good to go. Finally, edit /etc/lirc/lircd.conf, and add an include line pointing at your new configuration, e.g. include "/usr/share/lirc/remotes/myremote/lirc.conf.myremote", and then restart lirc (/etc/init.d/lirc start).

Now when you run irw, you’ll see named remote/button events when you press the buttons on your new remote. You can also press buttons on any other remote that is configured, and see the unique remote/button events for that. Refer to my previous How Tos for steps on mapping these to commands on your PC.

Finally, don’t forget to contribute your configuration to the lirc maintainers.