Difference between revisions of "Matrix - IR Receiver"

From FriendlyELEC WiKi
Jump to: navigation, search
(Update Log)
 
(13 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
==Introduction==
 
==Introduction==
 
[[File:IR Receiver01.png|thumb|IR Receiver]]
 
[[File:IR Receiver01.png|thumb|IR Receiver]]
*Matrix-IR Receiver是38KHz红外接收模块,主要器件是一个红外接收头,可接收标准38KHz调制的遥控器信号,并放大和滤波输出,通过MCU编程,即可实现对遥控器信号的解码操作。
+
* The Matrix-IR receiver is a 38KHz infrared receiver that receives 38KHz signals from an infrared remote control, amplifies and filers them to other devices. Its signal decoding is implemented by programming MCU.
*接收范围:12-13米
+
* Transmission distance: 12 ~ 13 meters.
  
 
==Features==
 
==Features==
Line 26: Line 26:
  
 
==Basic Device Operation==
 
==Basic Device Operation==
*红外接收头内部包括红外监测二极管、放大器、限副器、带通滤波器、积分电路、比较器等。红外监测二极管检测到红外信号,然后把信号送到放大器和限幅器,限幅器把脉冲幅度控制在一定的水平,而不论红外发射器和接收器的距离远近。交流信号进入带通滤波器(带通滤波器可以通过30khz到60khz的负载波),再通过解调电路和积分电路进入比较器,比较器输出高低电平,还原出发射端的信号波形。
+
*The IR receiver contains a photo diode, amplifier, band pass filter, integrator, hysteresis comparator and etc. When the IR receiver detects infrared signals it sends them to the preamplifier and band pass filter. After the signals are processed by the band pass filter (30KHz ~ 60KHz) they will be further processed by the integrator and comparator and finally be output as High or Low.
*注意:输出的高低电平和发射端是反相的,这样的目的是为了提高接收的灵敏度。
+
*Note: the output signal is the reversal of the input signal.
  
 +
==Applications==
 +
===Connect to NanoPi M1===
 +
Refer to the following connection diagram to connect the module to the NanoPi M1:<br>
 +
[[File:Matrix-IR_Receiver_nanopi_m1.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_m1]]
 +
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-IR_Receiver || NanoPi M1
 +
|-
 +
|S    || Pin7
 +
|-
 +
|V    || Pin4
 +
|-
 +
|G    || Pin6
 +
|}
 +
 +
===Connect to NanoPi 2===
 +
Refer to the following connection diagram to connect the module to the NanoPi 2:<br>
 +
[[File:Matrix-IR_Receiver_nanopi_2.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_2]]
 +
 +
Connection Details
 +
{| class="wikitable"
 +
|-
 +
|Matrix-IR_Receiver || NanoPi 2
 +
|-
 +
|S    || Pin7
 +
|-
 +
|V    || Pin4
 +
|-
 +
|G    || Pin6
 +
|}
 +
 +
===Connect to NanoPi M2 / NanoPi 2 Fire===
 +
Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire:<br>
 +
[[File:Matrix-IR_Receiver_nanopi_m2.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_m2]]
 +
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-IR_Receiver || NanoPi M2
 +
|-
 +
|S    || Pin7
 +
|-
 +
|V    || Pin4
 +
|-
 +
|G    || Pin6
 +
|}
 +
 +
===Connect to NanoPC-T2===
 +
Refer to the following connection diagram to connect the module to the NanoPC-T2:<br>
 +
[[File:Matrix-IR_Receiver_NanoPC-T2.jpg|frameless|600px|Matrix-IR_Receiver_NanoPC-T2]]
 +
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-IR_Receiver || NanoPC-T2
 +
|-
 +
|S    || Pin15
 +
|-
 +
|V    || Pin29
 +
|-
 +
|G    || Pin30
 +
|}
 +
 +
==Compile & Run Test Program==
 +
Boot your ARM board with Debian and copy the matrix code:
 +
<syntaxhighlight lang="bash">
 +
