Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting lirc to work with Raspberry Pi 3 (Raspbian Stretch)
Notes to make IR shield (made by LinkSprite) work in Raspberry Pi 3 (bought from Amazon [1]).
The vendor has some documentation [2] but that is not complete and sufficient for Raspbian Stretch.
Following are the changes that I made to make it work.
$ sudo apt-get update
$ sudo apt-get install lirc
# Add the following lines to /etc/modules file
lirc_dev
lirc_rpi gpio_in_pin=18 gpio_out_pin=17
# Add the following lines to /etc/lirc/hardware.conf file
LIRCD_ARGS="--uinput --listen"
LOAD_MODULES=true
DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"
# Update the following line in /boot/config.txt
dtoverlay=lirc-rpi,gpio_in_pin=18,gpio_out_pin=17
# Update the following lines in /etc/lirc/lirc_options.conf
driver = default
device = /dev/lirc0
$ sudo /etc/init.d/lircd stop
$ sudo /etc/init.d/lircd start
# Check status to make lirc is running
$ sudo /etc/init.d/lircd status
# Reboot before testing
$ reboot
# To test if lirc driver is working
$ sudo /etc/init.d/lircd stop
$ mode2 -d /dev/lirc0
<press a key in remote and you should see multple lines like below>
pulse 560
space 1706
pulse 535
# to record a custom remote/register a remote device
$ sudo /etc/init.d/lircd stop
$ sudo irrecord -d /dev/lirc0 ~/lircd.conf
# follow the instruction prompted by the above command carefully
# at the end ~/lircd.conf file will be generated
# backup the original lircd.conf
$ sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf
$ sudo cp ~/lircd.conf /etc/lirc/lircd.conf
$ sudo /etc/init.d/lircd start
# you can test if the recorded remote works by
$ irsend SEND_ONCE <device-name> KEY_POWER
$ irsend SEND_ONCE <device-name> KEY_VOLUMEUP
[1] https://www.amazon.com/Infrared-Shield-for-Raspberry-Pi/dp/B00K2IICKK/ref=pd_sbs_328_1?_encoding=UTF8&psc=1&refRID=1QPY33VFCGETBJ17K8QE
[2] http://learn.linksprite.com/raspberry-pi/shield/infrared-transceiver-on-raspberry-pi-lirc-software-installation-and-configuration/
@null-loop
Copy link

null-loop commented Apr 14, 2018

Just wanted to echo other peoples comments - best description of how to get everything setup I've found. Thank you for your efforts.

@markusamuel
Copy link

markusamuel commented Apr 14, 2018

Thanks a lot ! I was having a rough time making this work on RPi

@LachlanHogan
Copy link

LachlanHogan commented May 2, 2018

Anyone else using Raspbian Stretch that runs into the error: Info: Cannot configure the rc device for /dev/lirc0 try following the last comment in the bug report: https://sourceforge.net/p/lirc/tickets/168/

When I recorded signals with irrecord, I got:

begin codes
      KEY_POWER                0x219E48B7 0x7E825B6C
      KEY_HOME                 0x219E609F 0x7E825B6C
      KEY_UP                   0x219EA05F 0x7E825B6C
      KEY_LEFT                 0x219EE01F 0x7E825B6C
      KEY_ENTER                0x219E10EF 0x7E825B6C
      KEY_RIGHT                0x219E906F 0x7E825B6C
      KEY_DOWN                 0x219E00FF 0x7E825B6C
      KEY_BACK                 0x219ED827 0x7E825B6C
      KEY_STOP                 0x219E20DF 0x7E825B6C
      KEY_OPTION               0x219E58A7 0x7E825B6C
      KEY_REWIND               0x219EF807 0x7E825B6C
      KEY_PLAYPAUSE            0x219E50AF 0x7E825B6C
      KEY_FASTFORWARD          0x219E7887 0x7E825B6C
      KEY_PREVIOUS             0x219E40BF 0x7E825B6C
      KEY_NEXT                 0x219E807F 0x7E825B6C
      KEY_SEARCH               0x219EF00F 0x7E825B6C
      KEY_EJECTCD              0x219E08F7 0x7E825B6C
  end codes

After installing this configuration file at /etc/lirc/lircd.conf.d and rebooting, irw produced no output, though I could see using strace
that my /usr/sbin/lircd --nodaemon process was reading data from /dev/lirc0. Removing the 0x7E825B6C codes from each of the
above lines and rebooting caused irw to begin showing the key values in the left column above when I pressed the corresponding
buttons on my WD TV Live remote control.

After I removed the right hand codes from my *.lircd.conf file it all started working nicely!

@sfsdfd
Copy link

sfsdfd commented Jun 4, 2018

This instruction set doesn't appear to be working. After stopping and starting lircd, I get this:

