【ラズパイ】lircを使用した赤外線信号のトレースと送信

動いた。😄

lircのインストール

$ sudo apt-get install lirc

/boot/config.txtを書き換える。

今回は受信信号をGPIO21、赤外線LEDをGPIO20に接続しています。

# Uncomment this to enable infrared communication.
dtoverlay=gpio-ir,gpio_pin=21
dtoverlay=gpio-ir-tx,gpio_pin=20

/etc/lirc/lirc_options.confを書き換える。

まずはリモコンの信号を受信してデータを取るので、deviceは/dev/lirc1を記入する。

[lircd]
nodaemon        = False
driver          = default
device          = /dev/lirc1

lircdを一時停止。

$ sudo service lired stop

リモコンの信号を読み取る。

以下のコマンドを入力後、リモコンのボタンを押す。

今回は音量UPのボタンを押してみた。

mode2 -d /dev/lirc1 > volup.txt

volup.txtには、いかの様に出力されました。

space 16777215
pulse 9059
space 4508
pulse 632
space 501
pulse 635
space 506
pulse 681
space 455
pulse 682
space 456
pulse 630
space 505
pulse 632
space 505
pulse 584
space 1684
pulse 681
space 455
pulse 584
space 1684
pulse 584
space 1684
pulse 584
space 1684
pulse 585
space 1684
pulse 585
space 1685
pulse 640
space 1581
pulse 689
space 1627
pulse 611
space 524
pulse 611
space 1658
pulse 615
space 523
pulse 615
space 1655
pulse 614
space 522
pulse 615
space 1655
pulse 613
space 1654
pulse 614
space 524
pulse 613
space 527
pulse 609
space 525
pulse 611
space 1658
pulse 588
space 549
pulse 608
space 1660
pulse 589
space 548
pulse 589
space 548
pulse 589
space 1679
pulse 592
space 1677
pulse 590
space 1675
pulse 594
pulse 13407
space 63383
space 40258
pulse 9119
space 2190
pulse 643
pulse 21195
space 121207
space 97010
pulse 9169
space 2141
pulse 688
pulse 22186

このデータの中から、一番最初の

space 16777215

と、後半の

pulse 13407
space 63383
space 40258
pulse 9119
space 2190
pulse 643
pulse 21195
space 121207
space 97010
pulse 9169
space 2141
pulse 688
pulse 22186

の部分は、いらないデータなので削除。

※基本的にpulseから始まり、pulse→space→pulse→・・・と続くので、データの数は必然的に奇数となる。なので、それに当てはまらない部分は余計なデータ。

/etc/lirc/lircd.conf.d/配下に、任意の名前.confでファイルを作成。

$ vi /etc/lirc/lircd.conf.d/tv.conf

ファイルの中身はこんな感じ。

begin remote
 name tv
 flags RAW_CODES
 eps 30
 aeps 100
 gap 200000
 toggle_bit_mask 0x0

 begin raw_codes
 name volup
 9059 4508 632 501 635 506 681 455 682 456 630 505 632 505 584 1684 681
 455 584 1684 584 1684 585 1684 585 1685 640 1581 689 1627 611 524 611 1658 615
 523 615 1655 614 522 615 1655 613 1654 614 524 613 527 609 525 611 1658
 588 549 608 1660 589 548 589 548 589 1679 592 1677 590 1675 594

 name voldown
 9087 4478 609 526 588 550 609 527 588 549 609 526 610 527 608 1659 611
 526 610 1659 608 1658 612 1661 606 1658 608 1660 607 1660 611 526 611 1658 610
 527 609 1659 610 1658 608 1659 609 1662 606 528 608 528 608 530 610 1658
 608 528 608 530 608 526 610 529 608 1658 609 1659 608 1657 610
 end raw_codes
end remote

2行目のnameはファイル名と合わせた方が混乱が少ない。

begin raw_codesの中にname コマンド名を記入し、次の行に信号データのみを羅列。※エディターの置換機能を使えば簡単

赤外線を送信する。

/etc/lirc/lirc_options.confを書き換える。

送信を行うので、lirc0に書き換える。

[lircd]
nodaemon        = False
driver          = default
device          = /dev/lirc0

lircdを起動。

$ sudo service lired start

confの中身にエラーがあれば以下のコマンドでエラーが出力される。

$ sudo systemctl status lircd.service

以下のコマンドで作成したファイルが見えればOK。

$ irsend LIST '' ''

devinput-32
devinput-64
tv

赤外線LEDをテレビに向けて、コマンドを入力する。

$ irsend SEND_ONCE tv volup
$ irsend SEND_ONCE tv voldown

ようやくテレビが反応してくれました。

参考にしたサイト。

https://deviceplus.jp/hobby/entry_y18/

http://yukidfg.jpn.ph/2018/02/23/%E3%83%A9%E3%82%BA%E3%83%91%E3%82%A4%E3%82%92%E8%B5%A4%E5%A4%96%E7%B7%9A%E3%83%AA%E3%83%A2%E3%82%B3%E3%83%B3%E3%81%AB%E3%81%97%E3%81%A6%E5%AE%B6%E9%9B%BB%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B/

「【ラズパイ】lircを使用した赤外線信号のトレースと送信」への2件のフィードバック

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください