IR - 傳送 IR NEC 原始數據並解碼

材料準備

  • AmebaD [AMB21 / AMB22 / AMB23 / BW16 ] x 2

  • Grove – 紅外線發射器 x1 (Figure 1)

  • Grove – 紅外線接收器 x1 (Figure 2)

範例説明

在此範例中,我們使用兩個Ameba RTL8722模塊,它們分別與紅外線(IR)發射器和IR接收器連接,以發送和接收IR NEC 原始數據。

../../../../_images/image11.jpeg

圖一: Grove – 紅外線發射器

../../../../_images/image253.png

圖二: Grove – 紅外線接收器

在發送端,發送器將發送IR NEC原始數據。 原始數據可以看作是 “marks” 和 “spaces”(圖三)的連續持續時間(以微秒(us)為單位)。

  • Mark: 特定時間發送脈衝

  • Space: 特定時間不發送脈衝

../../../../_images/image335.png

圖三: 典型的紅外線發射和接收設置實作

有關更多詳細信息,請參閱SB-Projects的主題 IR Remote Control Theory 學習IR遙控器操作的理論以及IR協議說明。 在此範例中,我們將使用NEC(Now Renesas,也稱為日語格式)作為傳輸協議。」

NEC 特色
  • 8位元地址和8位元命令長度。

  • 具擴展模式,地址長度加倍。

  • 為了確保可靠性,發送兩次地址和命令。

  • 調節脈衝距離。

  • 載波頻率為38kHz。

  • Bit Time為1.125ms或2.25ms。

Modulation NEC protocol uses Pulse Distance Encoding of the bits for data communication (Figure 4). A logical “1” is represented by total duration of 2250us, with 560us of “marks” and (2250-560) us of “spaces”. While logical ”0” is represented by total duration of 1120us, with 560us “marks” and (1120-560) us of “spaces”.

../../../../_images/image427.png

圖四: NEC 調節

由於總共將傳輸32位元數據包含標頭和結束位元 (圖五)。如果我們在時間範圍內拆開數據,將有(2 + 32)x 2 +1 = 69個要傳輸的 “ marks ” / “ spaces ”(圖六),形成原始NEC數據在Arduino “ *.ino ” 文件中進行傳輸。關於如何獲得原始數據代碼的細節, 可以參考 Ken Shirriff’s 的 博客

../../../../_images/image519.png

圖五: 完整NEC數據的樣本(1或0)

../../../../_images/image69.png

圖六: NEC 原始完整數據的樣本(us)

圖七和圖八顯示了AMB21 / AMB22板的紅外發射器和接收器的引腳配置。

../../../../_images/image77.png

圖七: 紅外發射器和AMB21 / AMB22的引腳配置

../../../../_images/image85.png

圖八: 紅外接收器和AMB21 / AMB22的引腳配置

图九和图十显示了BW16板的红外发射器和接收器的引脚配置。

../../../../_images/image7-2.png

图十一: 红外发射器和BW16的引脚配置

../../../../_images/image8-2.png

Figure 10: Pin configuration of IR Receiver and BW16-TypeC

Figure 11 and Figure 12 shows the pin configuration of IR Emitter and Receiver with BW16-TypeC.

../../../../_images/image93.png

Figure 11: Pin configuration of IR Emitter and BW16-TypeC

../../../../_images/image9-2.png

Figure 12: Pin configuration of IR Receiver and BW16-TypeC

After the connection is being set up correctly, we will move to the coding part for this example. First, make sure the correct Ameba development board is selected in Arduino IDE: “Tools” → “Board”.

Open the “IRSendRAW” example in “File” “Examples” “AmebaIRDevice” “IRSendRAW” (Figure 13) and upload to 1st board connected with IR Emitter:

../../../../_images/image103.png

Figure 13: Example Location of IRSendRaw and IRRecvNEC

After successfully upload the sample code for IRSendRaw, you might need to upload the IRRecvNEC example for the 2nd board connected with IR Receiver from “File” “Examples” “AmebaIRDevice” “IRRecvNEC”.

After opening the serial monitor on the IR Receiver side and press the reset buttons on two boards, the data “48” will be received every 3 seconds (due to the delays () function, not compulsory to wait). After decoding the signal from the receiving Pin D8 and transmitting Pin D9 with Logic Analyser and Pulse View (Figure 14), the result is also shown as “48” after decoding the receiving data with IR NEC Protocol.

../../../../_images/image1112.png

Figure 14: Pulse View results from sending and receiving pin

程式碼説明

[1] Seeed Official website for Grove – Infrared Receiver https://wiki.seeedstudio.com/Grove-Infrared_Receiver/

[2] Seed Official website for Grove – Infrared Emitter https://wiki.seeedstudio.com/Grove-Infrared_Emitter/

[3] Ken SHirriff’s blog on A Multi-Protocol Infrared Remote Library for the Arduino http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

[4] SB-Projects: IR Remote Control Project https://www.sbprojects.net/knowledge/ir/index.php