Orange Pi PC + Armbian IR Setting (LIRC)

Orange Pi PCのIRリモートを有効にします。

:white_check_mark: 以下のカーネルモジュールの読込みとハードウェアの設定(gpio設定)は armbian-config で可能です。

Armbian comes with both sunxi_ir_rx (Jernej’s backported OpenELEC version) and sunxi_cir and none is loaded by default.
—>
ArmbianではデフォルトでIRのカーネルモジュールは読み込まれていないようです。
IRモジュールとしてsunxi_ir_rxとsunxi_cirの2種類存在しますが、sunxi_cirをロードします。

現在ロードされているモジュールは、以下コマンドで確認できます。

$ lsmod

モジュールsunxi_cirのロードには幾つか手順があります。

初めに、lircはデフォルトでインストールされておりサービスデーモンとして起動しているため一旦停止します。

$ sudo service lirc stop

1./etc/modulesの設定

/etc/modules内にsunxi_cirを追加することで起動時にモジュールがロードされます。

2./etc/lirc/hardware.confの設定

    ########################################################
    # /etc/lirc/hardware.conf
    #
    # Arguments which will be used when launching lircd
    LIRCD_ARGS="--uinput"

    # Don't start lircmd even if there seems to be a good config file
    # START_LIRCMD=false

    # Don't start irexec, even if a good config file seems to exist.
    # START_IREXEC=false

    # Try to load appropriate kernel modules
    LOAD_MODULES=true

    # Run "lircd --driver=help" for a list of supported drivers.
    DRIVER="default"
    # usually /dev/lirc0 is the correct setting for systems using udev
    DEVICE="/dev/lirc0"
    MODULES="sunxi_cir"

    # Default configuration files for your hardware if any
    LIRCD_CONF=""
    LIRCMD_CONF=""
    ########################################################

3.カーネルモジュールの読み込み(上記設定していれば必要ありません)

$ sudo modprobe sunxi_cir

IRシグナルを受信するかどうか確認します。

$ sudo mode2 -d /dev/lirc0

実行後リモコンの任意のボタンを押下。ターミナルにspace,pulse~が表示されれば受信できています。

既存の設定ファイルをバックアップし、元の設定ファイルを削除します。

$ sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf
$ sudo rm /etc/lirc/lircd.conf

lircの設定ファイルを以下の irrecord コマンドで作成します。(リモコンキーの割当)

割当できるキーネームは事前に $ irrecord --list-namespace で確認して下さい。

:white_check_mark: キーネームを任意(カスタムリモコンなど)に設定する場合、オプション -n を追加します。

irreocrd については次の返信記事で補足説明しています。

$ sudo irrecord -n -d /dev/lirc0 /etc/lirc/lircd.conf

lircを再起動

$ sudo service lirc start

irwコマンドで受信の確認をします。

LIRCのドキュメントは以下参照願います。

Raspbian-Jessieの場合は以下ファイルを編集してモジュールを追加、起動時に読み込むようにします。

$sudo vi /boot/config.txt

dtoverlay=lirc-rpi,gpio_in_pin=22,gpio_out_pin=23

ピン番号はGPIO番号を入力します。物理的なピン番号ではありません。

/etc/lirc/hardware.conf ファイルは MODULES= の部分を変更します。

    LIRCD_ARGS="--uinput"

    # Try to load appropriate kernel modules
    LOAD_MODULES=true

    # Run "lircd --driver=help" for a list of supported drivers.
    DRIVER="default"

    # usually /dev/lirc0 is the correct setting for systems using udev
    DEVICE="/dev/lirc0"
    MODULES="lirc_rpi"

再起動します。

irrecordについて補足説明です。repeat codeが取得できないとリモコンのキーボタンを押し続けてもキー入力がカウントされません。必ずrepeat codeが取得できているかどうか確認して下さい。取得できると任意のキー入力読取り後header, trail pulseと共に表示され、最後にChecking for toggle bit maskが表示されます(下記irrecordフロー参照)。

irrecordでの注意点は以下の通りです。

