1

I have an setup of Raspberry pi 3 Model B v1.2 and I have installed LIRC (Linux Infrared remote control) to send and receive IR signals (using an IR receiver and transmitter) from the raspberry pi.

Now my question is, How do I identify the protocol of the IR remote ? ex: NEC/RC5/RC6/SIRC.

Your help is much appreciated. Do comment below if any other information is required.

Surya H
  • 21

2 Answers2

0

I just found my remote's protocol by following these steps. You don't need LIRC specifically, just the kernel's rc_core support.

I enabled the IR receiver on my Raspberry Pi by adding the overlay in config.txt:

dtoverlay=gpio-ir,gpio_pin=17 # substitute with your pin number

Reboot and then confirm your receiver has been added:

# dmesg | grep 'rc '
[    7.985963] rc rc0: gpio_ir_recv as /devices/platform/ir-receiver@11/rc/rc0
[    7.994038] rc rc0: lirc_dev: driver gpio_ir_recv registered at minor = 0, raw IR receiver, no transmitter

My receiver is rc0. Remember this for later!
Find your receiver's input in /dev/inputs

# ls -l /dev/input/by-path/
total 0
lrwxrwxrwx 1 root root 9 Apr 28  2022 platform-fe9c0000.xhci-usb-0:1.1:1.0-event-kbd -> ../event0
lrwxrwxrwx 1 root root 9 Apr 28  2022 platform-ir-receiver@11-event -> ../event1

You'll need a program to check if the input is working. I tested the input with this simple perl script, but the principle will work in any language:

#!/usr/bin/perl

use strict; use warnings; use Fcntl 'O_RDONLY';

my $file = '/dev/input/event1'; # YOUR IR INPUT HERE sysopen(my $fh, $file, O_RDONLY) or die "no file: $!"; binmode($fh);

while (1) { my $count = sysread($fh, my $data, 24); my ($sec, $usec, $type, $code, $value) = unpack('L<L<S<S<l<', $data); print "$sec.$usec\n"; printf " type: %02x\n", $type; printf " code: %02x\n", $code; printf " value: %08x\n", $value; }

Now we can start testing protocols. You can change the set protocol by writing to the sysfs node for your IR input (mine is rc0):

# cd /sys/class/rc/rc0
# cat protocols                                                                                                                
rc-5 nec [rc-6] jvc sony rc-5-sz sanyo sharp mce_kbd xmp imon [lirc]

Now we just work through them one by one and press buttons on the remote until we see some action:

# echo 'rc-5' > protocols 
# cat protocols 
[rc-5] nec rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp imon [lirc]
# ~/read-input.pl
(no output)

No dice, let's keep trying.

# echo 'nec' > protocols 
# cat protocols 
rc-5 [nec] rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp imon [lirc]
# ~/read-input.pl
1689373948.890804
   type: 04
   code: 04
  value: 00860514
1689373948.890804
   type: 00
   code: 00
  value: 00000000

Looks like my remote speaks NEC protocol!

Now let's make sure it always has the right protocol set at boot time with a udev rule (Mine is rc0):

# cat /etc/udev/rules.d/ir-input.rules 
ACTION=="add", KERNEL=="rc0", SUBSYSTEM=="rc", RUN+="/bin/sh -c 'echo nec > /sys/class/rc/rc0/protocols'"

Now my remote works after a reboot.

Notes

wes
  • 133
0

You can also try the following;

List all the Remote Controllers:

ir-keytable

Locate which /sys/class/rc/rc contains lirc or protocols rc-6 etc.

Enable all the protocols for this remote control, in my case rc3:

ir-keytable -s rc3  -p rc-5 -p nec -p rc-6 -p jvc -p sony -p rc-5-sz -p sanyo -p sharp -p mce_kbd -p xmp -p imon -p lirc

You then test it and it tries to detect the protocol and scancode:

ir-keytable -s rc3 -t

My output with Philips remote:

107216.468048: lirc protocol(rc6_0): scancode = 0x9f toggle=1
107216.468072: event type EV_MSC(0x04): scancode = 0x9f
107216.468072: event type EV_SYN(0x00).

My output with Sharp remote:

107276.144048: lirc protocol(sharp): scancode = 0xd35
107276.144087: event type EV_MSC(0x04): scancode = 0xd35
107276.144087: event type EV_SYN(0x00).

My output with Pioneer remote:

107361.628075: lirc protocol(nec): scancode = 0xa51c
107361.628098: event type EV_MSC(0x04): scancode = 0xa51c
107361.628098: event type EV_SYN(0x00).

My output with Yamaha remote:

107411.440100: lirc protocol(nec): scancode = 0x7c9b repeat
107411.440136: event type EV_MSC(0x04): scancode = 0x7c9b
107411.440136: event type EV_SYN(0x00).

etc.