$ apt-get update && apt-get install git
 +
$ git clone https://github.com/friendlyarm/matrix.git
 +
</syntaxhighlight>
 +
If your cloning is done successfully a "matrix" directory will be generated.
 +
 +
Compile and install Matrix:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ make && make install
 +
</syntaxhighlight>
 +
 +
Run test program:
 +
<syntaxhighlight lang="bash">
 +
$ matrix-ir_receiver
 +
</syntaxhighlight>
 +
Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.<br>
 +
Here is what you should observe:<br>
 +
<syntaxhighlight lang="bash">
 +
Press the IR remoter
 +
0: Type=4, Code=4, Value=3b0d
 +
1: Type=0, Code=0, Value=0
 +
2: Type=4, Code=4, Value=3b12
 +
3: Type=0, Code=0, Value=0
 +
4: Type=4, Code=4, Value=3b15
 +
5: Type=0, Code=0, Value=0
 +
</syntaxhighlight>
 +
When you point our RC-100 controller to it and press any key on the controller an event will be detected.
 +
 +
==Code Sample==
 +
This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-ir_receiver". Here is its source code:
 +
<syntaxhighlight lang="c">
 +
int main(int argc, char ** argv)
 +
{
 +
    int board, i, j;
 +
    int retSize = -1;
 +
    char *devName = GPIO_IR_DEV;
 +
    int pin = GPIO_PIN(7);
 +
    char modStr[BUF_SIZE];
 +
    struct input_event evKey;
 +
   
 +
    if ((board = boardInit()) < 0) {
 +
        printf("Fail to init board\n");
 +
        return -1;
 +
    }
 +
    if (board == BOARD_NANOPI_T2)
 +
        pin = GPIO_PIN(15);
 +
   
 +
    sprintf(modStr, "modprobe %s gpio=%d", DRIVER_MODULE, pintoGPIO(pin));
 +
    system(modStr);
 +
    signal(SIGINT, IRIntHandler);
 +
    sleep(1);
 +
    irFD = openHW(devName, O_RDWR);
 +
    if (irFD < 0) {
 +
        printf("Fail to open GPIO IR device\n");
 +
        goto err;
 +
    }
 +
    printf("Press the IR remoter\n");
 +
    for (i=0; i<IR_EVENT_TIMES; i++) {
 +
        if (selectHW(irFD, 0, 0) == 1) {
 +
            retSize = readHW(irFD, &evKey, sizeof(struct input_event));
 +
            for (j=0; j<(int) retSize / sizeof(struct input_event); j++)
 +
                printf("%2d: Type=%d, Code=%d, Value=%x\n", i, evKey.type, evKey.code, evKey.value);
 +
        }
 +
    }
 +
    closeHW(irFD);
 +
err:
 +
    system("rmmod "DRIVER_MODULE);
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
For more details about this APIs called in this code sample refer to [[Matrix API reference manual]] <br>
 +
 +
 +
<!---
 
==Download Matrix Source Code==
 
==Download Matrix Source Code==
  
All the matrix modules' code samples are open source. They are maintained on GitHub: git://github.com/friendlyarm/matrix.git <br>
+
All the matrix modules' code samples are open source. They are maintained on GitHub: https://github.com/friendlyarm/matrix.git <br>
 
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.<br>
 
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.<br>
 
* The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi
 
* The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi
Line 46: Line 188:
 
Clone the matrix code from GitHub
 
Clone the matrix code from GitHub
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ git clone git://github.com/friendlyarm/matrix.git
+
$ git clone https://github.com/friendlyarm/matrix.git
 
</syntaxhighlight>
 
</syntaxhighlight>
 
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
 
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
  
==与NanoPi 2连接使用==
+
==Connect to NanoPi 2==
===硬件连接===
+
===Hardware Connection===
参考下图连接模块Matrix-IR_Receiver和NanoPi 2:<br>
+
Please refer to the following connection diagram to connect the Matrix-IR_Receiver to the NanoPi 2:<br>
 
[[File:Matrix-IR_Receiver_nanopi_2.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_2]]
 
[[File:Matrix-IR_Receiver_nanopi_2.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_2]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 67: Line 209:
 
|}
 
|}
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到nanopi2分支
+
Please login the matrix hub and enter the nanopi2 branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 74: Line 216:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the Matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ make CROSS_COMPILE=arm-linux- clean
 
