How to use IR Remote with Raspberry Pi using Python?

Neil Dey picture Neil Dey · Apr 29, 2017 · Viewed 11.1k times · Source

I bought this [IR Sensor and Remote][1] to use with my Raspberry Pi 3.

I have LIRC setup and I am able to detect an input from the IR Remote using the commands below:

sudo /etc/init.d/lirc stop

mode2 -d /dev/lirc0

When I run the above commands, I am able to detect input from the IR Remote. When I press any button on the IR REmote, I get an output like:

enter image description here

My question is - in the output above, I pressed '2" on the remote. How shall I go about deciphering (in python) which button is really pressed?

Update 1:

I tried using the python-lirc package but I get error on this line:

sockid=lirc.init("myprogram")

Answer

leamas picture leamas · Apr 30, 2017

The previous answers shortcuts the lirc decoding. Since you have a working mode2 the kernel driver works and sends correct data to lircd. However, mode2 does not tell you if the decoding works.

To check the decoding you use irw(1). Until you have working output from this program, you don't know if lirc can decode your remote.

The lircrc file described above is used to transform the generic button presses (as shown by irw) to application-specific commands. To debug this file you use ircat(1).

When you have working output from irw(1) and ircat(1) your lirc setup is complete. A working lirc setup is really required before using any python package. BTW, as of upcoming 0.10.0 lirc will have native python bindings.

A comprehensive guide to setup lirc can be found at http://lirc.org/html/configuration-guide.html