Difference between revisions of "Matrix - LED/zh"
(→连接NanoPC-T2) |
|||
(5 intermediate revisions by 2 users not shown) | |||
Line 30: | Line 30: | ||
==硬件连接== | ==硬件连接== | ||
+ | ===连接NanoPi NEO/NanoPi NEO Air=== | ||
+ | NanoPi M1和NanoPi NEO以及NanoPi NEO Air的前24Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,并且使用同一份代码。<br> | ||
+ | |||
+ | 参考下图连接模块:<br> | ||
+ | [[File:Matrix-LED_nanopi_NEO.jpg|frameless|600px|Matrix-LED_nanopi_NEO]] | ||
+ | |||
+ | 连接说明: | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-LED || NanoPi NEO | ||
+ | |- | ||
+ | |S || Pin7 | ||
+ | |- | ||
+ | |V || Pin4 | ||
+ | |- | ||
+ | |G || Pin6 | ||
+ | |} | ||
+ | |||
===连接NanoPi M1=== | ===连接NanoPi M1=== | ||
参考下图连接模块:<br> | 参考下图连接模块:<br> | ||
Line 79: | Line 97: | ||
|} | |} | ||
− | === | + | ===连接NanoPi M3=== |
参考下图连接模块:<br> | 参考下图连接模块:<br> | ||
+ | [[File:Matrix-LED_nanopi_m3.jpg|frameless|600px|Matrix-LED_nanopi_m3]] | ||
+ | |||
+ | 连接说明: | ||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | |Matrix-LED || NanoPi M3 | ||
+ | |- | ||
+ | |S || Pin7 | ||
+ | |- | ||
+ | |V || Pin4 | ||
+ | |- | ||
+ | |G || Pin6 | ||
+ | |} | ||
+ | |||
+ | ===连接NanoPC-T2/NanoPC-T3=== | ||
+ | 由于NanoPC-T2跟NanoPC-T3的引脚是一样的,所以连接方式是一样的,这里仅以T2为例,参考下图连接模块:<br> | ||
[[File:Matrix-LED_NanoPC-T2.jpg|frameless|600px|Matrix-LED_NanoPC-T2]] | [[File:Matrix-LED_NanoPC-T2.jpg|frameless|600px|Matrix-LED_NanoPC-T2]] | ||
Line 125: | Line 159: | ||
==代码说明== | ==代码说明== | ||
− | + | 所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-gpio_out,内容如下: | |
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
int main(int argc, char ** argv) | int main(int argc, char ** argv) | ||
{ | { | ||
int pin = GPIO_PIN(7); | int pin = GPIO_PIN(7); | ||
− | int i, board; | + | int i, value, board; |
int ret = -1; | int ret = -1; | ||
− | if ((board = boardInit()) < 0) | + | if ((board = boardInit()) < 0) { |
printf("Fail to init board\n"); | printf("Fail to init board\n"); | ||
+ | return -1; | ||
+ | } | ||
if (board == BOARD_NANOPI_T2) | if (board == BOARD_NANOPI_T2) | ||
pin = GPIO_PIN(15); | pin = GPIO_PIN(15); | ||
+ | |||
if (argc == 2) | if (argc == 2) | ||
pin = GPIO_PIN(atoi(argv[1])); | pin = GPIO_PIN(atoi(argv[1])); | ||
− | |||
if ((ret = exportGPIOPin(pin)) == -1) { | if ((ret = exportGPIOPin(pin)) == -1) { | ||
printf("exportGPIOPin(%d) failed\n", pin); | printf("exportGPIOPin(%d) failed\n", pin); | ||
Line 146: | Line 182: | ||
printf("setGPIODirection(%d) failed\n", pin); | printf("setGPIODirection(%d) failed\n", pin); | ||
} | } | ||
− | |||
for (i = 0; i < STATUS_CHANGE_TIMES; i++) { | for (i = 0; i < STATUS_CHANGE_TIMES; i++) { | ||
if (i % 2) { | if (i % 2) { | ||
− | + | value = GPIO_HIGH; | |
} else { | } else { | ||
− | + | value = GPIO_LOW; | |
} | } | ||
− | if (ret = | + | if ((ret = setGPIOValue(pin, value)) > 0) { |
+ | printf("%d: GPIO_PIN(%d) value is %d\n", i+1, pin, value); | ||
+ | } else { | ||
printf("setGPIOValue(%d) failed\n", pin); | printf("setGPIOValue(%d) failed\n", pin); | ||
} | } | ||
− | |||
sleep(1); | sleep(1); | ||
} | } |
Latest revision as of 08:47, 10 November 2016
Contents
1 介绍
Matrix-LED是一个简单的发光二极管模块。3-Pin 2.54mm排针,V接电源,G接地,S信号通过一个三极管放大控制LED的导通或关闭。您可以向S输出静态的高低电平信号,也可以输出变化的PWM信号,信号电平可以是3.3V或5V。当您向S输出高电平时LED以最大亮度发光,低电平就完全熄灭,可变占空比的PWM信号可以调节发光的亮度。
2 特性
- GPIO或PWM控制,3.3/5V电平,亮度通过PWM可调
- 体积小巧
- 2.54mm排针接口
- PCB尺寸(mm):8x24
- 引脚说明:
名称 | 描述 |
S | GPIO |
V | 电源5V |
G | 地 |
3 工作原理
3-Pin 2.54mm排针,V接电源,G接地,S信号通过一个三极管放大控制LED的导通或关闭。您可以向S输出静态的高低电平信号,也可以输出变化的PWM信号,信号电平可以是3.3V或5V。当您向S输出高电平时LED以最大亮度发光,低电平就完全熄灭,可变占空比的PWM信号可以调节发光的亮度。
4 硬件连接
4.1 连接NanoPi NEO/NanoPi NEO Air
NanoPi M1和NanoPi NEO以及NanoPi NEO Air的前24Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,并且使用同一份代码。
参考下图连接模块:
Matrix-LED_nanopi_NEO
连接说明:
Matrix-LED | NanoPi NEO |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.2 连接NanoPi M1
连接说明:
Matrix-LED | NanoPi M1 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.3 连接NanoPi 2
连接说明:
Matrix-LED | 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-LED | NanoPi M2 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.5 连接NanoPi M3
参考下图连接模块:
Matrix-LED_nanopi_m3
连接说明:
Matrix-LED | NanoPi M3 |
S | Pin7 |
V | Pin4 |
G | Pin6 |
4.6 连接NanoPC-T2/NanoPC-T3
由于NanoPC-T2跟NanoPC-T3的引脚是一样的,所以连接方式是一样的,这里仅以T2为例,参考下图连接模块:
Matrix-LED_NanoPC-T2
连接说明:
Matrix-LED | 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-gpio_out
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。
运行效果如下:
1: gpio status change 2: gpio status change 3: gpio status change 4: gpio status change 5: gpio status change
可以看到LED在不停地闪烁。
6 代码说明
所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-gpio_out,内容如下:
int main(int argc, char ** argv) { int pin = GPIO_PIN(7); int i, value, board; int ret = -1; if ((board = boardInit()) < 0) { printf("Fail to init board\n"); return -1; } if (board == BOARD_NANOPI_T2) pin = GPIO_PIN(15); if (argc == 2) pin = GPIO_PIN(atoi(argv[1])); if ((ret = exportGPIOPin(pin)) == -1) { printf("exportGPIOPin(%d) failed\n", pin); } if ((ret = setGPIODirection(pin, GPIO_OUT)) == -1) { printf("setGPIODirection(%d) failed\n", pin); } for (i = 0; i < STATUS_CHANGE_TIMES; i++) { if (i % 2) { value = GPIO_HIGH; } else { value = GPIO_LOW; } if ((ret = setGPIOValue(pin, value)) > 0) { printf("%d: GPIO_PIN(%d) value is %d\n", i+1, pin, value); } else { printf("setGPIOValue(%d) failed\n", pin); } sleep(1); } unexportGPIOPin(pin); return 0; }
API说明参考维基:Matrix API reference manual