$ make CROSS_COMPILE=arm-linux- clean
Line 80: Line 222:
 
$ make CROSS_COMPILE=arm-linux- install
 
$ make CROSS_COMPILE=arm-linux- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为NanoPi 2配套的arm-linux-gcc-4.9.3。<br>
+
Note: please make sure to install the cross compiler "arm-linux-gcc-4.9.3" on your PC, which is used to compile files for the NanoPi 2.<br>
编译成功后库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下。<br>
+
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" directory. <br>
 +
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git <br>
  
===运行测试程序===
+
===Run Test Program===
将带有Debian系统的SD卡插入一台运行Linux的电脑,可以挂载SD卡上的boot和rootfs分区。<br>
+
Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.<br>
假设rootfs分区的挂载路径为/media/rootfs,执行以下命令将Matrix的硬件驱动、库文件和测试程序拷贝到NanoPi 2的文件系统上。<br>
+
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the module, library and test program to the card<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cp modules /media/rootfs/ -r
 
$ cp modules /media/rootfs/ -r
Line 92: Line 235:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
将SD卡重新插入NanoPi 2,上电启动,在Debian的shell终端中执行以下命令加载硬件驱动。<br>
+
Insert this TF card to your NanoPi 2, power on and run the following commands to load the driver<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd /modules
 
$ cd /modules
 
$ insmod matrix_ir_recv.ko
 
$ insmod matrix_ir_recv.ko
 
</syntaxhighlight>
 
</syntaxhighlight>
成功加载驱动后,会在/dev/input/目录下生成一个event设备节点,这里假设生成的设备节点为event1。<br>
+
If the driver is successfully loaded a device node will be generated under /dev/input/. In our test case the node was event1.<br>
  
开源软件input-utils可以读取event设备的数据,它的使用方法如下:<br>
+
There is an open source utility "input-utils" which can be used to read the event device's data. Here is how it works:<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ apt-get install input-utils
 
$ apt-get install input-utils
 
$ input-events 1
 
$ input-events 1
 
</syntaxhighlight>
 
</syntaxhighlight>
1表示读设备节点event1。<br>
+
1 stands for device node "event1"<br>
  
用一个普通的遥控器往模块发送数据,可看到运行效果如下:<br>
+
You can use a regular remote control to send signals to it. Here is what you expect to observe:<br>
 
[[File:matrix-ir_receiver_result.png|frameless|600px|matrix-ir_receiver_result]]
 
[[File:matrix-ir_receiver_result.png|frameless|600px|matrix-ir_receiver_result]]
  
 +
==Connect to NanoPi==
 +
 +
==Connect to Tiny4412==
  
==与NanoPi连接使用==
+
==Connect to RaspberryPi==
  
==与Tiny4412连接使用==
+
==Connect to Arduino==
 +
--->
  
==与RaspberryPi连接使用==
+
==Resources==
  
==与Arduino连接使用==
+
==Update Log==
 +
===Feb-24-2016===
 +
* Added the driver's source code location in Section 5.2
  
==相关资料==
+
===June-21-2016===
 +
* Re-organized and simplified wiki

Latest revision as of 01:31, 21 June 2016

查看中文

1 Introduction

IR Receiver
  • The Matrix-IR receiver is a 38KHz infrared receiver that receives 38KHz signals from an infrared remote control, amplifies and filers them to other devices. Its signal decoding is implemented by programming MCU.
  • Transmission distance: 12 ~ 13 meters.

2 Features

  • GPIO control, 3.3/5V
  • Small
  • 2.54mm spacing pin header
  • PCB Dimension(mm): 8 x 24

