7

Im trying to get my Pi to take input from an IR remote using lirc. But it is not working. Ive tried a few different tutorials like this one that basically did the same thing.

One problem here is the the Pi couldnt find /etc/init.d/lirc, so i could not stop it. The test (mode2 -d /dev/lirc0) also fails, it does not tell me anything.

Under /boot/config.txt I have

dtoverlay=lirc-rpi,gpio_in_pin=17

hardware.conf is

# /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"

Also the wiring is like this enter image description here

1

1 Answer 1

11

Update 2019-06-14:
Please note that the infrared device has recently changed from lirc-rpi to gpio-ir. As confirmed by @Pascal in his comment the setup also works with the new device name.


Here is how I got it to work. First of all: I use the latest Raspbian Stretch Lite 2018-03-13. With this version there is no /etc/lirc/hardware.conf anymore if you install lirc. You should also use up to date versions.

In /boot/config.txt enable the infrared device. GPIO 17 out and GPIO 18 in are default and you can omit their settings. I have added them if you use other pins. You can find the settings in /boot/overlays/README.

# Uncomment this to enable the gpio-ir module
dtoverlay=gpio-ir,gpio_out_pin=17,gpio_in_pin=18,gpio_in_pull=up

# Or still using the old version uncomment this to enable the lirc-rpi module
dtoverlay=lirc-rpi,gpio_out_pin=17,gpio_in_pin=18,gpio_in_pull=up

Install lirc:

rpi3 ~$ sudo apt update
rpi3 ~$ sudo apt install lirc

Edit /etc/lirc/lirc_options.conf and change this settings to:

driver = default
device = /dev/lirc0

Now

rpi3 ~$ sudo systemctl reboot

After login you should have a lirc0 device and see something like:

rpi3 ~$ ls -l /dev/lirc0
crw-rw---- 1 root video 244, 0 2018-01-28 16:58 /dev/lirc0
rpi3 ~$ lsmod | grep lirc
lirc_rpi                9032  3
lirc_dev               10583  1 lirc_rpi
rc_core                24377  1 lirc_dev

Check services with:

rpi3 ~$ systemctl status lircd.service
rpi3 ~$ systemctl status lircd.socket

Now you can test if you get signals. Start mode2 and push some buttons on your remote control. mode2 should show you very low level info in space and pulse:

rpi3 ~$ sudo systemctl stop lircd.service
rpi3 ~$ sudo systemctl stop lircd socket
rpi3 ~$ sudo mode2 --driver default --device /dev/lirc0

If everything is OK to this, we can start lirc again:

rpi3 ~$ sudo systemctl start lircd socket
rpi3 ~$ sudo systemctl start lircd.service

Now we need a configuration file that maps the lirc pulses to the buttons of your remote control. On the internet there is a database with many config files for remote controls. the config file for my remote control I have found there. If you cannot find yours you have to training your remote control by yourself with:

rpi3 ~$ sudo irrecord -n -d /dev/lirc0 ~/lircd.conf

That's your exercise ;-) Haven't tested it. If you have your config file move it to
/etc/lirc/lircd.conf.d/
and restart lirc to load this file:

rpi3 ~$ sudo systemctl restart lircd

Now we can look if we get the pushed buttons. Start irw and push buttons on your remote control. You should get something like:

rpi3 ~$ irw
0000000000002422 00 KEY_VOLUMEUP Sony_RMT-CS33AD
0000000000002422 01 KEY_VOLUMEUP Sony_RMT-CS33AD
0000000000002422 02 KEY_VOLUMEUP Sony_RMT-CS33AD
0000000000006422 00 KEY_VOLUMEDOWN Sony_RMT-CS33AD
0000000000006422 01 KEY_VOLUMEDOWN Sony_RMT-CS33AD
0000000000006422 02 KEY_VOLUMEDOWN Sony_RMT-CS33AD

Last step is to give these events actions, e.g. start a program. For this we use the program irexec. This needs its config file ~/.config/lircrc with entries like this (simple example):

begin
prog = irexec
button = KEY_VOLUMEUP
config = echo "Volume-Up"
end
begin
prog = irexec
button = KEY_VOLUMEDOWN
config = echo "Volume-Down"
end

For any button add a new block begin ... end. The button name is exact the name you get with irw. As action (line config =) I do a simple echo so you can see on the console what button was pressed. Here you can call any other program, e.g. system programs, bash scripts, python programs, what you want. Look at man irexec.

Thanks to manthony121 in his last comment.

Have fun :-)

3
  • I purchased this IR Expansion Board for Raspberry Pi 3, with these setup instructions. My RPi3 is running the latest version of Raspbian OS (Stretch April 2019). Your instructions are slightly different, but the instructions on the product wiki also calls out a required step 2 if Raspbian older than Feb 2019. I don't see a /dev/lirc0 device.
    – Web User
    Commented Jun 8, 2019 at 22:58
  • 1
    For the newest kernel dtoverlay=lirc-rpi,gpio_out_pin=17,gpio_in_pin=18,gpio_in_pull=up should be dtoverlay=gpio-ir,gpio_out_pin=17,gpio_in_pin=18,gpio_in_pull=up otherwise the guide worked perfectly
    – Pascal
    Commented Sep 30, 2019 at 16:45
  • @Pascal Thanks for the feedback. I have updated the answer.
    – Ingo
    Commented Sep 30, 2019 at 17:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.