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位元命令长度。

  • 具扩展模式,地址长度加倍。

  • 为了确保可靠性,发送两次地址和命令。

  • Pulse distance modulation.

  • 载波频率为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 调节

有关更多详细信息,请参阅SB-Projects的主题 IR Remote Control Theory 学习IR遥控器操作的理论以及IR协议说明。 在此范例中,我们将使用NEC(Now Renesas,也称为日语格式)作为传输协议。

../../../../_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