[vc_row][vc_column width=”1/1″][vc_column_text]LED Matrix Kit s a serially driven 8×8 LED Matrix kit powered by MAX7219. It only needs three data lines and two power lines.
The 8×8 LED Matrix is easy to use and compatible with pcDuino/Arduino, and its LED brightness adjustment can be implemented in software.
8×8 LED Matrix kit has many applications in real life, such as various types of electronic display panels. If the LED matrix is not driven by any peripherals, it’ll waste the interface of devices, and the LED brightness will be impaired due to insufficient power, so that we cannot get ideal display effect.
The LED matrix can be driven in two ways: parallel or serial. We usually drive it in the serial manner in order to save interface. The serial-driven LED matrix actually dynamically displays the LEDs, i.e., displays the LEDs row-by-row or column-by-column. The persistence of vision for humans is about 0.1s, so as long as we can serially display all 8 rows/columns within 0.1s, we’ll see a complete character or pattern.
In this post, we are going to show to interface LED matrix kit to pcDuino.[/vc_column_text][vc_tour][vc_tab title=”Wire Diagram” tab_id=”1384718887-1-93″][vc_column_text]
- VCC of LED Matrix kit is connected to VCC of pcDuino.
- GND of LED Matrix kit is connected to GND of pcDuino.
- CLK of LED Matrix kit is connected to D8 of pcDuino.
- CS of LED Matrix kit is connected to D9 of pcDuino.
- DIN of LED Matrix kit is connected to D10 of pcDuino.
[/vc_column_text][/vc_tab][vc_tab title=”Obstain Arduino-ish API” tab_id=”1384718887-2-6″][vc_column_text]We need to use get the Arduino-ish API from github.
If you haven’t installed git on pcDuino before, we first need to intsall git first by doing:
$sudo apt-get install git
Then, we can obtain the API:
ubuntu@ubuntu:~$ git clone http://www.github.com/pcduino/c_enviroment
[/vc_column_text][/vc_tab][vc_tab title=”C Code” tab_id=”1384719166573-2-6″][vc_column_text]The code is shown below:
#include "core.h"
unsigned char i;
unsigned char j;
int Max7219_pinCLK = 8;
int Max7219_pinCS = 9;
int Max7219_pinDIN = 10;
unsigned char disp1[38][8] =
{
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//0
{0x10,0x30,0x50,0x10,0x10,0x10,0x10,0x10},//1
{0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
{0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
{0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
{0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
{0x3C,0x20,0x20,0x3C,0x24,0x24,0x3C,0x0},//6
{0x3E,0x22,0x4,0x8,0x8,0x8,0x8,0x8},//7
{0x0,0x3E,0x22,0x22,0x3E,0x22,0x22,0x3E},//8
{0x3E,0x22,0x22,0x3E,0x2,0x2,0x2,0x3E},//9
{0x8,0x14,0x22,0x3E,0x22,0x22,0x22,0x22},//A
{0x3C,0x22,0x22,0x3E,0x22,0x22,0x3C,0x0},//B
{0x3C,0x40,0x40,0x40,0x40,0x40,0x3C,0x0},//C
{0x7C,0x42,0x42,0x42,0x42,0x42,0x7C,0x0},//D
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x7C},//E
{0x7C,0x40,0x40,0x7C,0x40,0x40,0x40,0x40},//F
{0x3C,0x40,0x40,0x40,0x40,0x44,0x44,0x3C},//G
{0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x44},//H
{0x7C,0x10,0x10,0x10,0x10,0x10,0x10,0x7C},//I
{0x3C,0x8,0x8,0x8,0x8,0x8,0x48,0x30},//J
{0x0,0x24,0x28,0x30,0x20,0x30,0x28,0x24},//K
{0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x7C},//L
{0x81,0xC3,0xA5,0x99,0x81,0x81,0x81,0x81},//M
{0x0,0x42,0x62,0x52,0x4A,0x46,0x42,0x0},//N
{0x3C,0x42,0x42,0x42,0x42,0x42,0x42,0x3C},//O
{0x3C,0x22,0x22,0x22,0x3C,0x20,0x20,0x20},//P
{0x1C,0x22,0x22,0x22,0x22,0x26,0x22,0x1D},//Q
{0x3C,0x22,0x22,0x22,0x3C,0x24,0x22,0x21},//R
{0x0,0x1E,0x20,0x20,0x3E,0x2,0x2,0x3C},//S
{0x0,0x3E,0x8,0x8,0x8,0x8,0x8,0x8},//T
{0x42,0x42,0x42,0x42,0x42,0x42,0x22,0x1C},//U
{0x42,0x42,0x42,0x42,0x42,0x42,0x24,0x18},//V
{0x0,0x49,0x49,0x49,0x49,0x2A,0x1C,0x0},//W
{0x0,0x41,0x22,0x14,0x8,0x14,0x22,0x41},//X
{0x41,0x22,0x14,0x8,0x8,0x8,0x8,0x8},//Y
{0x0,0x7F,0x2,0x4,0x8,0x10,0x20,0x7F},//Z
{0x8,0x7F,0x49,0x49,0x7F,0x8,0x8,0x8},//中
{0xFE,0xBA,0x92,0xBA,0x92,0x9A,0xBA,0xFE},//国
};
void Write_Max7219_byte(unsigned char DATA)
{
unsigned char i;
digitalWrite(Max7219_pinCS,LOW);
for(i=8;i>=1;i--)
{
digitalWrite(Max7219_pinCLK,LOW);
if((DATA&0x80)==0x80) digitalWrite(Max7219_pinDIN,HIGH);
else digitalWrite(Max7219_pinDIN,LOW);
DATA = DATA<<1;
digitalWrite(Max7219_pinCLK,HIGH);
}
}
void Write_Max7219(unsigned char address,unsigned char dat)
{
digitalWrite(Max7219_pinCS,LOW);
Write_Max7219_byte(address); //写入地址,即数码管编号
Write_Max7219_byte(dat); //写入数据,即数码管显示数字
digitalWrite(Max7219_pinCS,HIGH);
}
void Init_MAX7219(void)
{
Write_Max7219(0x09, 0x00);
Write_Max7219(0x0a, 0x03);
Write_Max7219(0x0b, 0x07);
Write_Max7219(0x0c, 0x01);
Write_Max7219(0x0f, 0x00);
}
void setup()
{
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
pinMode(Max7219_pinCLK,OUTPUT);
pinMode(Max7219_pinCS,OUTPUT);
pinMode(Max7219_pinDIN,OUTPUT);
delay(50);
Init_MAX7219();
}
void loop()
{
for(j=0;j<38;j++)
{
for(i=1;i<9;i++)
Write_Max7219(i,disp1[j][i-1]);
delay(500);
}
}
The code can also be downloaded from here.
[/vc_column_text][/vc_tab][vc_tab title=”Compile” tab_id=”1384719275861-3-1″][vc_column_text]Edit \test\Makefile:
LIBS=-L../../sample/core -larduino -lspi
INCS=-I../../sample/core/include
TARGET=../../sample/test
OBJS = io_test adc_test pwm_test spi_test adxl345_test led_matrix_kit
all: $(OBJS)
@mkdir -p $(TARGET)
@mv $(OBJS) $(TARGET)
io_test: io_test.c
$(CC) $(LIBS) $(INCS) $< -o $@
led_matrix_kit: led_matrix_kit.c
$(CC) $(LIBS) $(INCS) $< -o $@
adc_test: adc_test.c
$(CC) $(LIBS) $(INCS) $< -o $@
pwm_test: pwm_test.c
$(CC) $(LIBS) $(INCS) $< -o $@
spi_test: spi_test.c
$(CC) $(LIBS) $(INCS) $< -o $@
adxl345_test: adxl345_test.c
$(CC) $< -o $@
clean:
@for i in $(OBJS); do rm -f $(TARGET)/$$i; done
In the above, led_matrix_kit :led_matrix_kit.c is the newly added program.
Next we can open a terminal and build the code:
ubuntu@ubuntu:~$ cd c_enviroment
ubuntu@ubuntu:~/c_enviroment $ make[/vc_column_text][/vc_tab][vc_tab title=”Execution” tab_id=”1384719350794-4-0″][vc_column_text]We enter directory /test, and type:
sudo ./led_matrix_kit
to run the code.
The following shows the setup:
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.