(1)キー学習で学習されるキーを押しますが、押す毎にドットが表示されます。ドットが10以上になるとrepeat codeやheaderなどを読み取ることができないようです。目安は1秒押し続けてリリースで、ドットの長さが指定長2x80になるまでキー押しキーリリースを繰り返します。
例)キー1を1秒押してドットが約3個表示されキーをリリース。次にキー2を1秒押して…。次にキー3を1秒押して…。 まだドットが指定長にならないので、再びキー1を1秒押して…。を繰り返します。

(2)上記(1)と同じ操作をします(下記irrecordのフロー参照)。この操作ではキー入力1回押下で1ドットのみ表示します。押し続けてもドットは増えないので数回同じキーを押下して下さい。

(3)最後のChecking for toggle bit maskでは同じキー(任意)を何回も押して下さい。押し続けるのではなく押してリリースを繰り返します。no toggle bit maskとなっていますがこれでいいようです。

(4)irwで必ずキーがリピートされているか確認します。キーを押し続けると以下のようにカウントアップして改行表示されます。

0000000000ffe01f 00 vol- car_mp3_remote
0000000000ffe01f 01 vol- car_mp3_remote
0000000000ffe01f 02 vol- car_mp3_remote
0000000000ffe01f 03 vol- car_mp3_remote
0000000000ffe01f 04 vol- car_mp3_remote

以下irrecordのフローです。rawデータでの読取りはしないようにします。

irrecord -n -d /dev/lirc0 /etc/lirc/lircd.conf

Please send the finished config files to <[email protected]> so that I
can make them available to others. Don't forget to put all information
that you can get about the remote control in the header of the file.

Press RETURN to continue.


Now start pressing buttons on your remote control.

It is very important that you press many different buttons and hold them
down for approximately one second. Each button should generate at least one
dot but in no case more than ten dots of output.
Don't stop pressing buttons until two lines of dots (2x80) have been
generated.

Press RETURN now to start recording.--->(1)参照
................................................................................
Found const length: 139005
Please keep on pressing buttons like described above.--->(2)参照
................................................................................
Space/pulse encoded remote control found.
Signal length is 67.
Found possible header: 8876 4438
Found trail pulse: 537
Found repeat code: 8881 2213
Signals are space encoded.
Signal length is 32
Now enter the names for the buttons.

Please enter the name for the next button (press <ENTER> to finish recording)
ch-

Now hold down button "ch-".

Please enter the name for the next button (press <ENTER> to finish recording)
ch

Now hold down button "ch".

Please enter the name for the next button (press <ENTER> to finish recording)
ch+

Now hold down button "ch+".

Please enter the name for the next button (press <ENTER> to finish recording)
prev

Now hold down button "prev".

Please enter the name for the next button (press <ENTER> to finish recording)
next

Now hold down button "next".

Please enter the name for the next button (press <ENTER> to finish recording)
pause

Now hold down button "pause".

Please enter the name for the next button (press <ENTER> to finish recording)
vol-

Now hold down button "vol-".

Please enter the name for the next button (press <ENTER> to finish recording)
vol+

Now hold down button "vol+".

............................................................

Please enter the name for the next button (press <ENTER> to finish recording)
9

Now hold down button "9".

Please enter the name for the next button (press <ENTER> to finish recording)

Checking for toggle bit mask.--->(3)参照
Please press an arbitrary button repeatedly as fast as possible.
Make sure you keep pressing the SAME button and that you DON'T HOLD
the button down!.
If you can't see any dots appear, then wait a bit between button presses.

Press RETURN to continue.
..............................
No toggle bit mask found.

最新の /etc/lirc/hardware.conf による設定ファイルは以下の通りです。

# /etc/lirc/hardware.conf
#
#Chosen Remote Control
REMOTE="car_remote"
REMOTE_MODULES="sunxi_cir" ここを指定
REMOTE_DRIVER="default"  ここを指定
REMOTE_DEVICE="/dev/lirc0" ここを指定
REMOTE_SOCKET=""
REMOTE_LIRCD_CONF="/etc/lirc/lircd.conf" ここを指定
REMOTE_LIRCD_ARGS="--uinput" ここを指定

