Difference between revisions of "Matrix - RGB LED"

From FriendlyELEC WiKi
Jump to: navigation, search
(介绍)
(Resources)
 
(13 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Introduction==
 
==Introduction==
 
[[File:Matrix-RGB_LED.png|thumb|]]
 
[[File:Matrix-RGB_LED.png|thumb|]]
*Matrix-RGB_LED是一个RGB发光二极管模块。5-Pin 2.54mm排针,V接电源,G接地,R、G、B引脚分别控制二极管发出红、绿、蓝三种颜色的光,或者组合发出混色光。
+
* The Matrix-RGB_LED is a RGB LED module. It has a 2.54mm pitch pin-header in which 5V is power supply, GND is ground, and R,G,B are connected to the LED’s red, green and blue pins.
*您可以向R、G、B引脚输出静态的高低电平信号,也可以输出变化的PWM信号,信号电平可以是3.3V或5V。当您向R、G、B引脚输出高电平时LED以最大亮度发光,低电平就完全熄灭;向R、G、B引脚输出可变占空比的PWM信号可以调节R、G、B颜色光发光的亮度,从而形成多种颜色的混色光。
+
* The inputs to Pin R, G and B can be either GPIO signals or PWM signals. The signal level can be either 3.3V or 5V. When the inputs to Pin R,G and B are high the LED will be the brightest.When the inputs to Pin R,G and B are low the LED will be completely off. When the inputs are PWM signals the LED's brightness can be controlled by controlling the PWM's duty cycle.
  
==特性==
+
==Features==
* GPIO或PWM控制,3.3/5V电平,亮度通过PWM可调
+
* GPIO or PWM input, 3.3/5V, LED lightness controllable via PWM
* 体积小巧
+
* Small
* 2.54mm排针接口
+
* 2.54 mm pitch pin-header
* PCB尺寸(mm):16x24
+
* PCB dimension(mm): 16 x 24
 
[[File:Matrix-RGB_LED_PCB.png|frameless|400px|]]
 
[[File:Matrix-RGB_LED_PCB.png|frameless|400px|]]
  
* 引脚说明:
+
* Pin Description:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|名称   || 描述
+
|Pin   || Description
 
|-
 
|-
|GND    ||
+
|GND    || Ground
 
|-
 
|-
|5V    || 电源5V
+
|5V    || Supply Voltage 5V
 
|-  
 
|-  
|R      || 红色控制引脚
+
|R      || Red
 
|-
 
|-
|G      || 绿色控制引脚
+
|G      || Green
 
|-
 
|-
|B    || 蓝色控制引脚
+
|B    || Blue
 
|}
 
|}
  
==工作原理==
+
==Basic Device Operation==
*RGB_LED的内部封装了三颗不同颜色的灯珠,三个灯珠的阳极或者阴极并联,当给另外三个引脚施加控制信号时,对应的LED就会亮起。当两种或三种LED亮起时,根据三原色原理,会组成其他颜色的光。施加PWM信号时,不同占空比的PWM信号可以调节R、G、B颜色光发光的亮度,从而组合成多种颜色。
+
* In the RGB_LED module three one-color LEDs(one red,one green and one blue) are housed in a single package.These three LEDs share one common anode or cathode.When applying control signals to the other three leads their corresponding LEDs will be on. When two or three LEDs are on simultaneously a different color will be produced.You can produce different colors by adjusting PWM signals' duty cycle.
  
==硬件连接==
+
==Applications==
===连接NanoPi M1===
+
===Connect to NanoPi M1===
参考下图连接模块:<br>
+
Refer to the following connection diagram to connect the module to the NanoPi M1:<br>
 
[[File:Matrix-RGBLED_nanopi_m1.jpg|frameless|600px|Matrix-RGBLED_nanopi_m1]]
 
[[File:Matrix-RGBLED_nanopi_m1.jpg|frameless|600px|Matrix-RGBLED_nanopi_m1]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 53: Line 53:
 
|}
 
|}
  
===连接NanoPi 2===
+
===Connect to NanoPi 2===
参考下图连接模块:<br>
+
Refer to the following connection diagram to connect the module to the NanoPi 2:<br>
 
[[File:Matrix-RGB_LED_nanopi2.jpg|frameless|600px|Matrix-RGB_LED_nanopi2]]
 
[[File:Matrix-RGB_LED_nanopi2.jpg|frameless|600px|Matrix-RGB_LED_nanopi2]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 73: Line 73:
 
|}
 
|}
  
===连接NanoPi M2 / NanoPi 2 Fire===
+
===Connect to NanoPi M2 / NanoPi 2 Fire===
NanoPi M2和NanoPi 2 Fire的40 Pin引脚定义是一模一样的,所以它们操作Matrix配件的步骤是一样的,这里仅以NanoPi M2为例。<br>
+
Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire.<br>
参考下图连接模块:<br>
+
 
[[File:Matrix-RGBLED_nanopi_m2.jpg|frameless|600px|Matrix-RGBLED_nanopi_m2]]
 
[[File:Matrix-RGBLED_nanopi_m2.jpg|frameless|600px|Matrix-RGBLED_nanopi_m2]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 94: Line 93:
 
|}
 
|}
  
===连接NanoPC-T2===
+
===Connect to NanoPC-T2===
参考下图连接模块:<br>
+
Refer to the following connection diagram to connect the module to the NanoPC-T2:<br>
 
[[File:Matrix-RGBLED_NanoPC-T2.jpg|frameless|600px|Matrix-RGBLED_NanoPC-T2]]
 
[[File:Matrix-RGBLED_NanoPC-T2.jpg|frameless|600px|Matrix-RGBLED_NanoPC-T2]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 114: Line 113:
 
|}
 
