2016年11月27日日曜日

[Raspberry Pi 3] 赤外線を受信する

Raspberry PIでエアコンをつけてみようと思ったので、まずは赤外線を受信するところから始めてみる。
受信にはさっき秋月電子で買って来た赤外線リモコン受信モジュール PL-IRM0101(38kHz)シールド付を使う。
なんだか他にも色々と赤外線受信モジュールはあった中から、これを選んだ理由は特にない。

まずは、lircをインストールする。
# apt-get install lirc

/boot/condig.txtに下記を設定を追加する
dtoverlay=lirc-rpi,gpio_in_pin=21

設定したらラズパイの再起動。
したら、受信させる。
$ mode2 -d /dev/lirc0

モジュールにむかってリモコンから赤外線を飛ばして↓のようにpulseとspaceが流れていけば、受信は成功している。
space 441
pulse 416
space 1300
pulse 416
space 442
pulse 416
space 1300
pulse 416
space 1300
pulse 416

次にリモコンの信号を記録する。
# irrecord -n -d /dev/lirc0 aircon.conf

・・・
Please send the finished config files to  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.
..irrecord: no data for 10 secs, aborting
irrecord: gap not found, can't continue
あれ、上手く行かないな。