Difference between revisions of "Matrix - RGB LED"

From FriendlyELEC WiKi
Jump to: navigation, search
(介绍)
(Resources)
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Matrix - RTC|English]]
+
[[Matrix - RGB LED/zh|查看中文]]
  
==介绍==
+
==Introduction==
 
[[File:Matrix-RGB_LED.png|thumb|]]
 
[[File:Matrix-RGB_LED.png|thumb|]]
*
+
* 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.
  
==特性==
+
==Features==
* I2C串口接口
+
* GPIO or PWM input, 3.3/5V, LED lightness controllable via PWM
* 56字节、电池支持、通用的RAM和无限写道
+
* Small
* 8-Pin DIP和8-Pin SO
+
* 2.54 mm pitch pin-header
* 操作温度在-40度到85度
+
* PCB dimension(mm): 16 x 24
* PCB尺寸(mm):24x32
+
[[File:Matrix-RGB_LED_PCB.png|frameless|400px|]]
[[File:Matrix-RTC_PCB.png|frameless|400px|]]
+
  
* 引脚说明:
+
* Pin Description:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|名称   || 描述
+
|Pin   || Description
 
|-
 
|-
|SDA   || I2C SDA
+
|GND   || Ground
 
|-
 
|-
|SCL    || I2C SCL
+
|5V    || Supply Voltage 5V
 
|-  
 
|-  
|5V    || 电源5V
+
|R      || Red
 
|-
 
|-
|GND    ||
+
|G      || Green
 +
|-
 +
|B    || Blue
 
|}
 
|}
  
==工作原理==
+
==Basic Device Operation==
* DS1307控制寄存器用来控制SQW/OWT引脚的操作:
+
* 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.
[[File:Matrix-RTC_PIN.png|frameless|400px|]]
+
* DS1307中的时间寄存器地址编码为00H-07H,而具有掉电保护的RAM寄存器的地址编码为08H-3FH。当地址指针指向RAM的最后一个地址3FH时,若进行多字节操作,则地址指针将会复位而指向00H,这样原来存在00H的数据将会丢失。
+
* DS1307的各类时间数据均以BCD码的格式存贮在
+
相应的时间寄存器中,具体分配为:
+
00H:秒;01H:分;02H:小时;03H:星期;04H:
+
日期;05H:月;06H:年;07H:控制字。
+
* DS1307支持I2C协议。设备发送数据到总线被定义为一个发射器和一个接收设备接收数据。DS1307的操作时序实际上就是I2C总线时序。
+
总线上传送的一帧数据为一个字节。
+
* 在对DS1307进行数据写入时,应先将日历时钟信息存放于单片机内部从45H开始的:8个RAM单元,而从DS1307读出的数据同样需存放在其中。
+
  
==下载Matrix源码==
+
==Applications==
Matrix配件相关的代码是完全开源的,统一由一个仓库进行管理:https://github.com/friendlyarm/matrix.git <br>
+
===Connect to NanoPi M1===
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。<br>
+
Refer to the following connection diagram to connect the module to the NanoPi M1:<br>
* nanopi分支用于支持NanoPi;
+
[[File:Matrix-RGBLED_nanopi_m1.jpg|frameless|600px|Matrix-RGBLED_nanopi_m1]]
* nanopi2分支用于支持NanoPi 2;
+
* tiny4412分支用于支持Tiny4412;
+
* raspberrypi分支用于支持RaspberryPi;
+
  
在主机PC上安装git,以Ubuntu14.04为例
+
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-RGBLED || NanoPi M1
 +
|-
 +
|R    || Pin7
 +
|-
 +
|G    || Pin8
 +
|-
 +
|B    || Pin10
 +
|-
 +
|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-RGB_LED_nanopi2.jpg|frameless|600px|Matrix-RGB_LED_nanopi2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-RGBLED || NanoPi 2
 +
|-
 +
|R    || Pin7
 +
|-
 +
|G    || Pin8
 +
|-
 +
|B    || Pin10
 +
|-
 +
|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-RGBLED_nanopi_m2.jpg|frameless|600px|Matrix-RGBLED_nanopi_m2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-RGBLED || NanoPi M2
 +
|-
 +
|R    || Pin7
 +
|-
 +
|G    || Pin8
 +
|-
 +
|B    || Pin10
 +
|-
 +
|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-RGBLED_NanoPC-T2.jpg|frameless|600px|Matrix-RGBLED_NanoPC-T2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-RGBLED || NanoPC-T2
 +
|-
 +
|R    || Pin15
 +
|-
 +
|G    || Pin16
 +
|-
 +
|B    || Pin17
 +
|-
 +
|V    || Pin29
 +
|-
 +
|G    || Pin30
 +
|}
 +
 
 +
==Compile & Run Test Program==
 +
Boot your ARM board with Debian and copy the matrix code:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ sudo apt-get install git
+
$ apt-get update && apt-get install git
 +
$ git clone https://github.com/friendlyarm/matrix.git
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
If your cloning is done successfully a "matrix" directory will be generated.
  
克隆Matrix配件代码仓库
+
Compile and install Matrix:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ git clone https://github.com/friendlyarm/matrix.git
+
$ cd matrix
 +
$ make && make install
 
</syntaxhighlight>
 
</syntaxhighlight>
克隆完成后会得到一个名为matrix的目录,里面存放着所有Matrix配件的代码。
 
  
==与NanoPi 2连接使用==
+
Run test program:
 +
<syntaxhighlight lang="bash">
 +
$ matrix-rgb_led
 +
</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">
 +
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
 +
</syntaxhighlight>
 +
You will see the LED displaying different colors.
 +
 
 +
==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:
 +
<syntaxhighlight lang="c">
 +
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;
 +
}
 +
</syntaxhighlight>
 +
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