IR Receiver.PCB

  • Pin Description:
Pin Description
S GPIO
V Supply Voltage 5V
G Ground

3 Basic Device Operation

  • The IR receiver contains a photo diode, amplifier, band pass filter, integrator, hysteresis comparator and etc. When the IR receiver detects infrared signals it sends them to the preamplifier and band pass filter. After the signals are processed by the band pass filter (30KHz ~ 60KHz) they will be further processed by the integrator and comparator and finally be output as High or Low.
  • Note: the output signal is the reversal of the input signal.

4 Applications

4.1 Connect to NanoPi M1

Refer to the following connection diagram to connect the module to the NanoPi M1:
Matrix-IR_Receiver_nanopi_m1

Connection Details:

Matrix-IR_Receiver NanoPi M1
S Pin7
V Pin4
G Pin6

4.2 Connect to NanoPi 2

Refer to the following connection diagram to connect the module to the NanoPi 2:
Matrix-IR_Receiver_nanopi_2

Connection Details

Matrix-IR_Receiver NanoPi 2
S Pin7
V Pin4
G Pin6

4.3 Connect to NanoPi M2 / NanoPi 2 Fire

Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire:
Matrix-IR_Receiver_nanopi_m2

Connection Details:

Matrix-IR_Receiver NanoPi M2
S Pin7
V Pin4
G Pin6

4.4 Connect to NanoPC-T2

Refer to the following connection diagram to connect the module to the NanoPC-T2:
Matrix-IR_Receiver_NanoPC-T2

Connection Details:

Matrix-IR_Receiver NanoPC-T2
S Pin15
V Pin29
G Pin30

5 Compile & Run Test Program

Boot your ARM board with Debian and copy the matrix code:

$ apt-get update && apt-get install git
$ git clone https://github.com/friendlyarm/matrix.git

If your cloning is done successfully a "matrix" directory will be generated.

Compile and install Matrix:

$ cd matrix
$ make && make install

Run test program:

$ matrix-ir_receiver

Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.
Here is what you should observe:

Press the IR remoter
 0: Type=4, Code=4, Value=3b0d
 1: Type=0, Code=0, Value=0
 2: Type=4, Code=4, Value=3b12
 3: Type=0, Code=0, Value=0
 4: Type=4, Code=4, Value=3b15
 5: Type=0, Code=0, Value=0

When you point our RC-100 controller to it and press any key on the controller an event will be detected.

6 Code Sample

This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-ir_receiver". Here is its source code:

int main(int argc, char ** argv)
{
    int board, i, j;
    int retSize = -1;
    char *devName = GPIO_IR_DEV;
    int pin = GPIO_PIN(7);
    char modStr[BUF_SIZE];
    struct input_event evKey;
 
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
    if (board == BOARD_NANOPI_T2)
        pin = GPIO_PIN(15);
 
    sprintf(modStr, "modprobe %s gpio=%d", DRIVER_MODULE, pintoGPIO(pin));
    system(modStr);
    signal(SIGINT, IRIntHandler);
    sleep(1);
    irFD = openHW(devName, O_RDWR);
    if (irFD < 0) {
        printf("Fail to open GPIO IR device\n");
        goto err;
    }
    printf("Press the IR remoter\n");
    for (i=0; i<IR_EVENT_TIMES; i++) {
        if (selectHW(irFD, 0, 0) == 1) {
            retSize = readHW(irFD, &evKey, sizeof(struct input_event));
            for (j=0; j<(int) retSize / sizeof(struct input_event); j++)
                printf("%2d: Type=%d, Code=%d, Value=%x\n", i, evKey.type, evKey.code, evKey.value);
        }
    }
    closeHW(irFD);
err:
    system("rmmod "DRIVER_MODULE);
    return 0;
}

For more details about this APIs called in this code sample refer to Matrix API reference manual


7 Resources

8 Update Log

8.1 Feb-24-2016

  • Added the driver's source code location in Section 5.2

8.2 June-21-2016

  • Re-organized and simplified wiki