Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@coaxial
Last active July 1, 2023 05:42
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coaxial/575fec33fcb10f69586e419b97927eb8 to your computer and use it in GitHub Desktop.
Save coaxial/575fec33fcb10f69586e419b97927eb8 to your computer and use it in GitHub Desktop.
How to setup an infrared remote on LibreELEC/Kodi on RPI

Using a simple IR receiver such as IR5040 or TSOPxxxxx and a Raspberry Pi running LibreELEC + Kodi

Enable lirc in Kodi

Edit the file at /flash/config:

  • mount -o remount,rw /flash
  • vi /flash/config
  • append device_tree_overlay=lirc-rpi
  • mount -o remount,ro /flash

Connect the receiver

Check pinout on datasheet; use 3.3V rail, any GND, and data to GPIO #18/pin 12 (cf https://learn.adafruit.com/assets/5909)

IR5040 datasheet: http://www.tme.eu/en/Document/54a544ab7820a97322a14fb463e54018/ir5040.pdf

When looking at the component, flat side parallel to the ground plane, legs towards you, leg further from the other to the right:

  • pin 1: GND
  • pin 2: VCC (2.7~5.0V)
  • pin 3: OUT

Reboot the PI

Check that the IR receiver works

  • ssh root@mykodi
  • dmesg | grep lirc (should give something like "lirc_rpi: auto-detected active low receiver on GPIO pin 18")
  • killall lircd && mode2 -d /dev/lirc0 to check if it receives anything when pressing any button on the remote

Map the IR codes to specific keys

In /storage/.config:

  • irrecord -d /dev/lirc0 to start the recording wizard, use brand-remote-model pattern to name file
  • record at least the following keys:
    • KEY_UP
    • KEY_DOWN
    • KEY_LEFT
    • KEY_RIGHT
    • KEY_PLAY (will play/pause)
    • KEY_PAUSE (optional, will do the same as KEY_PLAY)
    • KEY_STOP
    • KEY_VOLUMEUP
    • KEY_VOLUMEDOWN
    • KEY_INFO
    • KEY_EPG (contextual menu)
    • KEY_EXIT (back)

Symlink the remote file

lircd will look for a file named lircd.conf: If the remote doesn't have any effect but the receiver is working (as verified with mode2), then double check the remote config file is named lircd.conf.

  • ln -s "$(pwd)/myremote.lircd.conf" "$(pwd)/lircd.conf"

Check if lirc works

  • irw /rub/lirc/lircd-lirc0 and press remote buttons. Should see the keymaps as the buttons are pressed.

Troubleshooting

Check if lircd works at all

  • killall lircd
  • /usr/sbin/lircd --nodaemon --loglevel=debug --driver=default --device=/dev/lirc0 --output=/run/lirc/lircd-lirc0 --pidfile=/run/lirc/lircd-lirc0.pid --release=_LIRCUP /storage/.config/lircd.conf in one terminal
  • /usr/sbin/lircd-uinput --loglevel=debug --release=_LIRCUP /run/lirc/lircd-lirc0 in another
  • press keys, see if there is any output

If keys configured successfully, try

  • irw -d /dev/lirc0 and press buttons. If it registers, check that /storage/config/lircd.conf exists; file must be lircd.conf and not other name.

Helpful threads:

# Please take the time to finish this file as described in
# https://sourceforge.net/p/lirc-remotes/wiki/Checklist/
# and make it available to others by sending it to
# <lirc@bartelmus.de>
#
# This config file was automatically generated
# using lirc-0.9.4c(default) on Sat May 6 19:04:25 2017
# Command line used: -d /dev/lirc0 lircd.conf
# Kernel version (uname -r): 4.9.13
#
# Remote name (as of config file): sony-rmt-d109a
# Brand of remote device, the thing you hold in your hand:
# Remote device model nr: rmt-d109a
# Remote device info url:
# Does remote device has a bundled capture device e. g., a
# usb dongle? : no
# For bundled USB devices: usb vendor id, product id
# and device string (use dmesg or lsusb):
# Type of device controlled
# (TV, VCR, Audio, DVD, Satellite, Cable, HTPC, ...) :
# Device(s) controlled by this remote: tv/dvd
begin remote
name sony-rmt-d109a
bits 12
flags SPACE_ENC|CONST_LENGTH
eps 30
aeps 100
header 2387 601
one 1191 604
zero 590 604
post_data_bits 8
post_data 0x92
gap 44916
toggle_bit_mask 0x0
frequency 38000
begin codes
KEY_VOLUMEUP 0x06B
KEY_VOLUMEDOWN 0xCCB
KEY_UP 0x9EB
KEY_DOWN 0x5EB
KEY_LEFT 0xDEB
KEY_RIGHT 0x3EB
KEY_OK 0xD0B
KEY_PLAY 0x4CB
KEY_PAUSE 0x9CB
KEY_STOP 0x1CB
KEY_EXIT 0x70B
KEY_INFO 0x2AB
KEY_EPG 0xD8B
end codes
end remote
@coaxial
Copy link
Author

coaxial commented May 7, 2017

IR5040 datasheet (partial)

@jpingouix
Copy link

Hi,
At the beginning of this doc I see :
pin 1: GND
pin 2: VCC (2.7~5.0V)
pin 3: OUT
But on the link to Adafruit, there is: 1-Out 2- GND 3 -VCC
What is the right connexion ? I cannot receive any signal from the remote.
I try to use the IR receiver you see on the first picture. The smallest flat side is very difficult to see even using a magnifying glass, and the attached paper is not very clear on page 4, but I can see the flat is perpendicular to the pins, not parallel :

° ° ° ° (pins)
° not ___ (flat)
°


Any help would be very welcome, thanks in advance.

image
image

@jpingouix
Copy link

Sorry for the bad draw. I try to write something more clear :
Capture

@coaxial
Copy link
Author

coaxial commented Oct 6, 2021

You have to look at your schematic, it tells you what the pinout is. Yours is in a different order than the one I used, so you have to wire it accordingly so that your GND, VCC, OUT go to the right pins on the RPi.

Depending on your sensor, you might have fried it if you put VCC on the wrong pin.

@coaxial
Copy link
Author

coaxial commented Oct 6, 2021

In your case, it looks indeed like the flat side should be on the left and then your pins are OUT, GND, VCC. Each sensor can have a different order for the pins but it doesn't matter (in that case) as long as the output signal is compatible.

@jpingouix
Copy link

Thanks a lot for your answer . I'll try to-morrow to modify my wiring, hopefully the device is not dead ...

@jpingouix
Copy link

FINE ! It does work ! I am lucky, I had not fried the device, and OUT,GND,VCC is good.
Thanks again, best regards from France.

@coaxial
Copy link
Author

coaxial commented Oct 7, 2021

Glad to hear it, enjoy your system!

@jpingouix
Copy link

Well ..... I'm afraid I was too much optimist ! My first problem was to set the IR device working, and thanks to you, it does. BUT :

  • It works on my Raspberry Pi 3 running standard Raspbian.
  • On the same Rasp 3, changing only the SD card to run LibreELEC, without touching the IR device, it does not at all : dmesg | grep lirc displays nothing, /dev/lirc* does not exist. What is wrong ? I expect there are some differences between LibreELEC and the standard Raspbian, but I cannot install anything in the LibreELEC OS.
    And I tried to use an infrared remote to LibreELEC... Is there any solution ?

@coaxial
Copy link
Author

coaxial commented Oct 7, 2021

Sorry to hear. I’ve switched to CEC about three years ago and don’t use IR anymore.

Did you do the first step (and did it take?) You can check by opening the /flash/config file again and check that it has the extra overlay directive. You need to do it again when you swap the card because that’s all stored on the SD.

Or maybe your sensor is busted, you could try with a new one or you could build a circuit with a led and a resistor on the OUT pin. I’d expect the led to light up matching the pulses that the sensor receives if it’s functioning normally. I reread your comment and you’re saying it works in raspian so the sensor is most likely fine.

Finally, you’ll probably have more luck asking on the libreelec forums; you’ll have a higher chance of finding someone currently using libreelec with an IR sensor.

@jpingouix
Copy link

Me again ....
Most of my problems have been resolved now, but one : irw is well responding the name of the key I have pressed on the remote, but irexec do nothing. I have put a .lircrc file in /storage, but it seems it is never read...
Since my last message, I try to register to libreelec.tv forum, but they never send the registration code, so I cannot ask any question in the forum.

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