Controlling your Pi with an infrared remote
Installing LIRC
LIRC (Linux Infrared Remote Control [5]) is a software package for Linux, which, according to the developers "…allows you to decode and send infra-red signals of many (but not all) commonly used remote controls." LIRC was originally developed in 1999 and has been continually maintained since, so it is a very mature and stable implementation. Until recently, the LIRC package required a fairly difficult and lengthy process for compiling and installing on the Raspberry Pi. However, thanks to the efforts of an extremely talented community member, Aron Szabo, Raspbian now supports LIRC in the default configuration (and this support is also included in Raspbian derivatives, such as Raspbmc).
In Raspbmc, the LIRC module should already be installed by default, so if you are using an up-to-date version of Raspbmc, you can skip straight to the "Testing LIRC" section below. To begin, open an LXterminal instance (or SSH into your Raspberry Pi) and make sure your operating system is up to date by typing the following commands:
sudo apt-get update sudo apt-get upgrade
These commands may take a few minutes to complete, especially if you have not updated in a while. Once you have updated the OS, you will need to install LIRC and the required dependencies using:
sudo apt-get install lirc liblircclient-dev
You will then have the option to install the new packages; click Y to continue with the installation. Once the installation completes, you might get some warning messages saying No valid /etc/lirc/lircd.conf has been found or something similar; however, you can ignore these messages for now.
The next step is to set up the hardware config file. You should only need to do this if you are running Raspbian. Raspbmc should already have its hardware configuration file set up correctly. To set up the config file, use SSH or a terminal session and enter:
sudo nano /etc/lirc/hardware.conf
This command should open the hardware configuration file with the nano text editor. You then need to edit the contents of this file so that it looks exactly like the file shown in Listing 1.
Listing 1
/etc/lirc/hardware.conf
¤¤nonumber # # 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=""
Once you have edited the config file, press Ctrl-X and then Y to close and save the file. On Raspbmc, the LIRC module is preset to load automatically on boot. If you are running a standard version of Raspbian and you want LIRC to start automatically on boot, enter the following command:
sudo nano /etc/modules
This command will load the modules
file (which lists the kernel modules to load at boot time) using the nano text editor. You then need to add the following lines at the bottom of the file:
lirc_dev lirc_rpi gpio_in_pin=18
You can then close the file by typing Ctrl-X and save it by pressing Y. You now have a fully configured and working circuit and LIRC implementation, so you are now ready to test everything out.
Testing LIRC
If you are using Raspbmc, this configuration process will be a lot easier if you are able to log in to your Raspberry Pi with SSH [6]. Further help on achieving a secure SSH setup is available on the RasPi.TV website [7].
Before you test the IR receiver using SSH on Raspbmc, you first need to disable the in-built IR receiver function to allow you to receive the raw IR pulse output through an SSH session. You can do this by visiting the Raspbmc Settings menu, clicking on the IR Remote tab (as shown in Figure 6), and then making sure Enable GPIO TSOP IR Receiver is unchecked.
If the option was already unchecked, you are ready to go. If, however, you had to change the setting, you will need to save the changes and then restart the Raspberry Pi with the command:
sudo reboot
or
sudo shutdown -r now
To begin testing, open an SSH or a terminal session. If you are on a standard version of Raspbian, you can easily open a session with either LXterminal or SSH. If you are on Raspbmc, you will need to start SSH and then type the following commands:
sudo modprobe lirc_rpi sudo /etc/init.d/lirc stop sudo mode2 -d /dev/lirc0
Once you have entered those commands, point your IR remote at the receiver and press a few buttons. You will see output similar to Listing 2.
Listing 2
IR Remote Output
¤¤nonumber space 16300 pulse 95 space 28794 pulse 80 space 19395 pulse 83 space 402351 pulse 135 space 7085 pulse 85 space 2903
If you see this output, then you have set up everything correctly, and you are ready to start tailoring the LIRC installation to your remote.
Buy this article as PDF
Pages: 8
(incl. VAT)