|}
  
==编译运行测试程序==
+
==Compile & Run Test Program==
启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库:
+
Boot your ARM board with Debian and copy the matrix code:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ apt-get update && apt-get install git
 
$ apt-get update && apt-get install git
 
$ git clone https://github.com/friendlyarm/matrix.git
 
$ git clone https://github.com/friendlyarm/matrix.git
 
</syntaxhighlight>
 
</syntaxhighlight>
克隆完成后会得到一个名为matrix的目录。
+
If your cloning is done successfully a "matrix" directory will be generated.
  
编译并安装Matrix:
+
Compile and install Matrix:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 128: Line 127:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
运行测试程序:
+
Run test program:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-rgb_led
 
$ matrix-rgb_led
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br>
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.<br>
运行效果如下:<br>
+
Here is what you should observe:<br>
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
Set RGB LED: 0
 
Set RGB LED: 0
Line 144: Line 143:
 
Set RGB LED: 7
 
Set RGB LED: 7
 
</syntaxhighlight>
 
</syntaxhighlight>
可以看到RGBLED在不停地变换颜色。
+
You will see the LED displaying different colors.
  
==代码说明==
+
==Code Sample==
所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-rgb_led,内容如下:
+
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-rgb_led". Here is its source code:
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)
 
int main(int argc, char ** argv)
Line 193: Line 192:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
API说明参考维基:[[Matrix API reference manual/zh|Matrix API reference manual]] <br>
+
For more details about this APIs called in this code sample refer to [[Matrix API reference manual]] <br>
  
==相关资料==
+
==Resources==
 +
 
 +
==Update Log==
 +
===June-24-2016===
 +
* Created English wiki

Latest revision as of 14:54, 24 June 2016

查看中文

1 Introduction

Matrix-RGB LED.png
  • The Matrix-RGB_LED is a RGB LED module. It has a 2.54mm pitch pin-header in which 5V is power supply, GND is ground, and R,G,B are connected to the LED’s red, green and blue pins.
  • The inputs to Pin R, G and B can be either GPIO signals or PWM signals. The signal level can be either 3.3V or 5V. When the inputs to Pin R,G and B are high the LED will be the brightest.When the inputs to Pin R,G and B are low the LED will be completely off. When the inputs are PWM signals the LED's brightness can be controlled by controlling the PWM's duty cycle.

2 Features

  • GPIO or PWM input, 3.3/5V, LED lightness controllable via PWM
  • Small
  • 2.54 mm pitch pin-header
  • PCB dimension(mm): 16 x 24

Matrix-RGB LED PCB.png

  • Pin Description:
Pin Description
GND Ground
5V Supply Voltage 5V
R Red
G Green
B Blue

3 Basic Device Operation

  • In the RGB_LED module three one-color LEDs(one red,one green and one blue) are housed in a single package.These three LEDs share one common anode or cathode.When applying control signals to the other three leads their corresponding LEDs will be on. When two or three LEDs are on simultaneously a different color will be produced.You can produce different colors by adjusting PWM signals' duty cycle.

4 Applications

4.1 Connect to NanoPi M1

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

Connection Details:

Matrix-RGBLED NanoPi M1
R Pin7
G Pin8
B Pin10
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-RGB_LED_nanopi2

Connection Details:

Matrix-RGBLED NanoPi 2
R Pin7
G Pin8
B Pin10
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-RGBLED_nanopi_m2

Connection Details:

Matrix-RGBLED NanoPi M2
R Pin7
G Pin8
B Pin10
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-RGBLED_NanoPC-T2

Connection Details:

Matrix-RGBLED NanoPC-T2
R Pin15
G Pin16
B Pin17
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-rgb_led

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:

Set RGB LED: 0
Set RGB LED: 1
Set RGB LED: 2
Set RGB LED: 3
Set RGB LED: 4
Set RGB LED: 5
Set RGB LED: 6
Set RGB LED: 7

You will see the LED displaying different colors.

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-rgb_led". Here is its source code:

int main(int argc, char ** argv)
{
    int ret = -1;
    int val, board;
 
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
    if (board == BOARD_NANOPI_T2) {
        ledPin1 = GPIO_PIN(15);
        ledPin2 = GPIO_PIN(16);
        ledPin3 = GPIO_PIN(17);
    }
    if ((ret = exportGPIOPin(ledPin1)) == -1) {
        printf("exportGPIOPin(%d) failed\n", ledPin1);
    }
    if ((ret = setGPIODirection(ledPin1, GPIO_OUT)) == -1) {
        printf("setGPIODirection(%d) failed\n", ledPin1);
    }
    if ((ret = exportGPIOPin(ledPin2)) == -1) {
        printf("exportGPIOPin(%d) failed\n", ledPin2);
    }
    if ((ret = setGPIODirection(ledPin2, GPIO_OUT)) == -1) {
        printf("setGPIODirection(%d) failed\n", ledPin2);
    }
    if ((ret = exportGPIOPin(ledPin3)) == -1) {
        printf("exportGPIOPin(%d) failed\n", ledPin3);
    }
    if ((ret = setGPIODirection(ledPin3, GPIO_OUT)) == -1) {
        printf("setGPIODirection(%d) failed\n", ledPin3);
    }
    signal(SIGINT, intHandler);
    for (val = 0; val < 8; val++) {
        printf("Set RGB LED: %x\n", val);
        setRGBLED(val);
        usleep(1000 * 1000);
    }
    unexportGPIOPin(ledPin1);
    unexportGPIOPin(ledPin2);
    unexportGPIOPin(ledPin3);
    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 June-24-2016

  • Created English wiki