7

After much searching I was surprised and dismayed about the conflicting information on how to setup IR remote control for my RPi project. I thought it would be easy but setting up Linux InfraRed Control (LIRC) has been problematic for a long time

But much changed in June 2019 with the release of the Buster version of Raspbian making much of the tutorials out there worthless. Many tutorials have you create a hardware.conf file but LIRC does not need nor want it and the lirc-rpi module has been replaced with the gpio-ir module.

So how do you set up LIRC on the RPi using Raspbian (Buster)?

user1200233
  • 333
  • 1
  • 2
  • 9

3 Answers3

12

This answer assumes the RPi is running raspbian (version Buster Jun 2019). Also a working knowledge of the terminal, basic commands from the command prompt and editing text files is assumed.

Step 1: Install lirc

1) Open terminal window and install LIRC. Be forewarned that this will likely raise an error "Failed to start Flexible IR remote input/output application support" as the installed files now have .dist appended and the suffix must be removed as noted below. Not hard but frustrating.

$ sudo apt-get update
$ sudo apt-get install lirc

----DON'T WORRY! as this will likely raise an error "Failed to start Flexible IR remote input/output application support" as the .dist suffix needs to be deleted from lirc_options.conf. Just copy the file as shown.

$ sudo cp /etc/lirc/lirc_options.conf.dist /etc/lirc/lirc_options.conf

2) Reinstall lirc now that the lirc_options.conf file has been renamed

$ sudo apt-get install lirc

Step 2: Edit lirc_options.conf

Edit /etc/lirc/lirc_options.conf as follows by changing these two lines:

:
:
driver = default
device = /dev/lirc0
:
:

Step 3: Perform copy to remove .dist suffix from lircd.conf.dist

Remove suffix .dist from /etc/lirc/lircd.conf.dist

$ sudo cp /etc/lirc/lircd.conf.dist /etc/lirc/lircd.conf

Step 4: Edit config.txt

Edit /boot/config.txt by adding one line in the lirc-rpi module section as follows. This example assumes the RPi is 'listening' on BCM Pin 17 for the IR receiver but any RPi IO pin can be used. I have not tried it yet but if you want to send commands from the RPi then add and uncomment the 4th line as shown below to send IR commands on BCM pin 18

:
:
:
# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi
dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
:
:
:

Step 5: Check status and reboot

1) Stop, start and check status of lircd to ensure there are no errors!

$ sudo systemctl stop lircd.service
$ sudo systemctl start lircd.service
$ sudo systemctl status lircd.service

2) Reboot

$ sudo reboot

Step 6: Test remote

This step assumes you have have a IR receiver hooked up to your RPi on the pin specified in config.txt.

1) stop LIRCD service and test remote using mode2 command

$ sudo systemctl stop lircd.service
$ sudo mode2 -d /dev/lirc0

3) Point the remote at the receiver and press some buttons. You should see something LIKE this:

:
:
space
pulse
:
:

4) Press Ctrl-C to exit

5) Your IR receiver is setup and ready to proceed to Part 2 and be accessed in python.

user1200233
  • 333
  • 1
  • 2
  • 9
  • This answer is fine if you actually want to use the *default* driver (which has a silly name). However, LIRC is a complex and flexible tool with other drivers available, notably the default *devinput*. See e. g., the official docs at http://lirc.org/html/configuration-guide.html – leamas Aug 11 '19 at 10:06
  • 1
    Thanks for answer. What is the difference between `gpio_pin` and `gpio_in_pin` in config.txt? What is the difference between `lirc-rpi` and `gpio-ir`? – Mubin Icyer Jan 01 '20 at 10:30
  • I could not run `mode2` command. I received `Cannot initiate device /dev/lirc0` error. I must also stop socket `sudo systemctl stop lircd.socket` – Mubin Icyer Jan 01 '20 at 10:34
  • 1
    I think this answer is an extract from https://www.instructables.com/Setup-IR-Remote-Control-Using-LIRC-for-the-Raspber/ , here is the Part 2: https://www.instructables.com/Easy-Setup-IR-Remote-Control-Using-LIRC-for-the-Ra/ – scmanjarrez May 22 '22 at 13:48
0

The above solution doesn't work with Raspbian Buster Kernel 4.19. I've checked it with (Raspbian Buster version 2020-05-27)

However, it works fine if you use only irsend that sends IR signals. If you want to receive & record IR signals using irrecord, mode2, irw or irexec commands some staff required.

Step - 1: Install a patch to use irrecord with kernel 4.19.X and gpio-ir

sudo su -c "grep '^deb ' /etc/apt/sources.list | sed 's/^deb/deb-src/g' > /etc/apt/sources.list.d/deb-src.list"
sudo apt update
sudo apt install devscripts

Step - 2: If you have already installed lirc with apt, please uninstall it as follows

sudo apt remove lirc liblirc0 liblirc-client0

Step - 3: Installing with a patch for gpio-ir in Raspbian Buster

sudo apt install dh-exec doxygen expect libasound2-dev libftdi1-dev libsystemd-dev libudev-dev libusb-1.0-0-dev libusb-dev man2html-base portaudio19-dev socat xsltproc python3-yaml dh-python libx11-dev python3-dev python3-setuptools
mkdir build
cd build
apt source lirc
wget https://raw.githubusercontent.com/neuralassembly/raspi/master/lirc-gpio-ir-0.10.patch
patch -p0 -i lirc-gpio-ir-0.10.patch
cd lirc-0.10.1
debuild -uc -us -b
cd ..
sudo apt install ./liblirc0_0.10.1-5.2_armhf.deb ./liblircclient0_0.10.1-5.2_armhf.deb ./lirc_0.10.1-5.2_armhf.deb

Note: The final install command will fail. You have to configure /boot/config.txt and /etc/lirc/lirc_options.conf files.

Step - 4: Edit /boot/config.txt

:
:
:
# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi
dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
:
:
:

Step - 5: Perform copy to remove .dist suffix from lirc_options.conf.dist and lircd.conf.dist

sudo cp /etc/lirc/lirc_options.conf.dist /etc/lirc/lirc_options.conf
sudo cp /etc/lirc/lircd.conf.dist /etc/lirc/lircd.conf

Step - 6: Reinstall

sudo apt install ./liblirc0_0.10.1-5.2_armhf.deb ./liblircclient0_0.10.1-5.2_armhf.deb ./lirc_0.10.1-5.2_armhf.deb 

Step - 7: Edit /etc/lirc/lirc_options.conf

:
:
driver = default
device = /dev/lirc0
:
:

Step - 8: Check status and reboot

Check:

$ sudo systemctl stop lircd.service
$ sudo systemctl start lircd.service
$ sudo systemctl status lircd.service

Reboot:

$ sudo reboot

Step - 9: Test remote

$ sudo systemctl stop lircd.service
$ sudo mode2 -d /dev/lirc0

Here is the reference for full description

Ma'ruf
  • 167
  • 1
  • 10
0

Make your custom remote control used by installing one python module.

Circuit Diagram link

  1. Install ircodec
  2. Run this command in terminal "sudo systemctl start pigpiod"
  3. Receive and transmit IR signal (https://pypi.org/project/ircodec/)