8*8 LED RGB Matrix

概 述

8*8 LED RGB Matrix是一个XY轴可任意级联的三色多彩LED显示矩阵模块,可用于显示图片和文字,支持多图层和各图层的各种平移效果。

理论上支持X轴横向最大4096个和Y轴纵向最大4096个模块的任意级联,无需设计硬件。当然,如果您想要把它们级联成一个大型矩阵显示屏的话,那么您就需要一个高速控制器和大功率电源。

实际使用中,级联个数主要取决于您所用MCU的数据存储空间和模块允许通过的最大电流。

注:由于限制,目前只支持7种颜色的显示,最大3×3级联!

性能描述

硬件特性

软件特性

模块的连接与测试

显示屏与子板的连接

注意文字的方向是一致的

数据接口

SPI接口采用六针接口形式,其中1针是CLK接口,2针是LATCH接口,3针是DATA接口。这三个排阵分别于右侧的三个横向的长排针水平连接。

与Arduino UNO的连接

Arduino UNO连接方法

与interface shield的连接

注意123脚位于有突起的一边数据线的方向。

供电方式

这个六针接口可以直接连接到inerface shield的shiftout接口上,如果使用1-5个模块,可以直接采用shiftout接口的vcc直接供电,这时,需要将POWER Jumper短接。 如果模块较多,可采用外接电源供电,直接连接外接5V电源至外接电源输出入POWER接线柱,这时,POWER Jumper电源跳线帽需要拔掉。如下图所示:

DFR0202_2_2.jpg

硬件连接

数据输入端,datapin clkpin latchpin都要连接在1号子板上。

注意子板的方向,以上图为例,双四针的方向朝左,单八针的方向朝上,这样才能构成平面直角坐标系。

当用户使用少于4个子板时,可以使用arduino供电,此时需要将POWER Jumper跳线帽短接。可使用interface shield子板,将shiftout口接到下图红色区域的接口即可。数据接口一律连接到1号子板。

软件使用说明

成员函数列表

rgb_matrix构造函数

rgb_matrix(uint8_t x8, uint8_t y8,uint8_t _data_pin, uint8_t _clk_pin,uint8_t _latch_pin);

构造函数 ,当 data使用数字11口,clk使用数字13口时,使用硬件spi。当使用其他口时为软件spi。 Eg:

rgb_matrix M = rgb_matrix(1,2,11,13,8); //x方向一个子板,y方向2个子版级联,使用硬件spi,latch使用数字8口

向顶层图层缓存中写入一个ASCII字符

int put_char(uint16_t x,uint16_t y, uint8_t asc, uint8_t rotation, uint8_t mode, uint8_t color);

eg:

M.put_char(0,0,’B’,NO_ROT,MULTIPLY,RED+GREEN); //在(0,0)出不翻转使用红+绿色显示B,如果这个位置上原来有数据,那么和原有数据叠�

向指定图层缓存中写入一个ASCII字符

int put_char(uint16_t x,uint16_t y, uint8_t asc, uint8_t rotation, uint8_t mode, uint8_t color, uint8_t index);

eg:

M.put_char(0,0,’B’,ANTI_90,COVER,RED,TOP_LAYER);  //在顶层(0,0)处逆时针翻转90度,使用红色显示字符B,如果这个位置上有数据,那么将其覆盖。

在顶层用红色画一个点

int plot(int16_t x, int16_t y); //point

eg:

M.plot(1,2)  //顶层(1,2)这个点用红色点亮

在顶层用红色画一条线

int plot(int16_t x0,int16_t y0,int16_t x1,int16_t y1,uint8_t add_dot); //line

eg:

M.plot(0,0,5,7,NO_ADD_DOT);   //将顶层(0,0)至(5,7)点,用红色直线连接起来,不补全不连续点

在顶层用红色画一条函数曲线

int plot(int16_t x0,int16_t x1,int16_t y[],uint8_t add_dot); //function

eg:

uint16_t y[]={0,2,5,7,4,2,5,1};
M.plot(0,7,y,ADD_DOT);  //在顶层用红色绘制函数图象,图象上点的坐标为(x,y[x]),x范围从0到7,不连贯处用点补齐,

在指定图层上画一个点

int plot(int16_t x, int16_t y, uint8_t color, uint8_t index); //point eg:

M.plot(1,5,BLUE,TOP_LAYER+1); //在图层1上(1,5)处用蓝色画点

在指定图层上画一条线

int plot(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t add_dot, uint8_t color, uint8_t index); //line

eg:

M.plot(0,0,5,5,NO_ADD_DOT,GREEN,TOP_LAYER); //在图层1上,从点(0,0)到(5,5)画一条绿色线,不连续点不用补齐。

在指定图层上画一条函数曲线

'''int plot(int16_t x0, int16_t x1, int16_t y[], uint8_t add_dot,uint8_t color, uint8_t index); '''

eg:

uint16_t y[]={0,2,5,7,4,2,5,1};
M.plot(0,7,y,ADD_DOT,GREEN,TOP_LAYER);  //在顶层用绿色绘制函数图象,图象上点的坐标为(x,y[x]),x范围从0到7,不连贯处用点补齐,

增加新图层(从heap中分配缓存空间)

int add_layer();

eg:

M.add_layer();  //增加新图层,从heap中分配缓存空间。空间不足则返回-1

增加新图层(由调用者指定缓存空间)

int add_layer(uint8_t*);

eg:

static uint8_t   data_buf[N_X*N_Y*8*3]={0};
M.add_layer(data_buf);   //增加新图层,使用data段的data_buf作为图层缓存

移除最后一个图层(top层禁止移除)

int remove_layer();

eg:

M.remove_layer();    //移除最后一个图层,顶层进制移除

移除指定索引号的一个图层(top层禁止移动)

int remove_layer(uint8_t index);

eg:

M.remove_layer(TOP_LAYER+1);   //移除图层1

设置光标位置

int set_cur(uint16_t x,uint16_t y);

eg:

M.set_cur(0,8);  //将光标设置到(0,8)处,主要用于print函数

将光标设置到初始位置

int set_cur(uint8_t rotation);

Eg:

M.set_cur(NO_ROT);    //将光标设置到不翻转显示时的初始位置

在顶层用红色打印一个16bit数据(10进制形式)

int print(uint16_t data, uint8_t rotation);

eg:

M.set_cur(0,0);
M.print(3561,NO_ROT);  //在顶层(0,0)处开始用红色显示3561,不翻转显示

在顶层用红色打印一个字符串,不支持转义字符

int print(const char p[], uint8_t rotation); //string

eg:

M.set_cur(NO_ROT);
M.print(“Hello Matrix”,NO_ROT);  //在顶层左上角开始用红色打印字符串Hello Matrix。不翻转显示。

向指定图层加入单色图片

int put_pic(int16_t x, int16_t y, uint8_t size_x, uint8_t size_y, const char p[], uint8_t mode,uint8_t color,uint8_t index);

eg:

//纵向取模,高位在上。先左后右,先上后下。
const char pic[] =
{
      0x02,0x04,0x1F,0xE0,0x02,0x04,0x18,0xF0,
      0x10,0x13,0x10,0x10,0x14,0x18,0x00,0x00,
      0x00,0x00,0xFF,0x00,0x00,0x10,0x20,0xC2,
      0x01,0xFE,0x00,0x80,0x60,0x30,0x00,0x00
};

M.put_pic(0,0,16,16,pic,COVER,GREEN,TOP_LAYER);  //在顶层用绿色显示一个16X16图片,如果这个位置原来有数据,那么覆盖它。

向指定图层加入汉字

int put_HZ(int16_t x, int16_t y, const char p[], uint8_t mode,uint8_t color,uint8_t index);

eg:

const char ni[] =
{
      0x02,0x04,0x1F,0xE0,0x02,0x04,0x18,0xF0,
      0x10,0x13,0x10,0x10,0x14,0x18,0x00,0x00,
      0x00,0x00,0xFF,0x00,0x00,0x10,0x20,0xC2,
      0x01,0xFE,0x00,0x80,0x60,0x30,0x00,0x00
};

M.put_HZ(0,0,ni,COVER,GREEN,TOP_LAYER);  //在顶层(0,0)处用绿色显示汉字”你”,如果这个位置原来有数据,那么覆盖它。

向顶层图层加入汉字

int put_HZ(int16_t x, int16_t y, const char p[]);

eg:

const char ni[] =
{
      0x02,0x04,0x1F,0xE0,0x02,0x04,0x18,0xF0,
      0x10,0x13,0x10,0x10,0x14,0x18,0x00,0x00,
      0x00,0x00,0xFF,0x00,0x00,0x10,0x20,0xC2,
      0x01,0xFE,0x00,0x80,0x60,0x30,0x00,0x00
};

M.put_HZ(0,0,ni,COVER,GREEN,TOP_LAYER);  //在顶层(0,0)处用红色显示汉字”你”

向指定图层缓存中打印16bit数据(10进制)

int print(uint16_t data, uint8_t rotation, uint8_t mode,uint8_t color,uint8_t index);

eg:

M.set_cur(0,0);
M.print(2356,NO_ROT,COVER,GREEN,TOP_LAYER);  //在顶层(0,0)处开始用绿色显示2356,不翻转显示,如果这个位置有数据,那么覆盖它

向指定图层缓存中打印一个字符串

int print(const char p[], uint8_t rotation, uint8_t mode,uint8_t color,uint8_t index); //string

eg:

M.set_cur(NO_ROT);
M.print(“Hello Matrix”,NO_ROT,COVER,GREEN,TOP_LAYER);  //在顶层左上角开始用绿色打印字符串Hello Matrix。不翻转显示。

在指定图层上全屏显示彩虹

int rainbow(uint8_t index);

eg:

M.rainbow(TOP_LAYER);   //顶层显示彩虹

显示函数(调用后将进入此函数的死循环)

void display(void (*display_hook)());

eg:详见loop和hook函数介绍

清除所有图层缓存的所有数据

int clear(void);

eg: 略

清除指定图层缓存的所有数据

int clear(uint8_t index);

eg:略

清除指定图层缓存中指定矩形位置处所有数据

int clear(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint8_t index);

Eg:

M.clear(2,3,6,6,TOP_LAYER);    //清除顶层(2,3) (6,6)为对角顶点的矩形区域的所有数据

图层平移函数

int move(uint8_t dir, uint16_t step, uint8_t index);

eg:

M.move(RIGHT,1,TOP_LAYER);  //顶层向右平移一位

执行AT指令

int at_cmd(uint8_t *p);

eg: 详见AT指令支持调用的函数

AT命令支持调用的函数

plot                AT命令下不支持显示函数图象
clear               AT命令下支持clear的所有重载格式
print               AT命令下不支持字符串打印
put_char            AT命令下支持put_char的所有重载格式
add_layer           AT命令下不支持buf定义在bss和data段
remove_layer        AT命令下支持remove_layer的所有重载格式
move                AT命令下支持图层上下左右平移任意单位
set_cur             AT命令下支持set_cur的所有重载格式

loop和hook函数介绍

(假设是个2X2矩阵):

void loop()
{
    M.rainbow(TOP_LAYER);
    M.display(hook);
}

程序调用display后,会陷入这个函数永远不出来,我们需要向它传入一个回调函数指针,在刷新的间隔,这个回调函数将被调用,完成用户控制。这个hook函数的执行时间会影响到刷新频率,因此不能太长。如果采用硬件spi模式,这个函数执行时间也不能太短,太短的话会造成屏幕重影显示。在例程中有这个延时函数的指导使用时间,用户可根据自己的需要进行更改。

AT指令执行例程

这个函数执行后,可用串口(波特率115200)进行如下控制:

AT+clear() 清屏 AT+set_cur(0) 初始化不翻转显示时的光标位置 AT+print(123,0) 在顶层显示123 注:AT指令控制的print函数不支持显示字符串 AT+add_layer() 增加新图层 AT+set_cur(0,8) 重新设置光标位置 AT+put_char(0,8,65,1,0,3,1) 在(0,8)处翻转显示A,颜色是red+green AT+put_char(8,8,66,1,0,5,1) 在(8,8)处翻转显示B,颜色是red+blue AT+move(4,1,0) 图层0向右移动一格 AT+move(3,1,0) 图层0向左移动一格 AT+move(1,1,1) 图层1向上移动一格 AT+move(2,1,1) 图层1向下移动一格 AT+remove_layer(1) 移除图层1

程序实例:1X1

    /*****************************************************************************
    * Copyright:    ChengDu Geeker Tech. Co., Ltd. (DFRobot)
    * File name:      hello_matrix.pde
    * Description:    test the function of rgb matrix
    * Author:       wanghui_CD
    * Version:      V1.0
    * Date:         2012.06.21
    * History:      none
    *****************************************************************************/
    #include <rgb_matrix.h>
    #include <SPI.h>

    unsigned long time=0;
    unsigned int tick_100ms = 0;
    unsigned char counter=0;

    #define N_X 1
    #define N_Y 1

    /*
    //Interface shield ShiftOut connector
    #define DATA_PIN  9
    #define CLK_PIN   3
    */
    //Hardware SPI
    #define DATA_PIN  11
    #define CLK_PIN   13

    #define LATCH_PIN 8

    rgb_matrix M = rgb_matrix(N_X, N_Y, DATA_PIN, CLK_PIN, LATCH_PIN);

    unsigned char cmd[50]={0},cmd_num=0;
    unsigned char tmp =  'A';
    unsigned char st=0;

    void setup()
    {
           Serial.begin(115200);
           delay(200);
    }

    /*************************************************************************
    *  Description:
    *                         display callback function
    *        Receive AT comand via serial,and then run the right comand.
    *        This function can be run in sweep interval.
    *        Reduce delay time at function tail if screen blink.
    *        Increase delay time at function tail if screen shows a double image.
    * Param:   none
    * Retval:  none
    **************************************************************************/
    void hook(void)
    {
        int i = 0;
        unsigned long enter_time,exit_time;
        enter_time = micros();
        if((++counter)%10 == 0)
        {
            if(millis() - time >= 100)
            {
                time = millis();
                tick_100ms ++;
                M.move(UP,1,0);
                if(tick_100ms%2 == 0)
                {
                }
                if(tick_100ms%5 == 0)
                {
                    M.clear();
                    M.put_char(0,0,tmp+(st++)%26,1,MULTIPLY,RED << (st%3),TOP_LAYER);
                }
                if(tick_100ms%10 == 0)
                {
                }
                if(tick_100ms%20 == 0)
                {
                }
                if(tick_100ms%50 == 0)
                {
                }
            }
        }
        if(Serial.available())
        {
            cmd[cmd_num++] = Serial.read();
            if((cmd_num>=2) && (cmd[cmd_num-1] == 0x0a) && (cmd[cmd_num-2] == 0x0d))
            {
                M.at_cmd(cmd);
                cmd_num = 0;
            }
         }
         exit_time = micros();
         if(enter_time < exit_time)
         {
           if(exit_time - enter_time < 500)
           {
             delayMicroseconds(500 - (exit_time-enter_time));
           }
         }
    }

    /*************************************************************************************
    *  Description:
    *                         loop function
    *        Display function must be called.
    *        If you wanna do something after display be called,
    *    you should give display function a parameter which is a pointer to a function.
    * Param:   none
    * Retval:  none
    **************************************************************************************/
    void loop()
    {
        M.set_cur(0,0);
        M.display(hook);
    }