lircd-0.9.4c[3841]: Notice: /etc/lirc/lircd.conf.d/devinput.lircd.conf: devinput: Multiple values for same …BTN_MOUSE
lircd-0.9.4c[3841]: Warning: Duplicate remotes "devinput" found, problems ahead
lircd-0.9.4c[3841]: Notice: lircd(default) ready, using /var/run/lirc/lircd
lircd-0.9.4c[3841]: Notice: /etc/lirc/lircd.conf.d/devinput.lircd.conf: devinput: Multiple values for same …BTN_SOUTH
lircd-0.9.4c[3841]: Notice: /etc/lirc/lircd.conf.d/devinput.lircd.conf: devinput: Multiple values for same …_TOOL_PEN
lircd-0.9.4c[3841]: Notice: /etc/lirc/lircd.conf.d/devinput.lircd.conf: devinput: Multiple values for same …N_TRIGGER
lircd-0.9.4c[3841]: Notice: /etc/lirc/lircd.conf.d/devinput.lircd.conf: devinput: Multiple values for same …ER_HAPPY1
lircd-0.9.4c[3841]: Notice: /etc/lirc/lircd.conf.d/devinput.lircd.conf: devinput: Multiple values for same …BTN_WHEEL
lircd-0.9.4c[3841]: Warning: Duplicate remotes "devinput" found, problems ahead
lircd-0.9.4c[3841]: Notice: lircd(default) ready, using /var/run/lirc/lircd

@superiuspi
Copy link

superiuspi commented Jun 8, 2018

Hello there !
thanks for your share !!!
Do you know how to configure the pi to command 2 IR séparately ???
thanks for you help...

@barustnt
Copy link

barustnt commented Jul 6, 2018

hi
thank you for this explanation
but i have a problem
when " backup the original lircd.conf"
pi@raspberrypi:~ $ sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf
mv: cannot stat '/etc/lirc/lircd.conf': No such file or directory
and my remote name is x.lircd.conf
can you help me please

@TSM-EVO
Copy link

TSM-EVO commented Jul 19, 2018

@prasanthj

Can you go a step further and try to get lirc_web working as well? I am trying to get it working, but right now, it's not finding my remote.

I need to use it to send the IR commands to my A/C. lirc is working and I can use irsend SEND_ONCE to send a keypress, but lirc_web doesn't find my remote.

Any help is appreciated.

@adin283
Copy link

adin283 commented Aug 9, 2018

@unnamalai-kb
Does a button has a gap value, or a whole remote control has a gap value?
I had tested that every button had different gap value, so how can I write the /etc/lirc/lirc.conf ?

@barneyman
Copy link

barneyman commented Aug 18, 2018

thank you for doing this - i appreciate it.

@j00sef
Copy link

j00sef commented Aug 30, 2018

If anyone is having trouble with this guide as I have since it seems to be more suited to ver 0.9.0. I have found another guide that is intended to help you setup lirc's latest version(0.9.4c) with raspbian stretch. Here is the link https://github.com/mtraver/rpi-ir-remote. It worked for me hopefully it'll clarify some of your problems.

@m1r05l4v
Copy link

m1r05l4v commented Oct 8, 2018

In case some run into same problems with new Stretch and LIRC 0.9.4c. This is how I have made work

Above LIRC setup was not working for me.
Im using Stretch and LICR 0.9.4.c

Some helpful tips I have found in first post
but on this https://raspberrypi.stackexchange.com/questions/81876/raspberry-pi-3-not-lirc-not-running-working
I found solution

I run setup as explained and it worked.
for example
instead of mode2 -d /dev/lirc0 for me worked sudo mode2 --driver default --device /dev/lirc0
after that II pointed remote and get pulse on the list.

RECORD
Also to record the buttons I have done as per bellow because irrecord didnt work for me with command
sudo irrecord -d /dev/lirc0 ~/lircd.conf
I got

Could not open new config file /home/user/lircd.conf
Could not init hardware (lircd running ? --> close it, check permissions)

in order to solve this I used sudo irrecord --driver default --device /dev/lirc0 ~/lircd.conf

so steps are

sudo /etc/init.d/lircd stop
sudo irrecord --driver default --device /dev/lirc0 ~/lircd.conf

follow steps
then
sudo /etc/init.d/lircd start

Check your remote with command
irw

here it should recognise your buttons and file name
and to send command
irsend SEND_ONCE KEY_POWER

@hG3n
Copy link

hG3n commented Dec 5, 2018

In case some run into same problems with new Stretch and LIRC 0.9.4c. This is how I have made work

Above LIRC setup was not working for me.
Im using Stretch and LICR 0.9.4.c

