This page contains some information about Linux Infrared Remote Control (LIRC) and how to set it up with PiFace CAD and the Raspberry Pi.

LIRC looks something like this:

An image of PiFace Digital with a simple circuit connected.

Setting up the Infrared Receiver

Download and run the setup script:

$ wget
$ chmod +x
$ sudo ./

Alternatively you can set up the receiver manually.


The following instructions are for a manual set up of the above script. If you have run the script above, you can skip straight to Configuring LIRC.

First, install lirc:

$ sudo apt-get install lirc

The latest version of Raspbian should contain the lirc_rpi kernel module. It allows you to specify which GPIO pin the Infrared Receiver is attached to. On PiFace CAD, the Infrared Receiver is connected to GPIO pin 23. To load the module type:

$ sudo modprobe lirc_rpi gpio_in_pin=23

You can test that it works with the mode2 program:

$ sudo kill $(pidof lirc)  # stop lirc using /dev/lirc0
$ mode2 -d /dev/lirc0

If, after pressing some buttons, you get a series of pulse/space lengths then your Infrared Receiver is working. To make sure that the module is loaded each time you boot, add the following lines to /etc/modules:

lirc_rpi gpio_in_pin=23

Update /etc/lirc/hardware.conf to contain the following:

# /etc/lirc/hardware.conf
# Arguments which will be used when launching lircd

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

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

#Try to load appropriate kernel modules

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

# Default configuration files for your hardware if any

Finally, reboot your Rasbperry Pi:

$ sudo reboot

Configuring LIRC

See also:


The /etc/lirc/lircd.conf file tells LIRC about your remote control. Since every remote control is different, you need to generate a different config for each remote. Alternatively you could try and find your remote control config file here:

To generate your own configuration run:

$ sudo irrecord -f -d /dev/lirc0 /etc/lirc/lircd.conf

and carefully follow the on-screen instructions. At some point it will ask you to enter the commands for each button you press. You can list the available commands (in another terminal) with:

$ irrecord --list-namespace

After you have finished, restart the lirc daemon (or reboot) and test your remote by running:

$ irw

Your commands should appear in the console.

~/.lircrc (or /etc/lirc/lircrc)

The ~/.lircrc file is used to configure what other programs see from LIRC. See examples in irexec and python-lirc.

See also:


irexec is a program that runs commands mapped to IR signals. It is configured using the ~/.lircrc file.

Simple ~/.lircrc:

    prog = irexec
    button = KEY_1
    config = echo "You pressed one"
    repeat = 0

Now when you run irexec and press 1 on the remote control You pressed one will be printed to the console:

$ irexec
You pressed one
You pressed one
You pressed one

Here is another example that uses mpc to control Music Player Daemon:

    prog = irexec
    config = mpc prev
    repeat = 0
    prog = irexec
    button = KEY_NEXTSONG
    config = mpc next
    repeat = 0
    prog = irexec
    button = KEY_PLAY
    config = mpc play
    repeat = 1


python-lirc is a Python extension that allows us to access configs in ~/.lircrc when LIRC receives a signal.

First we need to add more configurations to our ~/.lircrc:

    prog = irexec
    button = KEY_1
    config = echo "You pressed one"
    repeat = 0

  prog = myprogram
  button = KEY_1
  config = one

  prog = myprogram
  button = KEY_1
  config = two

Then we can wait for IR codes in Python:

$ python3
>>> import lirc
>>> sockid = lirc.init("myprogram")
>>> lirc.nextcode()  # press 1 on remote after this
>>> lirc.nextcode()  # press 2 on remote after this

PiFace CAD

PiFace Control and Display provides a wrapper around python-lirc. An example of how to use it can be found in Examples.

Table Of Contents

Previous topic


Next topic

Reference (PiFace CAD)

This Page