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