#Chosen IR Transmitter
TRANSMITTER="None"
TRANSMITTER_MODULES=""
TRANSMITTER_DRIVER=""
TRANSMITTER_DEVICE=""
TRANSMITTER_SOCKET=""
TRANSMITTER_LIRCD_CONF=""
TRANSMITTER_LIRCD_ARGS=""

#Disable kernel support.
#Typically, lirc will disable in-kernel support for ir devices in order to
#handle them internally.  Set to false to prevent lirc from disabling this
#in-kernel support. 
#DISABLE_KERNEL_SUPPORT="true"

#Enable lircd
START_LIRCD="true"  ここを指定

#Don't start lircmd even if there seems to be a good config file
#START_LIRCMD="false"

#Try to load appropriate kernel modules
LOAD_MODULES="true"

# Default configuration files for your hardware if any
LIRCMD_CONF=""

#Forcing noninteractive reconfiguration
#If lirc is to be reconfigured by an external application
#that doesn't have a debconf frontend available, the noninteractive
#frontend can be invoked and set to parse REMOTE and TRANSMITTER
#It will then populate all other variables without any user input
#If you would like to configure lirc via standard methods, be sure
#to leave this set to "false"
FORCE_NONINTERACTIVE_RECONFIGURATION="false"
START_LIRCMD=""

ARMBIAN 5.70 stable Debian GNU/Linux 9 (stretch) 4.19.13-sunxi

lirc/stable,now 0.9.4c-9 armhf [installed]

上記システムにデフォルトでインストールされているバージョンでは、幾つかの設定ファイルの中の一つである、従来の hardware.conflirc_options.conf に置き換わっています。

A10 : Configuration files
The lirc configuration is mostly done in the lirc config directory, usually /etc/lirc. Besides this, there are occasionally needs to configure the kernel drivers using files in /etc/modprobe.d.

       /etc
        |
        |
        |---lirc
        |     |
        |     |-----------  lirc_options.conf
        |     |
        |     |-----------  lircrc(irexec.lircrc)
        |     |
        |     |-----------  lircd.conf
        |     |
        |     |-----------  lircd.conf.d
        |                       |
        |                       |------- remote1.lircd.conf
        |                       |
        |                       |------- remote2.lircd.conf
        |
        |---modprobe.d
                |
                | --------- blacklist-xxx.conf
                |
                | ----------options-xxx.conf

     $HOME
       |
       |----.config
                |
                |-----------lircrc(irexec.lircrc)

The files:

  • lirc_options.conf holds the lircd options. This includes driver, port and other important configuration. All of these options can be overridden on the lircd command line.
  • lircd.conf contains timing information. It’s used by lircd to convert raw data from the kernel to key symbols. As shipped, the lircd.conf is empty and just includes any configuration file in lircd.conf.d.
  • lircd.conf.d contains all used remote configuration files. When receiving data lircd will try to decode it, trying each of these files.
  • /etc/lirc/lircrc is an optional default lircrc file. Debian Stretch では、irexec.serviceirexec.lirrcをデフォルトの設定ファイルとしているようです。
  • modprobe.d/blacklist-*. These contains a single blacklist directive used to disable kernel drivers which conflicts with lirc’s driver.
  • modprobe.d/options-*. Contains kernel module options e. g., which serial port the lirc_serial module should use.
  • $HOME/.config/lircrc is the main lircrc file. Many applications supporting LIRC have specific paths to their lircrc files.

:white_check_mark: /etc/lirc/lirc_options.conf 内で driverdevice の項目を変更します。

    # 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          = devinput
    driver          = default
    #device          = auto
    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
    #uinput         = ...
    #release        = ...
    #logfile        = ...

    [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]
    # release-timeout = 200

再起動後IRシグナルを受信するかどうか確認します。

$ sudo mode2 -d /dev/lirc0

実行後リモコンの任意のボタンを押下。ターミナルにspace,pulse~が表示されれば受信できています。

