Difference between revisions of "Matrix - IR Receiver/zh"
From FriendlyELEC WiKi
(→与NanoPi 2连接使用) |
(→连接NanoPC-T2) |
||
(9 intermediate revisions by 2 users not shown) | |||
Line 29: | Line 29: | ||
*注意:输出的高低电平和发射端是反相的,这样的目的是为了提高接收的灵敏度。 | *注意:输出的高低电平和发射端是反相的,这样的目的是为了提高接收的灵敏度。 | ||
− | == | + | ==硬件连接== |
+ | ===连接NanoPi NEO/NanoPi NEO Air=== | ||
+ | NanoPi M1和NanoPi NEO以及NanoPi NEO Air的前24Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,并且使用同一份代码。<br> | ||
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix-IR_Receiver_nanopi_NEO.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_NEO]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | 连接说明: | |
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | |Matrix-IR_Receiver || NanoPi NEO | |
+ | |- | ||
+ | |S || Pin7 | ||
+ | |- | ||
+ | |V || Pin4 | ||
+ | |- | ||
+ | |G || Pin6 | ||
+ | |} | ||
− | + | ===连接NanoPi M1=== | |
− | < | + | 参考下图连接模块:<br> |
− | + | [[File:Matrix-IR_Receiver_nanopi_m1.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_m1]] | |
− | + | ||
− | + | 连接说明: | |
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-IR_Receiver || NanoPi M1 | ||
+ | |- | ||
+ | |S || Pin7 | ||
+ | |- | ||
+ | |V || Pin4 | ||
+ | |- | ||
+ | |G || Pin6 | ||
+ | |} | ||
− | == | + | ===连接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]] | ||
Line 59: | Line 73: | ||
|Matrix-IR_Receiver || NanoPi 2 | |Matrix-IR_Receiver || NanoPi 2 | ||
|- | |- | ||
− | |S | + | |S || Pin7 |
|- | |- | ||
− | |V | + | |V || Pin4 |
|- | |- | ||
− | |G | + | |G || Pin6 |
|} | |} | ||
− | === | + | ===连接NanoPi M2 / NanoPi 2 Fire=== |
− | + | NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。<br> | |
− | < | + | 参考下图连接模块:<br> |
− | + | [[File:Matrix-IR_Receiver_nanopi_m2.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_m2]] | |
− | + | ||
− | < | + | |
− | + | 连接说明: | |
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | |Matrix-IR_Receiver || NanoPi M2 | |
− | + | |- | |
− | + | |S || Pin7 | |
− | + | |- | |
− | + | |V || Pin4 | |
− | + | |- | |
+ | |G || Pin6 | ||
+ | |} | ||
− | === | + | ===连接NanoPi M3=== |
− | + | 参考下图连接模块:<br> | |
− | + | [[File:Matrix-IR_Receiver_nanopi_m3.jpg|frameless|600px|Matrix-IR_Receiver_nanopi_m3]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | 连接说明: | |
− | + | {| class="wikitable" | |
− | + | |- | |
− | + | |Matrix-IR_Receiver || NanoPi M3 | |
− | + | |- | |
− | + | |S || Pin7 | |
+ | |- | ||
+ | |V || Pin4 | ||
+ | |- | ||
+ | |G || Pin6 | ||
+ | |} | ||
− | + | ===连接NanoPC-T2/NanoPC-T3=== | |
− | + | 由于NanoPC-T2跟NanoPC-T3的引脚是一样的,所以连接方式是一样的,这里仅以T2为例,参考下图连接模块:<br> | |
− | + | [[File:Matrix-IR_Receiver_NanoPC-T2.jpg|frameless|600px|Matrix-IR_Receiver_NanoPC-T2]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | = | + | |
− | + | ||
− | + | ||
− | [[File:Matrix- | + | |
连接说明: | 连接说明: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
− | |Matrix-IR_Receiver || | + | |Matrix-IR_Receiver || NanoPC-T2 |
|- | |- | ||
− | |S | + | |S || Pin15 |
|- | |- | ||
− | |V | + | |V || Pin29 |
|- | |- | ||
− | |G | + | |G || Pin30 |
|} | |} | ||
− | == | + | ==编译运行测试程序== |
− | + | 启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ | + | $ apt-get update && apt-get install git |
− | $ git | + | $ git clone https://github.com/friendlyarm/matrix.git |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | 克隆完成后会得到一个名为matrix的目录。 | ||
− | + | 编译并安装Matrix: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ | + | $ cd matrix |
− | $ make | + | $ make && make install |
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− | + | 运行测试程序: | |
− | + | ||
− | + | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ | + | $ matrix-ir_receiver |
− | + | ||
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br> | |
− | + | 运行效果如下:<br> | |
<syntaxhighlight lang="bash"> | <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> | </syntaxhighlight> | ||
− | + | 使用官方配套的红外遥控器RC-100对准开发板按下按键,可以检测到事件。 | |
− | + | ==代码说明== | |
− | <syntaxhighlight lang=" | + | 所有的开发板都共用一套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> | </syntaxhighlight> | ||
− | + | API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br> | |
− | + | ||
− | + | ||
− | [[ | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
==相关资料== | ==相关资料== |
Latest revision as of 08:45, 10 November 2016
Contents
1 介绍
- Matrix-IR Receiver是38KHz红外接收模块,主要器件是一个红外接收头,可接收标准38KHz调制的遥控器信号,并放大和滤波输出,通过MCU编程,即可实现对遥控器信号的解码操作。
- 接收范围:12-13米
2 特性
- GPIO控制,3.3/5V电平
- 体积小巧
- 2.54mm排针接口
- PCB尺寸(mm):8x24
- 引脚说明:
名称 | 描述 |
S | GPIO |
V | 电源5V |
G | 地 |
3 工作原理
- 红外接收头内部包括红外监测二极管、放大器、限副器、带通滤波器、积分电路、比较器等。红外监测二极管检测到红外信号,然后把信号送到放大器和限幅器,限幅器把脉冲幅度控制在一定的水平,而不论红外发射器和接收器的距离远近。交流信号进入带通滤波器(带通滤波器可以通过30khz到60khz的负载波),再通过解调电路和积分电路进入比较器,比较器输出高低电平,还原出发射端的信号波形。
- 注意:输出的高低电平和发射端是反相的,这样的目的是为了提高接收的灵敏度。
4 硬件连接
4.1 连接NanoPi NEO/NanoPi NEO Air
NanoPi M1和NanoPi NEO以及NanoPi NEO Air的前24Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,并且使用同一份代码。
参考下图连接模块:
Matrix-IR_Receiver_nanopi_NEO
连接说明:
Matrix-IR_Receiver | NanoPi NEO |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.2 连接NanoPi M1
连接说明:
Matrix-IR_Receiver | NanoPi M1 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.3 连接NanoPi 2
连接说明:
Matrix-IR_Receiver | NanoPi 2 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.4 连接NanoPi M2 / NanoPi 2 Fire
NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。
参考下图连接模块:
Matrix-IR_Receiver_nanopi_m2
连接说明:
Matrix-IR_Receiver | NanoPi M2 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.5 连接NanoPi M3
参考下图连接模块:
Matrix-IR_Receiver_nanopi_m3
连接说明:
Matrix-IR_Receiver | NanoPi M3 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.6 连接NanoPC-T2/NanoPC-T3
由于NanoPC-T2跟NanoPC-T3的引脚是一样的,所以连接方式是一样的,这里仅以T2为例,参考下图连接模块:
Matrix-IR_Receiver_NanoPC-T2
连接说明:
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