1: 2018-04-05 (木) 06:40:06 yuji ソース
Line 1: Line 1:
 +#topicpath
 +* Raspberry Pi Zero WにRPZ-IR-Sensorを使って学習リモコンを作る [#rde78df1]
 +
 +Raspberry Pi Zero Wに,RPZ-IR-Sensorを使って学習リモコンを作ってみる。~
 +手持ちのパーツで自作しても良かったが,今回は,温度,湿度,気圧センサーも搭載されている[[RPZ-IR-Sensor>http://indoor.lolipop.jp/IndoorCorgiElec/RPZ-IR-Sensor.php]]を購入して使ってみることに。
 +
 +以前使用していた[[LIRC>http://lirc.org/]]を使って,学習リモコン機能を作ってみる。
 +
 +[[Raspbian Stretch>/PC/RaspberryPi/Linuxを動かしてみる/Raspbianのインストール]]が入っているRaspberry Pi Zero Wで,作業を行った。
 + $ lsb_release -a
 + No LSB modules are available.
 + Distributor ID: Raspbian
 + Description:    Raspbian GNU/Linux 9.4 (stretch)
 + Release:        9.4
 + Codename:      stretch
 +
 +** LIRCのインストール [#lca85cfa]
 +lircのPackageをインストールする。
 + # apt-get install lirc
 +
 +** LIRCの設定 [#eb919efe]
 +/boot/config.txtを以下のように編集する。
 +
 +''/boot/config.txt''
 + # Uncomment this to enable the lirc-rpi module
 + dtoverlay=lirc-rpi
 + dtparam=gpio_out_pin=13
 + dtparam=gpio_in_pin=4
 +
 +/etc/lirc/lirc_options.confを以下のように編集する。
 +
 +''/etc/lirc/lirc_options.conf''
 + [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
 +
 +編集が終わったらRaspberry Pi Zero Wを再起動する。
 +
 +lsmodでlircモジュールがロードされているか確認する。
 + $ lsmod | grep lirc
 + lirc_rpi                8001  2
 + lirc_dev                8313  1 lirc_rpi
 +
 +/dev/lirc0が作成されているか確認する。
 + $ ls -l /dev/lirc*
 + crw-rw---- 1 root video 243, 0  4月  3 14:55 /dev/lirc0
 +
 +** リモコン信号の受信の確認 [#s1957bb3]
 +リモコン信号を受信できるかどうか確認してみる。~
 +
 +lircdデーモンを一旦停止する。
 + # systemctl stop lircd.service
 +これしておかないと,mode2実行時にデバイス使用中のエラーとなる。
 +
 +リモコンの動作確認をする前に,mode2コマンドのバージョンを確認する。
 + $ mode2 -v
 + mode2 0.9.4c
 +
 +リモコン信号受光部に向けて,適当なリモコンからなんかのボタンを押して信号を送信してみる。~
 + $ mode2 -d /dev/lirc0
 + Using driver default on device /dev/lirc0
 + Trying device: /dev/lirc0
 + Using device: /dev/lirc0
 +
 + space 2610664                          <--- リモコン受光モジュールにリモコンを向けてボタンを押すと受信する
 + pulse 1202
 + space 476
 + pulse 1201
 + space 452
 + pulse 368
 + space 1215
 + pulse 364
 +  :
 +このようなメッセージが表示されれば,リモコン信号が受信出来ている。
 +数字は,一つのパターンの長さ(時間)を表している。
 +
 +** irrecordでリモコンデータを学習する [#l8528e74]
 +リモコンデータを学習するので,デーモンを停止しておく。
 + # systemctl stop lircd.service
 +
 +TVのリモコンを学習してみる。
 + $ irrecord -n -f -d /dev/lirc0
 + Using raw access on device /dev/lirc0
 +  :
 + Press RETURN to continue.                                    <--- リターンを押す
 +
 + Checking for ambient light  creating too much disturbances.
 + Please don't press any buttons, just wait a few seconds...
 +
 + No significant noise (received 0 bytes)
 +
 + Enter name of remote (only ascii, no spaces) :TV            <--- リモコン操作の名前(保存するファイル名)を入力
 + Using TV.lircd.conf as output filename
 +
 + Now start pressing buttons on your remote control.
 +  :
 + Press RETURN now to start recording.                        <--- リターンを押す
 +  :
 + Please enter the name for the next button (press <ENTER> to finish recording)
 + power                                                        <--- リモコンのボタン名powerを学習させる
 +
 + Now hold down button "power".                                <--- リモコンの電源ボタンを押す
 +
 + Please enter the name for the next button (press <ENTER> to finish recording)
 + volup                                                        <--- リモコンのボタン名volupを学習させる
 +
 + Now hold down button "volup".                                <--- リモコンのVolume↑ボタンを押す
 +
 + Please enter the name for the next button (press <ENTER> to finish recording)
 + voldown                                                      <--- リモコンのボタン名voldownを学習させる
 +
 + Now hold down button "voldown".                              <--- リモコンのVolume↓ボタンを押す
 +
 + Please enter the name for the next button (press <ENTER> to finish recording) <--- 学習終了の場合はリターン。
 +
 + Successfully written config file TV.lircd.conf
 +このようにして学習したリモコンデータを,/etc/lirc/lircd.conf.d/ にコピーする。
 + $ sudo cp TV.lircd.conf /etc/lirc/lircd.conf.d/
 +
 +エアコンのリモコンも一応学習できた。
 +
 +リモコンの定義データを確認する。
 + $ irsend LIST "" ""
 + devinput
 + devinput
 + TV
 +のように,devinputが2個表示された場合はうまくいかないので,devinput.lircd.confファイルを削除する。
 + # rm /etc/lirc/lircd.conf.d/devinput.lircd.conf
 +デーモンをリスタートする。
 + # systemctl restart lircd.service
 +
 +** リモコン信号の送信 [#d1dc34d0]
 +学習したリモコンデータを使って,なにか送信してみる。
 +- テレビをつけるデータを送信~
 + $ irsend SEND_ONCE TV power
 +うまく送信されれば,TVがONする。この時,リモコン送信中を示す赤色LEDが一瞬点灯する。
 +- テレビを切るデータを送信~
 + $ irsend SEND_ONCE TV power
 +
 +power信号は,テレビをOn/Offするトグル動作になる。(OnのためのデータやOffのためのデータは無い)
 +
 +ちなみに,リモコンデータを数回連続で送信したい場合は,
 + $ irsend -#5 SEND_ONCE TV volup
 +のようにする。(#の後に回数を指定する)


トップ   差分 バックアップ 複製 名前変更 リロード   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom
Counter: 1283, today: 1, yesterday: 1