Some helpful tips I have found in first post
but on this https://raspberrypi.stackexchange.com/questions/81876/raspberry-pi-3-not-lirc-not-running-working
I found solution

I run setup as explained and it worked.
for example
instead of mode2 -d /dev/lirc0 for me worked sudo mode2 --driver default --device /dev/lirc0
after that II pointed remote and get pulse on the list.

RECORD
Also to record the buttons I have done as per bellow because irrecord didnt work for me with command
sudo irrecord -d /dev/lirc0 ~/lircd.conf
I got

Could not open new config file /home/user/lircd.conf
Could not init hardware (lircd running ? --> close it, check permissions)

in order to solve this I used sudo irrecord --driver default --device /dev/lirc0 ~/lircd.conf

so steps are

sudo /etc/init.d/lircd stop
sudo irrecord --driver default --device /dev/lirc0 ~/lircd.conf

follow steps
then
sudo /etc/init.d/lircd start

Check your remote with command
irw

here it should recognise your buttons and file name
and to send command
irsend SEND_ONCE KEY_POWER

Thanks man! Setting this up drove me crazy.

@Matze2018
Copy link

Matze2018 commented Dec 10, 2018

Hello, i want to use lirc with a raspberry BUT not with the gpio.
I want to use an uart /dev/ttyACM1
Is this possible?

@charlieskc
Copy link

charlieskc commented Feb 24, 2019

mine still no luck...
tail -f /var/log/messages | grep lirc
Feb 24 17:51:54 raspberrypi lircd-0.9.4c[1221]: Notice: Using systemd fd
Feb 24 17:51:54 raspberrypi lircd-0.9.4c[1221]: Warning: Running as root
Feb 24 17:51:54 raspberrypi lircd-0.9.4c[1221]: Warning: config file /etc/lirc/lircd.conf contains no valid remote control definition
Feb 24 17:51:54 raspberrypi lircd-0.9.4c[1221]: Notice: lircd(default) ready, using /var/run/lirc/lircd
Feb 24 17:51:54 raspberrypi lircd-0.9.4c[1221]: Notice: accepted new client on /var/run/lirc/lircd
Feb 24 17:51:54 raspberrypi lircd-0.9.4c[1221]: Info: Cannot configure the rc device for /dev/lirc0
Feb 24 17:52:59 raspberrypi lircd-0.9.4c[1221]: Info: removed client
Feb 24 17:53:17 raspberrypi lircd-0.9.4c[1221]: Notice: accepted new client on /var/run/lirc/lircd
Feb 24 17:53:17 raspberrypi lircd-0.9.4c[1221]: Info: Cannot configure the rc device for /dev/lirc0
Feb 24 17:53:27 raspberrypi lircd-0.9.4c[1221]: Info: removed client

@rogue45
Copy link

rogue45 commented Feb 26, 2019

Thanks! This was a super helpful reference.

@Loopback59
Copy link

Loopback59 commented Apr 12, 2019

Great! Worked at my old Pi A (Stretch) too.

@drstil
Copy link

drstil commented Apr 17, 2019

Thank you for this nice reference!

I'm using a Raspberry PI 3 and set up everything as written above. I'm using a TSOP34836 IR receiver. When I start receiving data with "mode2 -d /dev/lirc0" I got a lot of data input:
pulse 405
space 362
pulse 10150
pulse 383
even if the IR receiver is completely covered or even if the receiver ist not connected at all. Seems that there is unspecific input.
I just tested and set ground at GPIO 18, then input is changing, there are now only pulses but no spaces anymore. So it seems that the correct GPIO is set.
Still tested another GPIO and same result.

Do you have any idea what could be wrong or what I cloud try? Do you need more information?

Thank you for your help and best!

EDIT:
Just tested another GPIO ports and finally GPIO 20 and 21 were working without any unspecific signal. Still don't understand why, maybe PCM_CLK on GPIO 18?

@drstil
Copy link

drstil commented Apr 19, 2019

I tried without settings in /etc/modules and it did also work. Any idea for what you need the settings in /etc/modules, cloud we ignore them?

@johanvanl
Copy link

johanvanl commented Apr 23, 2019

Thanks a lot to everyone for the info above. Having struggled to get lirc working.

The solution mcblacky posted did the trick for me.

One thing I had problems with was after restarting the Pi the solution stopped working.

Irw only responded to some of the keys on my keyboard.
Only working after I stopped and started lirc. Restart didn’t work either.

Where I now have the following commands in my rc.local file for my solution to work after a boot:

sleep 30s
systemctl stop lircd.socket lircd.service
sleep 30s
systemctl start lircd.socket lircd.service

Why would lirc need to be stopped and started before working?

Thanks

@knowblesse
Copy link

knowblesse commented Jul 27, 2019

