BugOne driving a LED matrix

It’s been a while since my last blink on this blog. Today I’m gonna blink 64 LEDs … I mean an 8×8 LED matrix. This article is about driving a LED matrix from a MAX 7219 with a BugOne board (code for Arduino also provided).

The setup is really simple since the LED matrix and the MAX 7219 come from an “evaluation kit” I bought on eBay (search for MAX7219 LED MATRIX KIT). The kit come soldered, and provide access to pins : Gnd, Vcc, Din, Clk and CS/Load.

I had no issue powering the kit either in 3.3V with the BugOne and in 5V with the Arduino. The connections between the matrix kit and the Arduino or BugOne boards are the following:

  • BugOne: Din=PortB 0, Clk=PortB 1, CS/Load= PortB 2.
  • Arduino: Din= 13, Clk= 12, CS/Load= 11.

There are no special issues with the code. Communication with the MAX7219 is pretty simple, words of 16 bits are transferred through Din and Clk: 4bits at 0, 4 bits for the command and 8 bits for the data. Code in MAX7219.h file show a list of all available commands:

// --- MAX7219 COMMANDS ---
#define CMD_NOOP 0x0000
#define CMD_DIGIT_0 0x0100
#define CMD_DIGIT_1 0x0200
#define CMD_DIGIT_2 0x0300
#define CMD_DIGIT_3 0x0400
#define CMD_DIGIT_4 0x0500
#define CMD_DIGIT_5 0x0600
#define CMD_DIGIT_6 0x0700
#define CMD_DIGIT_7 0x0800
#define CMD_DECODE_MODE 0x0900
#define CMD_INTENSITY 0x0A00
#define CMD_SCAN_LIMIT 0x0B00
#define CMD_SHUTDOWN 0x0C00
#define CMD_DISPLAY_TEST 0x0F00

I decided to code them directly on 2 bytes to avoid the need for a 8 bit shift afterwards. I didn’t wrote a lot of functions to drive the matrix. First one inits the matrix, second writes a command and the last one is more useful because it allows to send a ‘picture’ from 8 bytes:

extern void matrix_init();
extern void matrix_write(uint16_t data);
extern void matrix_img(uint8_t * img);

Implementation for theses functions is not described here but is available in the archive (see at the end of the article). In fact it is really close to the code provided in a previous article on the MAX6969: setting data pin, performing a clock cycle and validating the data in the end.

One thing more interesting is the use of these functions to show the smiley face from the picture. Note that there is also an home displayed alternatively.

// --- Data ---

char img1[] = {    
char img2[] = {    

// --- Main ---

int main(void) {
	while (1) {

The longest part of this code is to set the data for the images. While the use of binary notation makes code longer, it allows to edit images by hand more easily.

So this is it, today I blinked a LED matrix. As promised, code is available in following archives for both the BugOne and the Arduino.

3 Replies to “BugOne driving a LED matrix”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.