LIRC Setup for IR Blaster with Ubuntu 18.04

$ sudo apt-get install lirc

While installing lirc, you will be asked about the device type of IR receiver and transmitter.
Since we will set up later manually, just select None.

lirc_odroid module driver is already included by default.
Now you need to set up lirc_options.conf and lircd.conf first and then probe the modules with some parameters.

LIRC Configuration (1) - lirc_options.conf

lirc_options.conf is generated by default when lirc is installed
and you need to modify two parameters as following.

$ sudo vi /etc/lirc/lirc_options.conf
driver          = default
device          = /dev/lirc0

Please refer to this link for the whole contents of lirc_options.conf.
lirc_options.conf

LIRC Configuration (2) - hk.lircd.conf

lircd.conf files under /etc/lirc/lircd.conf.d include signal timing information and provide a mapping from button presses to key symbols.
You need to add a new lircd.conf based on your custom remote controller.
With the Hardkernel IR remote controller, the following example is available.

$ sudo vi /etc/lirc/lircd.conf.d/hk.lircd.conf

hk.lircd.conf
https://www.hardkernel.com/shop/ir-remote-controller/


Install module and Run lirc service

All necessary configuration is done, you need to install lirc_odroid module and set some parameters.

# The usage of lirc_odroid module
lirc_odroid  gpio_out_pin=${gpio_number} invert=[0 or 1] softcarrier=[0 or 1]
1. ODROID-N2 Example

Supposing to use Pin#11 of ODROID-N2 (GPIO #483),

$ service lircd stop
$ modprobe lirc_dev
$ modprobe lirc_odroid gpio_out_pin=483 softcarrier=1 invert=1
$ service lircd restart
2. ODROID-C2 Example

Supposing to use Pin#11 of ODROID-C2 (GPIO #247),

$ service lircd stop
$ modprobe lirc_dev
$ modprobe lirc_odroid gpio_out_pin=247 softcarrier=1 invert=1
$ service lircd restart
3. ODROID-XU4 Example

Supposing to use Pin#26 of ODROID-XU4 (GPIO #24),

$ service lircd stop
$ modprobe lirc_dev
$ modprobe lirc_odroid gpio_out_pin=24 softcarrier=1 invert=1
$ service lircd restart
4. ODROID-C1/C1+ Example

Supposing to use Pin#7 of ODROID-C1/C1+ (GPIO #83),

$ service lircd stop
$ modprobe lirc_dev
$ modprobe lirc_odroid gpio_out_pin=83 softcarrier=1 invert=1
$ service lirc restart


If you have the warning No such device during modprobe lirc_odroid,
check if the gpio_out_pin is already assigned to another purpose and change to another pins.


Send IR code using 'irsend'

If lirc_odroid module has been loaded and lirc service is running normally, you can get the key list as following.
Please make sure the remote name is same with the name described in /etc/lirc/lircd.conf.d/hk.lircd.conf.

$ irsend LIST odroid ""
irsend: 0000000000009966 KEY_LEFT
irsend: 000000000000837c KEY_RIGHT
irsend: 00000000000053ac KEY_UP
irsend: 0000000000004bb4 KEY_DOWN
irsend: 000000000000738c KEY_ENTER
irsend: 00000000000041be KEY_HOME
irsend: 00000000000011ee KEY_MUTE
irsend: 000000000000a35c KEY_MENU
irsend: 00000000000059a6 KEY_BACK
irsend: 000000000000817e KEY_VOLUMEDOWN
irsend: 00000000000001fe KEY_VOLUMEUP
irsend: 0000000000003bc4 KEY_POWER

irsend is basic LIRC program to send the key code.

$ irsend SEND_ONCE odroid KEY_ENTER

For more detailed information, please refer to this link.
http://www.lirc.org/html/irsend.html

Please note that some parts in lirc_options.conf depend on the toolchain version,
so select the correct conf file among the following references based on your board.

lirc_options.conf for ODROID-C2 and ODROID-N2

lirc_options.conf
# These are the default options to lircd, if installed as
# /etc/lirc/lirc_options.conf. See the lircd(8) and lircmd(8)
# manpages for info on the different options.
#
# Some tools including mode2 and irw uses values such as
# driver, device, plugindir and loglevel as fallback values
# in not defined elsewhere.
 
[lircd]
nodaemon        = False
driver          = default 
device          = /dev/lirc0 
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/aarch64-linux-gnu/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600
#effective-user =
#listen         = [address:]port
#connect        = host[:port]
#loglevel       = 6
#release        = true
#release_suffix = _EVUP
#logfile        = ...
#driver-options = ...
 
[lircmd]
uinput          = False
nodaemon        = False
 
# [modinit]
# code = /usr/sbin/modprobe lirc_serial
# code1 = /usr/bin/setfacl -m g:lirc:rw /dev/uinput
# code2 = ...
 
 
# [lircd-uinput]
# add-release-events = False
# release-timeout    = 200
# release-suffix     = _EVUP

lirc_options.conf for ODROID-XU4 and ODROID-C1

lirc_options.conf
# These are the default options to lircd, if installed as
# /etc/lirc/lirc_options.conf. See the lircd(8) and lircmd(8)
# manpages for info on the different options.
#
# Some tools including mode2 and irw uses values such as
# driver, device, plugindir and loglevel as fallback values
# in not defined elsewhere.
 
[lircd]
nodaemon        = False
driver          = default 
device          = /dev/lirc0 
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/arm-linux-gnueabihf/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600
#effective-user =
#listen         = [address:]port
#connect        = host[:port]
#loglevel       = 6
#release        = true
#release_suffix = _EVUP
#logfile        = ...
#driver-options = ...
 
[lircmd]
uinput          = False
nodaemon        = False
 
# [modinit]
# code = /usr/sbin/modprobe lirc_serial
# code1 = /usr/bin/setfacl -m g:lirc:rw /dev/uinput
# code2 = ...
 
 
# [lircd-uinput]
# add-release-events = False
# release-timeout    = 200
# release-suffix     = _EVUP

hk.lircd.conf

hk.lircd.conf
begin remote
 
name odroid
bits 16
flags SPACE_ENC|CONST_LENGTH
eps  30
aeps 100
 
header 9000 4500
one 563 1688
zero 563 564
ptrail 563
pre_data_bits 16
pre_data 0x4DB2
repeat 9000 2250
gap 100000
toggle_bit_mask 0x0
    begin codes
        KEY_LEFT  0x9966
        KEY_RIGHT  0x837C
        KEY_UP  0x53AC
        KEY_DOWN  0x4BB4
        KEY_ENTER  0x738C
        KEY_HOME  0x41BE
        KEY_MUTE  0x11EE
        KEY_MENU  0xA35C
        KEY_BACK  0x59A6
        KEY_VOLUMEDOWN  0x817E
        KEY_VOLUMEUP  0x01FE
        KEY_POWER  0x3BC4
    end codes
end remote

If the default node /dev/lirc0 is already occupied for IR receiver and you want to use the both functionalities,
please try the following instruction.

ex) ODROID-C2 case

$ ls /dev/lirc*
/dev/lirc0
 
$ modprobe lirc_odroid gpio_out_pin=247 softcarrier=1 invert=1
$ ls /dev/lirc*
/dev/lirc0  /dev/lirc1
$ lsmod
Module                  Size  Used by
lirc_odroid             4988  0
ir_lirc_codec           4934  0
lirc_dev               10879  2 lirc_odroid,ir_lirc_codec
ir_mce_kbd_decoder      3402  0
ir_sanyo_decoder        1657  0
ir_sony_decoder         1663  0
ir_jvc_decoder          1725  0
ir_rc6_decoder          2010  0
ir_rc5_decoder          1586  0
ir_nec_decoder          1789  0
.....
.....
$ lircd --driver=default --device=/dev/lirc1 --output=/var/run/lirc/lirc1 --pidfile=/var/run/lirc/lirc1.pid
$ ls /var/run/lirc
lirc0  lirc0.pid  lirc1  lirc1.pid  lircd  lircd.pid  lircm
$ irsend LIST "" odroid
$ irsend SEND_ONCE odroid KEY_POWER -d /var/run/lirc/lirc1