程序实例:2X2

    /*****************************************************************************
    * Copyright:  ChengDu Geeker Tech. Co., Ltd. (DFRobot)
    * File name:      hello_matrix.pde
    * Description:    test the function of rgb matrix
    * Author:       wanghui_CD
    * Version:      V1.0
    * Date:         2012.06.21
    * History:      none
    *****************************************************************************/
    #include <rgb_matrix.h>
    #include <SPI.h>

    unsigned long time=0;
    unsigned int tick_100ms = 0;
    unsigned char counter=0;

    #define N_X 2
    #define N_Y 2

    /*
    //Interface shield ShiftOut connector
    #define DATA_PIN  9
    #define CLK_PIN   3
    */
    //Hardware SPI
    #define DATA_PIN  11
    #define CLK_PIN   13

    #define LATCH_PIN 8

    rgb_matrix M = rgb_matrix(N_X, N_Y, DATA_PIN, CLK_PIN, LATCH_PIN);

    unsigned char cmd[50]={0},cmd_num=0;

    void setup()
    {
           Serial.begin(115200);
           delay(200);
    }

    /*************************************************************************
    *  Description:
    *                         display callback function
    *        Receive AT comand via serial,and then run the right comand.
    *        This function can be run in sweep interval.
    *        Reduce delay time at function tail if screen blink.
    *        Increase delay time at function tail if screen shows a double image.
    * Param:   none
    * Retval:  none
    **************************************************************************/
    void hook(void)
    {
        int i = 0;
        if((++counter)%5 == 0)    //如果100ms时钟不准,5这个值是可以微调的
        {
            if(millis() - time >= 100)
            {
                time = millis();
                tick_100ms ++;
                if(tick_100ms%2 == 0)
                {
                }
                if(tick_100ms%5 == 0)
                {
                }
                if(tick_100ms%10 == 0)
                {
                    M.move(LEFT,1,TOP_LAYER);    //顶层(图层0)每秒左移一位
                }
                if(tick_100ms%20 == 0)
                {
                    M.move(RIGHT,1,TOP_LAYER+1);   //图层1每2秒右移一位
                }
                if(tick_100ms%50 == 0)
                {
                }
            }
        }
        if(Serial.available())                            //接收AT指令
        {
            cmd[cmd_num++] = Serial.read();
            if((cmd_num>=2) && (cmd[cmd_num-1] == 0x0a) && (cmd[cmd_num-2] == 0x0d))
            {
                M.at_cmd(cmd);
                cmd_num = 0;
            }
         }
    }

    /*************************************************************************************
    *  Description:
    *                         loop function
    *        Display function must be called.
    *        If you wanna do something after display be called,
    *    you should give display function a parameter which is a pointer to a function.
    * Param:   none
    * Retval:  none
    **************************************************************************************/
    void loop()
    {
        int tmp,i;
        M.add_layer();
        M.put_char(0,0,'A',NO_ROT,MULTIPLY,RED,TOP_LAYER);
        M.put_char(5,0,'B',NO_ROT,MULTIPLY,GREEN,TOP_LAYER);
        M.put_char(10,0,'C',NO_ROT,MULTIPLY,BLUE,TOP_LAYER);

        M.put_char(0,8,'D',NO_ROT,MULTIPLY,GREEN+RED,1);
        M.put_char(5,8,'E',NO_ROT,MULTIPLY,RED+BLUE,1);
        M.put_char(10,8,'F',NO_ROT,MULTIPLY,BLUE+GREEN,1);
        M.display(hook);
    }

相关资料

原理图 数据手册 rgb_matrix_1.0版库文件 rgb_matrix_0023版库文件 8*8 LED 三色多彩显示矩阵模块介绍

<File:nextredirectltr.png>购买 8*8 LED 三色多彩显示矩阵模块(SKU:DFR0202)