.....
.....
pulse 552
space 1704
pulse 552
space 576
pulse 584
space 1672
.....
.....
timeout 124928

リモコンキーの登録(デバイスとドライバはlirc_options.confとの整合性をとること。省略可)

設定ファイルは作業ディレクトリに作成されるため、作成後/etc/lirc/lircd.conf.dにコピーしてlircdを再起動すること。

$ sudo irrecord -d /dev/lirc0 -H default

:bangbang: 設定ファイルの各キーに0x00000000が割当てられるバグ。削除すること。

設定ファイルの内容が反映されているかどうかの確認は、

$ sudo irw

mplayerの起動、シェルコマンドの実行など irexec によるリモコンボタンスイッチの機能設定は /etc/lirc/irexec.lircrc ファイルで行います。

mplayer, vlcなどlircに対応しているアプリ毎のボタンスイッチの機能設定は /etc/lirc/lircrc ファイルで行います。

以下は、/etc/lirc/lircrc 内でアプリ毎(mplayervlc)に機能設定を振分けている例です。各アプリのスイッチ機能設定は /etc/lirc/mplayer, /etc/lirc/vlc 内で行っています。

    # Sample mplayer lircrc configuration.

    # This config assumes an MCE remote.  You may need to change the button names
    # if you have a different remote.  Use the irw command to find the names for
    # your remote's buttons.
    #
    # To use this config, paste it to the end of your ~/.lircrc (create the file if
    # it doesn't exist).

    include "/etc/lirc/vlc"
    include "/etc/lirc/mplayer"

リモコンボタンをトグルボタンとして利用する場合

irexecの設定ファイル irexec.lircrcconfigによる複数の実行コマンドを記述し、flagsオプションtoggle_resetを指定します。

begin
  prog = irexec
  button = key1
  config = echo 255 > /sys/class/leds/orangepi:red:status/brightness
  config = echo 0 > /sys/class/leds/orangepi:red:status/brightness
  repeat = 0
  flags = toggle_reset
end

設定を読み込むためirexecを再起動します。

$ sudo service irexec restart

上記は、 “key1” を押す毎にOrangepi PC上の赤色LEDがオン・オフする設定です。

Linux orangepipc 5.10.21-sunxi #21.02.3 SMP Mon Mar 8 00:28:04 UTC 2021 armv7l GNU/Linux

:white_check_mark: armbian-configによるモジュールロード

本記事投稿時点でのOrangepiPC版Armbianでは、armbian-configによりIRセンサやGPIOピンなど、付属するハードのモジュールをロードします。

$ sudo armbian-config

スペースキーで有効・無効の切り換えが出来ます。

モジュールの確認は、

$ lsmod
.....
sunxi_cir              20480  0
rfkill                 20480  4 cfg80211
industrialio           53248  1 sun4i_gpadc_iio
gpu_sched              28672  1 lima
xt_state               16384  0
sun8i_thermal          16384  0
sunxi_cedrus           32768  0
xt_conntrack           16384  1
v4l2_mem2mem           20480  1 sunxi_cedrus
videobuf2_dma_contig    20480  1 sunxi_cedrus
nft_counter            16384  3
videobuf2_memops       20480  1 videobuf2_dma_contig
videobuf2_v4l2         20480  2 sunxi_cedrus,v4l2_mem2mem
videobuf2_common       40960  3 sunxi_cedrus,v4l2_mem2mem,videobuf2_v4l2
nft_chain_nat          16384  4
w1_gpio                16384  0
.....

Linux orangepipc 5.10.21-sunxi #21.02.3 SMP Mon Mar 8 00:28:04 UTC 2021 armv7l GNU/Linux

irwコマンドによるテストでは、ボタン押下時の動作は確認できたが、irexecのサービスデーモンが無効となっていたため、リモコンによるvlcプレーヤの制御が出来ない不具合が発生。

irexecデーモンの起動時の状態を確認

$ sudo systemctl is-enabled irexec
disabled

:white_check_mark: 起動時に実行されるように設定

$ sudo systemctl enable irexec