######### For users using kernel version 4.19+ ###########
This code does not work for higher kernel version. (Mine : kernel version : 4.19.58, lirc version : 0.10.1-5.2)
as "m1r05l4v" commented above, for users who has higher kernel versions, please refer the other doc

In case some run into same problems with new Stretch and LIRC 0.9.4c. This is how I have made work

Above LIRC setup was not working for me.
Im using Stretch and LICR 0.9.4.c

Some helpful tips I have found in first post
but on this https://raspberrypi.stackexchange.com/questions/81876/raspberry-pi-3-not-lirc-not-running-working
I found solution

I run setup as explained and it worked.
for example
instead of mode2 -d /dev/lirc0 for me worked sudo mode2 --driver default --device /dev/lirc0
after that II pointed remote and get pulse on the list.

RECORD
Also to record the buttons I have done as per bellow because irrecord didnt work for me with command
sudo irrecord -d /dev/lirc0 ~/lircd.conf
I got

Could not open new config file /home/user/lircd.conf
Could not init hardware (lircd running ? --> close it, check permissions)

in order to solve this I used sudo irrecord --driver default --device /dev/lirc0 ~/lircd.conf

so steps are

sudo /etc/init.d/lircd stop
sudo irrecord --driver default --device /dev/lirc0 ~/lircd.conf

follow steps
then
sudo /etc/init.d/lircd start

Check your remote with command
irw

here it should recognise your buttons and file name
and to send command
irsend SEND_ONCE KEY_POWER

@mst94
Copy link

mst94 commented Jul 29, 2019

hello, my kernel is 4.19.58 on raspbian 10 buster.
I have some troubles with irrecord.
I have tried it with 2 remotes, but both do not work, the following problems occure:

  1. After hit the remote until 2 lines are filled with dots, the message appears:
    "Got gap (121879)}"
    and furthermore: "Cannot find any gap, using an arbitrary 50 ms one" ... and so one

  2. Then I create my names for the keys. This works well.

  3. Then the toogle mask creating failes: "Cannot find any toggle mask"

The created configuration file has except for the name, gap and frequency everywhere 0 or 0x0. For the created key-codes as well, so it is useless.

Does somebody have a glue?

Thanks a lot

@essieM
Copy link

essieM commented Jul 31, 2019

I'm having the exact same issue as you @mst94. Any luck with finding a solution?

@mst94
Copy link

mst94 commented Jul 31, 2019

I'm having the exact same issue as you @mst94. Any luck with finding a solution?

Hi, unfortunately I am still searching for a solution to this problem... I will post a solution here when I am lucky!

@mst94
Copy link

mst94 commented Aug 3, 2019

I'm having the exact same issue as you @mst94. Any luck with finding a solution?

Removing LIRC and reinstalling it with this guide made it working! https://github.com/AnaviTechnology/anavi-docs/blob/master/anavi-infrared-phat/anavi-infrared-phat.md#setting-up-lirc

I hope it will work for you as well.

@essieM
Copy link

essieM commented Aug 5, 2019

Thanks @mst94. I was able to get it working as well..

@Ogg3l
Copy link

Ogg3l commented Oct 10, 2019

I have the same issue. Which raspberry pi Version and which Kernel Version do you use? I tried to Set it up with the tutorial. Maybe the ir receiver is the Problem? Which ir receiver do you use?

@mst94
Copy link

mst94 commented Oct 16, 2019

I have the same issue. Which raspberry pi Version and which Kernel Version do you use? I tried to Set it up with the tutorial. Maybe the ir receiver is the Problem? Which ir receiver do you use?

Hi, take a look above: "Kernel is 4.19.58 on raspbian 10 buster".

I am using "TSOP31238 Integrated IR receiver 38kHz 45° VISHAY TELEFUNKEN", ordered from Amazon.

@todlo
Copy link

todlo commented Jan 28, 2020

for anyone on buster who was, like me, struggling and failing with this, see: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=235256

tl;dr, lirc_dev isn't included in kernel 4.19, so it's recommended to use gpio-ir... but then irrecord (among others) doesn't work, so there's a patch that this absolute lifesaver has provided (linked in the above), which you can roll into your own patched, compiled & installed version of lirc.

@ephdtrg
Copy link

ephdtrg commented Feb 6, 2020

Can confirm, patching lirc with both guides provided by @mst94 and @todlo fixed all issues, codes are recognized correctly now, thank you guys.
Tested on RPi 4 with kernel 4.19.75 rasbpian buster and lirc 0.10.1-5.2 (patched).

@blanhamMines
Copy link

blanhamMines commented Aug 14, 2020

I am getting an error when trying to execute the command:

irsend SEND_ONCE vanLights KEY_POWER.

I get this output:

transmission failed
Error running command: Input/output error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment