Difference between revisions of "Matrix - IR Receiver"
From FriendlyELEC WiKi
(→Resources) |
|||
Line 29: | Line 29: | ||
*Note: the output signal is the reversal of the input signal. | *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 | ||
+ | |} | ||
+ | |||
+ | ==编译运行测试程序== | ||
+ | 启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ apt-get update && apt-get install git | ||
+ | $ git clone https://github.com/friendlyarm/matrix.git | ||
+ | </syntaxhighlight> | ||
+ | 克隆完成后会得到一个名为matrix的目录。 | ||
+ | |||
+ | 编译并安装Matrix: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ cd matrix | ||
+ | $ make && make install | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | 运行测试程序: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ matrix-ir_receiver | ||
+ | </syntaxhighlight> | ||
+ | 注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br> | ||
+ | 运行效果如下:<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> | ||
+ | 使用官方配套的红外遥控器RC-100对准开发板按下按键,可以检测到事件。 | ||
+ | |||
+ | ==代码说明== | ||
+ | 所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-ir_receiver,内容如下: | ||
+ | <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> | ||
+ | API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br> | ||
+ | |||
+ | |||
+ | <!--- | ||
==Download Matrix Source Code== | ==Download Matrix Source Code== | ||
Line 117: | Line 259: | ||
==Connect to Arduino== | ==Connect to Arduino== | ||
+ | ---> | ||
==Resources== | ==Resources== |
Revision as of 01:24, 21 June 2016
Contents
1 Introduction
- 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
- 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:
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:
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 编译运行测试程序
启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库:
$ apt-get update && apt-get install git $ git clone https://github.com/friendlyarm/matrix.git
克隆完成后会得到一个名为matrix的目录。
编译并安装Matrix:
$ cd matrix $ make && make install
运行测试程序:
$ matrix-ir_receiver
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
运行效果如下:
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
使用官方配套的红外遥控器RC-100对准开发板按下按键,可以检测到事件。
6 代码说明
所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-ir_receiver,内容如下:
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; }
API说明参考维基: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