Controlling your Pi with an infrared remote
Configuring the Remote
You will need to create a file called /etc/lirc/lircd.conf
that contains the remote control configuration information. I will start by configuring LIRC to work with the optional IR remote listed in the "Parts List" box. Be sure you are in the home directory, then create a configuration file using the nano text editor by typing the following commands:
cd ~ sudo nano lircd.conf
You can then type in or copy/paste the code shown in Listing 3. Next, close and save this file by pressing Ctrl-X and then Y.
Listing 3
/etc/lirc/lircd.conf
01 # Please make this file available to others 02 # by sending it to <lirc@bartelmus.de> 03 # 04 # this config file was automatically generated 05 # using lirc-0.9.0-pre1(default) on Tue Oct 8 07:05:38 2013 06 # 07 # contributed by 08 # 09 # brand: /home/pi/lircd.conf 10 # model no. of remote control: 11 # devices being controlled by this remote: 12 # 13 14 begin remote 15 16 name /home/pi/lircd.conf 17 bits 16 18 flags SPACE_ENC|CONST_LENGTH 19 eps 30 20 aeps 100 21 22 header 9006 4447 23 one 594 1648 24 zero 594 526 25 ptrail 587 26 repeat 9006 2210 27 pre_data_bits 16 28 pre_data 0xFD 29 gap 107633 30 toggle_bit_mask 0x0 31 32 begin codes 33 KEY_1 0x08F7 34 KEY_2 0x8877 35 KEY_3 0x48B7 36 KEY_4 0x28D7 37 KEY_5 0xA857 38 KEY_6 0x6897 39 KEY_7 0x18E7 40 KEY_8 0x9867 41 KEY_9 0x58A7 42 KEY_0 0x30CF 43 KEY_DOWN 0xB04F 44 KEY_LEFT 0x10EF 45 KEY_UP 0xA05F 46 KEY_RIGHT 0x50AF 47 KEY_BACK 0x708F 48 KEY_ENTER 0x906F 49 KEY_SETUP 0x20DF 50 KEY_PAUSE 0x609F 51 KEY_PAUSE 0x807F 52 KEY_STOP 0x609F 53 KEY_VOLUMEUP 0x40BF 54 KEY_VOLUMEDOWN 0x00FF 55 end codes 56 57 end remote
If you are using Raspbmc, you are done configuring the remote, because Raspbmc is set up to pull in a configuration file stored in the /home/pi
folder. However, on Raspbmc, you then need to return to the IR receiver menu in the settings and re-enable the Enable GPIO TSOP IR Receiver option (Figure 7). The GPIO IR Remote Profile also needs to point to the custom file you just set up.
Once you have changed these two settings, you can then save the settings and restart the Raspberry Pi.
When the system restarts, you should receive a pop-up in the bottom right-hand corner of the screen saying Detected New Connection – Starting LIRC, and you should now have a fully working IR remote with Raspbmc!
If you are using Raspbian, you will instead need to enter a couple more commands. First, move the configuration file into its correct location:
sudo mv /home/pi/lircd.conf /etc/lirc/lircd.conf
Then, restart LIRC:
sudo /etc/init.d/lirc restart
You should now have a fully working remote with Raspbian!
Using an Existing Remote
The LIRC SourceForge page already has ready-made configuration files for a huge number of remote controls [8]. For example, the SourceForge archive contains files for my Sony RM-ED009 remote and my SkyHD remote.
If a configuration file for your remote is available at SourceForge, you can still follow the instructions in the preceding "Configuring the Remote" section. But, instead of copying the contents of Listing 3, you can just copy/paste the code found at SourceForge.
If you are unable to find a ready-made configuration file for your remote, that does not mean the remote is not supported by the software, just that no one has contributed a configuration file for it. One of the main benefits of the LIRC software is that it can "learn" remotes – meaning you can easily configure your own remote to be used with the software.
To begin this learning process, you first need to have completed the steps in the previous "Testing LIRC" section. You can then use the irrecord
function, which is built into LIRC, to record the outputs of the new remote.
When you run irrecord
, it will ask you to name each button as you "teach" it to LIRC; a predefined list of valid names is available, which you can find by running the following command:
irrecord --list-namespace
It is worth noting down the available button names, or copying and pasting them to a text file to refer to later. When you are ready, you can initiate the irrecord
function using the following command:
irrecord -d /dev/lirc0 ~/lircd.conf
When using the irrecord
command, make sure you follow the instructions very carefully. If you make any mistakes, you can always start again, but it takes a fair bit of time, so it is worth getting right the first time. If you want to keep the configuration file for the old remote, make a backup using the following command:
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf
Once you have a backup, it is then very easy to copy the new file with the irrecord
function back to the directory it needs to be in. If you are using Raspbmc, you can just leave the config file where it is and skip this step. To copy the file, issue the following command:
sudo cp ~/lircd.conf /etc/lirc/lircd.conf
If you are using Raspbmc, you will need to return to the Settings menu and tick the Enable GPIO TSOP IR Receiver option, as well as selecting the custom configuration file from the list (see the end of the previous "Configuring the Remote" section for a more detailed description).
You can then restart the system using the following command:
sudo reboot (or sudo shutdown -r now)
If you are using Raspbian, you can just restart LIRC without rebooting, using the following command:
sudo /etc/init.d/lirc start
You should now have a fully configured remote.
If you could not find your remote listed in the repository and had to generate your own configuration file, please help to support the LIRC community by sending the model number of your remote, the configuration file, and preferably a picture of the specific remote to lirc@bartelmus.de. This will allow your file to become part of the configuration file repository.
Buy this article as PDF
Pages: 8
(incl. VAT)