連假剛結束,今天學堂上哄哄隆隆,大家談著廟會、祭典、出遊的點點滴滴,好不熱鬧。就連學長來了,都還不知道,繼續機哩括啦的說 。
這學期的實習課已經結束,接下來的 專 題,可以自由報名參加。首先安排的是 視而不 見的 紅外線串講 。大家都知道實習 機板上有一個 IR TX 發射器,假使沒有 IR RX 接收器,也是枉然。為了鼓勵同學們的踴躍參與,除了發給接收器之外,還附贈紅外線遙控器一只,希望大家一起玩的個盡興。不過報名者得寫心得報告 文 章,將擇其優者參加明年之生生祭大賽,盼為小學堂增光。現在請大家到班長 M♪o 處登記,隨後正式開講。
☿☺ 竟然全班加入,看來這下學長可是虧大了耶!
生︰同學們不要被紅外線嚇到,雖說眼睛看不見,比方講,
,它 Pi-Noir 可是抓的住它。如從驅動原理上說,和發光二極體 LED 差異不大︰
因為一般家用遙控器所用的訊號『規範』 Protocol ,需要作高速的資料處理,所以通常不用『派生』 Python 直接操作。更由於應用與系統整合的考慮,因此早年就有了 Linux LIRC ── Linux Infrared Remote Control ── 專案,提供了方便的程式界面以及使用架構。現在就讓我們展開紅外線之旅的吧。
Driver Model
| +---------------------------------------------------------------+ S | | 'gpm -t msc -m /var/run/lirc/lircm' or a well configured X | O | | (see section 'Configuring lircmd') for details | F | +--------------+------------------------------------------------+ T | | W | /var/run/lirc/lircm (named pipe (FIFO) ==> one connection) A | | R | +-----------+-----------+ +----------------------------------+ E | | mouse daemon (lircmd) | | tools (irexec, irxevent, ...) | | | configured with | | configured with ~/.config/lircrc | | | lircmd.conf | | | | +-----------+-----------+ +-----------+----------------------+ | | | | +-------------+-------------+ | | | /var/run/lirc/lircd (socket → multiple connections) | | S | +----------------+--------------------------+ O | | decoder daemon (lircd), irrecord or mode2 | TCP/IP F | | lircd is configured through lircd.conf +--- port T | User space | | 8765 W | +------------------+------------------------+ A | | | R | | | E | | | | | /dev/uinput (Linux input layer) | | | | +---------------------------------+---------------------------------- | Kernel space | (character device | | driver → | +------------+----------+ one connection) | | | | /dev/lirc /dev/ttySx | | | | +------------+-------------+ +-----+---------------+ | | LIRC device driver | | Linux serial driver | | | (with ioctl-interface) | | | | +------------+-------------+ +----------+----------+ | | | --+--------------------+----------------------------+------------------ | | | | +----------+------------+ | | | | | | +-------+----------------+ +----+-----+ +-------+-----------------+ H | | serial / parallel port | | TV cards | | Irman/RemoteMaster/etc. | W | +------------------------+ +----------+ +-------------------------+ | Formats
|
△ IR protocol analyzer
IR protocol analyzer is a universal application for automatic decoding several types of infrared remote control protocol packets. The application uses microphone input of a soundcard to capture infrared signal from a remote control. As a consequence, the hardware receiver is minimalistic and easy to build; just plug a phototransistor to input of your soundcard, that’s all hardware you need.
Application processes IR signal from a remote control and compares it with its own database of known protocols. When a match is found, packet is decoded and its characteristic is displayed to user (including protocol name, description, decoded data and graph with timing).
Protocol definitions are stored in separate XML file. This XML file can be easily modified and new protocol definitions can be added by user. When an unknown packet is captured, user may still display its graph with timing details. Then, on the basis of the graph and timing, he may create new protocol description.
IR protocol analyzer – screenshot
Documentation
- User’s manual (pdf, 512 kB)
- Analýza protokolu dálkového ovladače – rozbor zápočtové úlohy (pdf, 630 kB)
Download
- IR protocol analyzer v1.1 (315 kB)
- IR protocol analyzer v1.0 (313 kB)
- Latest protocol definition file 2012-01-25 (XML, 11kB)
Licence
You can use this program for free. If you find the program useful, please consider making a donation via PayPal.
…
△ Theory
The ProtocolAnalyzer constantly samples the analog input signal, trying to recreate any digital pulses found in the signal. The so called flank detector uses a quite simple algorithm to find the flanks of the pulses:
Find sequences where the sampled value changed significanlty (Flank Swing) over a short period of time (Flank Length)
To avoid the same flank being counted twice if it is large, we wait a while (Flank Holdoff) after finding a flank until we accept a new flank. This picture shows the meaning of the settings on a real sampled signal. The red line is the analog value (where the sample points are marked with black dots). The blue line is the flank detectors interpretation of the signal:
In the example Flank Swing was set at 50 and Flank Length set to 3, so when the signal changed more than 50 over 3 samples, the flank was detected (see the blue line). Note that the signal changed more than 50 in the following samples as well, but since this was within Flank Holdoff, this was not counted.
……
△ 軟體安裝以及設定
【安裝】
sudo apt-get install lirc liblircclient-dev sudo apt-get install python-lirc python3-lirc
在 /boot/config.txt 的檔案底增加一行︰
dtoverlay=lirc-rpi,gpio_in_pin=9,gpio_out_pin=12
在 //etc/modules 的檔案底增加兩行︰
lirc_dev
lirc_rpi gpio_in_pin=9 gpio_out_pin=12
【設定】
將 /etc/lirc/hardware.conf 修改成︰
pi@raspberrypi ~
給定遙控器之 /etc/lirc/lircd.conf 檔案內容︰
pi@raspberrypi ~
【測試】
安裝好 IR 接收器,執 行 irw ,
IRW(1) User Commands IRW(1)
NAME
irw – sends data from Unix domain socket to stdout
SYNOPSIS
irw [socket]
DESCRIPTION
irw will connect to any Unix domain socket and will print the data that it receives to stdout. If you don’t give it a socket name argument it will watch
/var/run/lirc/lircd. Useful for debugging.
-h –help
display usage summary
-v –version
display version
SEE ALSO
The documentation for lirc is maintained as html pages. They are located under html/ in the documentation directory.
irw 0.9.0-pre1 October 2010
,對準 IR 接收器操作遙控器,結果類似如下︰
pi@raspberrypi ~ $ irw 0000000000fd08f7 00 KEY_1 /home/pi/lircd.conf 0000000000fda05f 00 KEY_UP /home/pi/lircd.conf 0000000000fd00ff 00 KEY_VOLUMEDOWN /home/pi/lircd.conf 0000000000fd00ff 01 KEY_VOLUMEDOWN /home/pi/lircd.conf 0000000000fd00ff 02 KEY_VOLUMEDOWN /home/pi/lircd.conf 0000000000fd40bf 00 KEY_VOLUMEUP /home/pi/lircd.conf 0000000000fd40bf 01 KEY_VOLUMEUP /home/pi/lircd.conf 0000000000fdb04f 00 KEY_DOWN /home/pi/lircd.conf 0000000000fdb04f 01 KEY_DOWN /home/pi/lircd.conf
碼︰會 習。☿ 長︰同學們請安靜。也許有人還忙著安裝以及驗證紅外線的軟體程式。先發下今天的講義︰
‧ 數碼管討論摘要。
‧入出針文法大綱。
‧試作程式。
請大家回顧瞻前,稍候開始會習。
誰知同學們對那個『入出針語言』興奮莫名,討論的意外熱烈,直到時間已近傍晚,還興致高昂。縱使深感大家的熱情,實在難以記其要,勉強摘記︰
‧一開始顯示 1234 ,沒有什麼意思!該將實習 機板命名,用個代表大家的符號,彰顯小學堂彼此間的友情。
‧派生停止執行緒的辦法,聽說可以將之設定為 daemon 。
‧要是加入 IRTX 與 IRRX 就更好玩了。
‧變元只能記數值,不知道可不可以擴增函元 Functional 的呢?
‧蜂鳴器的禁音文法不好用。
‧……