1

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")

Community
  • 1
  • 1
Neil Dey
  • 449
  • 2
  • 7
  • 18

3 Answers3

1

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

leamas
  • 151
  • 1
  • 6
0

You probably do not want to use the mode2 output for this. There is a Python library available (Here) which would likely be a much better way to go for this project.

Code:

import lirc
sockid = lirc.init("myprogram")
print(lirc.nextcode())
lirc.deinit()

lircrc configuration file

begin
  button = 1          # what button is pressed on the remote
  prog = myprogram    # program to handle this command
  config = one, horse # configs are given to program as list
end

begin
  button = 2
  prog = myprogram
  config = two
end

Results after pressing button 1

['one', 'horse']
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • I tried that but I find an issue in the line 'sockid = lirc.init("myprogram")'. I have updated the question with the output I am seeing. – Neil Dey Apr 29 '17 at 03:32
  • @NeilDey, looks like you did not get lirc or its conf file setup right. Suggest you try the debug tips ([here](http://www.lirc.org/html/configure.html#lircrc_format)). Note the `echo` commands used to debug... Also have you restarted lirc after your `sudo /etc/init.d/lirc stop`? – Stephen Rauch Apr 29 '17 at 03:40
0

These days there is no need to use lirc as IR events are handled through the kernel.

In my case I setup an IR receiver on a GPIO pin in /boot/config.txt

dtoverlay=gpio-ir,gpio_pin=16

Then installed evdev

pip install evdev

Reboot, and the following worked (your input device path my vary)

from evdev import InputDevice, categorize, ecodes
dev = InputDevice('/dev/input/event0')

for event in dev.read_loop():
    print(event)

When pressing some buttons on the remote I get:

$> sudo python3 irtest.py
device /dev/input/event0, name "gpio_ir_recv", phys "gpio_ir_recv/input0"
event at 1639133806.295636, code 04, type 04, val 64
event at 1639133806.295636, code 00, type 00, val 00
event at 1639133806.405607, code 04, type 04, val 64
event at 1639133806.405607, code 00, type 00, val 00
event at 1639133808.745610, code 04, type 04, val 16
...
dgorissen
  • 6,207
  • 3
  • 43
  • 52