Interfacing a MAX7219 Driven LED Matrix with ATtiny85

LED Matrix 8x8 MAX7219 Assembling

The MAX7219 controller is manufactured by Maxim Integrated is compact, serial input/output common-cathode display driver that could interface microcontrollers to 64 individual LEDs, 7-segment numeric LED displays of up to 8 digits, bar-graph displays, etc. Included on-chip are a BCD code-B decoder, multiplex scan circuitry, segment and digit drivers and an 8×8 static RAM that stores each digit. 

The MAX7219 modules are very convenient to use with microcontrollers such as ATtiny85, or, in our case the Tinusaur Board.

The Hardware

The MAX7219 modules usually look like this:

MAX7219 Module LED Matrix 8x8
MAX7219 Module and LED Matrix 8×8

They have an input bus on one side and output bus on the other. This allows you to daisy chain 2 or more modules, i.e. one after another, to create more complicated setups.

The modules that we are using are capable of connecting in a chain using 5 small jumpers. See the picture below.

MAX7219 Module LED Matrix 8x8
2x MAX7219 Modules Connected

Pinout and Signals

MAX7219 module has 5 pins:

  • VCC – power (+)
  • GND – ground (-)
  • DIN – Data input
  • CS – Chip select
  • CLK – Clock

That means that we need 3 pins on the ATtiny85 microcontroller side to control the module. Those will be:

  • PB0 – connected to the CLK
  • PB1 – connected to the CS
  • PB2 – connected to the DIN

This is sufficient to connect to the MAX7219 module and program it.

The Protocol

Communicating with the MAX7219 is relatively easy – it uses a synchronous protocol which means that for every data bit we send there is a clock cycle that signifies the presence of that data bit.

MAX7219 Timing Diagram
MAX7219 Timing Diagram

In other words, we send 2 parallel sequences to bits – one for the clock and another for the data. This is what the software does.

The Software

The way this MAX7219 module works is this:

  • We write bytes to its internal register.
  • MAX7219 interprets the data.
  • MAX7219 controls the LEDs in the matrix.

That also means that we don’t have to circle through the array of LEDs all the time in order to light them up – the MAX7219 controller takes care of that. It could also manage the intensity of the LEDs.

So, to use the MAX7219 modules in a convenient way we need a library of functions to serve that purpose.

First, we need some basic functions in order to write to the MAX7219 registers.

  • Writing a byte to the MAX7219.
  • Writing a word (2 bytes) to the MAX7219.

The function that writes one byte to the controller looks like this:

void max7219_byte(uint8_t data) {
    for(uint8_t i = 8; i >= 1; i--) {
        PORTB &= ~(1 << MAX7219_CLK);   // Set CLK to LOW
        if (data & 0x80)                // Mask the MSB of the data
            PORTB |= (1 << MAX7219_DIN);    // Set DIN to HIGH
        else
            PORTB &= ~(1 << MAX7219_DIN);   // Set DIN to LOW
        PORTB |= (1 << MAX7219_CLK);        // Set CLK to HIGH
        data <<= 1;                     // Shift to the left
    }
}

Now that we can send bytes to the MAX7219 we can start sending commands. This is done by sending 2 byes – 1st for the address of the internal register and the 2nd for the data we’d like to send.

There is more than a dozen of register in the MAX7219 controller.

MAX7219 Registers and Commands
MAX7219 Registers and Commands

Sending a command, or a word, is basically sending 2 consecutive bytes. The function implementing that is very simple.

void max7219_word(uint8_t address, uint8_t data) {
    PORTB &= ~(1 << MAX7219_CS);    // Set CS to LOW
    max7219_byte(address);          // Sending the address
    max7219_byte(data);             // Sending the data
    PORTB |= (1 << MAX7219_CS);     // Set CS to HIGH
    PORTB &= ~(1 << MAX7219_CLK);   // Set CLK to LOW
}

It is important to note here the line where we bring the CS signal back to HIGH – this marks the end of the sequence – in this case, the end of the command. A similar technique is used when controlling more that one matrix connected in a chain.

Next step, before we start turning on and off the LEDs, is to initialize the MAX7219 controller. This is done by writing certain values to certain registers. For convenience, while coding it we could put the initialization sequence in an array.

uint8_t initseq[] = {
    0x09, 0x00, // Decode-Mode Register, 00 = No decode
    0x0a, 0x01, // Intensity Register, 0x00 .. 0x0f
    0x0b, 0x07, // Scan-Limit Register, 0x07 to show all lines
    0x0c, 0x01, // Shutdown Register, 0x01 = Normal Operation
    0x0f, 0x00, // Display-Test Register, 0x00 = Normal Operation
};

We just need to send the 5 commands above in a sequence as address/data pairs.

Next step – lighting up a row of LEDs.

This is very simple – we just write one command where 1st byte is the address (from 0 to 7) and the 2nd byte is the 8 bits representing the 8 LEDs in the row.

void max7219_row(uint8_t address, uint8_t data) {
    if (address >= 1 && address <= 8) max7219_word(address, data);
}

It is important to note that this will work for 1 matrix only. If we connect more matrices in a chain they will all show the same data. The reason for this is that after sending the command we bring the CS signal back to HIGH which causes all the MAX7219 controllers in the chain to latch and show whatever the last command was.

Testing

This is a simple testing program that lights up a LED on the first row (r=1) on the right-most position, then moves that on the left until it reaches the left-most position, then does the same on one row up (r=2) )until it reaches the top (r=8).

max7219_init();
for (;;) {
    for (uint8_t r = 1; r <= 8; r++) {
        uint8_t d = 1;
        for (uint8_t i = 9; i > 0; i--) {
            max7219_row(r, d);
            d = d << 1;
            _delay_ms(50);
        }
    }
}
MAX7219 Testing MAX7219LED8x8 Library
MAX7219 Testing

This testing code doesn’t do much but it demonstrates how to communicate with the MAX7219 controller.

The MAX7219LED8x8 Library

All of the functions mentioned above are part of the MAX7219LED8x8 library. Its source code is available at https://bitbucket.org/tinusaur/max7219led8x8.

The Tinusaur Shield GAMEx3

If you already have a Tinusaur Board we have the Shield GAMEx3 for it to connect a MAX7219 module easier to your ATtiny85 microcontroller.

Shield GAMEx3
Shield GAMEx3

The Gametinu Project

The Gametinu is a small game platform that you could build yourself using the Shield GAMEx3 and a few more parts and tools.

Gametinu
Gametinu

References

MAX7219 specification and datasheet:


This article is a rewritten version of another article from 2014:
MAX7219 driver for LED Matrix 8×8.


Launching Crowdfunding Campaign in January

Tinusaur OLED SSD1306xLED Crowdfunding Campaign

It looks like that our most popular software library is the SSD1306xLED. This is a library for working with OLED displays based on the SSD1306 controller. So, we decided to create a Tinusaur shield to carry an OLED display and we’re thinking about putting it up for crowdfunding this January.

What could you do it a Tinusaur Board and an OLED display?

There is an internal temperature sensor built into the ATtiny85 microcontroller and you don’t need any external components to use it. You can read its value and show it on the display.

Tinusaur OLED SSD1306xLED
Tinusaur OLED SSD1306xLED measuring temperature and voltage

We’ve figured a way to measure the battery level (or the power supply voltage) connected to the ATtiny85 microcontroller by using the PB5 (that is the RESET pin, yes) and one additional resistor. It is not very precise but could give you an indication, at least.

DHT11 module
DHT11 Module

You could also connect one of those popular DHT11 sensor modules, measure temperature and humidity and show it on the screen.

BM180 module
BM180 Module

You could also connect the Bosch BMP180 sensor module and measure barometric pressure and temperature, and show it on the screen. That will also allow you to calculate the altitude – pretty neat, isn’t it?

The official announcement with information about the start date, goals and other details is coming up in early January.

BLOCKTINU – The Development Environment for the Tinusaur – ATtiny85 Microcontroller Board

BLOCKTINU - The Development Environment for the Tinusaur

The Blocktinu is the development environment for your Tinusaur microcontroller boards where you could use blocks to produce real C programming language source code.

As you move your blocks (on the left) to implement your algorithms, the source code (on the right) will be automatically updated. Pretty neat, huh?

Now you can start learning the C programming language by playing with the blocks and looking at the changes in the source code that has been generated.

Once your program is ready it will be compiled in the cloud so no installation of any SDK will be necessary. The resulting binary code for the ATtiny85 microcontroller will be returned back to you.

The Blocktinu is part of the Tinusaur project.

The Blocktinu and the Tinusaur are open source projects. Both the software and the hardware!

The Blocktinu is almost ready for public use.

The Blocktinu is part of the Tinusaur crowdfunding campaign that we have launched on January 22nd, 2018.

Support our crowdfunding campaign. Get yourself a Tinusaur microcontroller board. You will receive early access to the Blocktinu development environment.

ANNOUNCEMENT: The Tinusaur Crowdfunding Campaign on January 22nd 2018

Tinusaur Crowdfunding Campaign on January 22nd 2018

Campaign link: http://igg.me/at/tinusaur
Project link: http://tinusaur.org

  1. A small robot car that you could build yourself and program it to follow a black line on the floor.
  2. A small game platform, that you could build and program yourself.

Those are the Tinusaur project goodies. They can help you learn, teach and make things with microcontrollers, and have fun at the same time. This is what the Tinusaur project is about.

Next Monday, on January 22nd we are launching a crowdfunding campaign to make more of those fun projects.

Join us at http://igg.me/at/tinusaur and subscribe for updates about the launch.

 

GAMETINU – Small Game Platform, Powered by the Tinusaur – ATtiny85 Microcontroller Board

GAMETINU - Small Game Platform, Powered by the Tinusaur - ATtiny85 Microcontroller Board

The Gametinu is a small game platform that you could build yourself. But don’t worry, it isn’t that complicated. This circuit is very simple, and there are very few things that could go wrong. The “brain” of the Gametinu is the Tinusaur board, powered by the popular Atmel ATtiny85 microcontroller.

Once your Gametinu is ready you can start programming it.

On the frame, you have a small 64 LED display. Beneath the display, you have a button and a buzzer.

You can program the Gametinu to run one of those no-player games such as the “Conway’s Game of Life“. You could also program it to run simple one-button games such as the Stacker Game.

The Gametinu is part of the Tinusaur project. It is important to mention that the Tinusaur and the Gametinu are open source projects? Both the software and the hardware! You can buy all parts, fabricate the PCBs, and assemble them yourself.

The Gametinu is almost ready for production. It is now part of the crowdfunding campaign that we are launching on January 22nd, 2018.

Sounds interesting?

Subscribe to get updates about the launch. Link to the campaign: http://igg.me/at/tinusaur

More information about the Gametinu will be posted on its page.

 

CARTINU – Small Robot Car, Powered by the Tinusaur – ATtiny85 Board

CARTINU - Small Robot Car, Powered by the Tinusaur - ATtiny85 Board

The Cartinu is a small robot car that you could build yourself. But don’t worry! It isn’t that complicated – this circuit, is so simple, that there are very few things that could go wrong. The “brain” of the Cartinu is the Tinusaur board that is powered by the popular Atmel ATtiny85 microcontroller.

Once your Cartinu is ready you could start programming it.

On the chassis, you have 2 powerful planetary gear motors. You also have 2 infrared proximity sensors on the bottom of the chassis. That allows you to program the Cartinu to follow a black line on the floor.

The Cartinu is part of the Tinusaur project. It is important to mention that the Tinusaur and the Cartinu are an open source project? Both the software and the hardware! You can buy all parts, fabricate the PCBs, and assemble them yourself.

The Cartinu is almost ready for production and is part of the crowdfunding campaign that we are launching on January 22nd 2018.

Sounds interesting?

Subscribe to get updates about the launch.

 

More information about the Cartinu will be posted on its page.

 

Short Video about the Tinusaur Project

The Tinusaur Project

This is a short 2-minute video explaining what is the Tinusaur project about, who is it good for and what you could do with its microcontroller and shield boards.

The Tinusaur is a small microcontroller board with a tiny chip on it.

The Tinusaur board is powered by the popular Atmel ATtiny85 microcontroller. It comes as an assembly kit: a small package with parts – you get the chance to learn how to solder it. Don’t worry, it isn’t that complicated. This circuit is so simple that there are very few things that could go wrong.

Once your mainboard is ready you could start learning by making and playing using our shield boards.

Our shield called LEDx2 has 2 LEDs – Green and Red. It comes also in parts, so you have to assemble it yourself. You can make its LEDs to blink. For example: like the traffic lights.

Want to do more?

We also have the EDUx4IO shield designed primarily for education. It has 4 different components on it: LED, Buzzer, Button, Photoresistor. With the LED and the Buzzer, you have 2 ways to output digital and analog signals. With the Photoresistor and the Button, you have 2 ways to input digital and analog signals.

There is also temperature sensor built into the ATtiny85 microcontroller chip.

Workshop: Assembling the Tinusaur Kit in Varna, Bulgaria

Tinusaur Workshop VarnaLab Varna Bulgaria

This Saturday, September 2nd, we will have one day workshop for assembling the Tinusaur kits for those who supported our Indiegogo crowdfunding campaign. It will take place in Varna, Bulgaria, our host will be VarnaLab – the local hackerspace.

Tinusaur Board Parts

We will learn the basics of electronic components, microcontrollersATtiny85 in particular and, of course, how to solder.

We will bring to the workshop soldering irons and all the necessary materials to do the job. Also, for those who were not able to get one of the kits during our Indiegogo campaign, we will have some for sale.

Tinusaur Workshop

At the moment we can organize such workshops only in Bulgaria but we’d really like to start doing this in other countries. Volunteers are very welcome. 🙂

This is the Facebook event: https://www.facebook.com/events/842138465944360/
If you’re around, you’re welcome to come.

 

Where is the breadboard?

Tinusaur Boards Pinout

You may ask “How am I going to connect the Tinusaur Board to a breadboard for a quick start or prototyping?”.

Well, in most cases you won’t need a breadboard and the reason for that is the way the Tinusaur Board has been designed with 2 2-row headers that give you enough pins to do some prototyping directly on the board.

Tinusaur Boards Pinout

The 2 outer rows are always GND while the 2 inner rows are always signal (except when they duplicate the GND), and the Vcc is inner as well. On the newer version of the board, there is also e separate 2-pin (female or male) external power connector. The board could be powered by a coin cell battery as well or directly through the USBasp programmer. So, with 18+2=20 pins in total, it is more like a tiny breadboard where you can stick some wires or even some parts. Pretty neat, isn’t it?

If you’re not ready yet to prototype your own circuit you can use some of the shields we’ve got. To learn how to make a LED blink you could use the Tinusaur Shield LEDx2 or the upcoming Tinusaur Shield LEDx3. For more advanced topics you could use the Tinusaur Shield EDUx4IO that can help you learn how to work with buttons, produce sounds with a buzzer, read analog data such as light intensity using a photoresistor, and many other things.

So, do I need a breadboard for prototyping?

  • The answer is NO, you don’t need a breadboard in most cases.

Where is the Tinusaur project used?

Tinusaur Workshop

The Tinusaur Project is used in schools, universities, and clubs around the world.

In Formal Education

The Tinusaur Project is already getting traction in the field of the Formal learning.

In 2016 it was considered and later officially selected as the platform for the “Microcontrollers and embedded devices” class in St. Cyril and St. Methodius University of Veliko Tarnovo, in Bulgaria. It is now part of the curriculum. As part of that effort, we ran a quick funding campaign and successfully collect all the funds necessary to produce Tinusaur Starter EDU PLUS for each student so they can have on for free, assemble, program, and take them home. It was a huge success – all the students loved it.

Tinusaur Workshop in the University
Tinusaur Workshop in the University

In 2016, as part of a government-funded initiative “Tvoyat Chas” (in Bulgarian, eng.: “Your Class”) the Tinusaur Project was considered and later chosen as one of the kits to be used for high school students – age between 15 and 17. They just loved it.

In Informal Learning

Tinusaur Project Workshop UNI4KIDS

The Tinusaur Project is very popular in the field of the Informal learning for it is very affordable, easy to learn and work with.

In 2016 as part of a summer school of science organized by UNI4KIDS the Tinusaur Project was used in the electronics, microcontroller and robotics classes. Children of ages between 11 and 17 had the chance to learn how to solder, assemble their very first microcontroller board and program it. It was an incredible experience to work with such smart and motivated young people.

The Tinusaur Workshops

Since 2014 we’ve been organizing 1 or 2-day training workshops where people could get a Tinusaur kit, learn how to solder and assemble it, and write their first microcontroller programs.

Another two-day workshop about microcontrollers, soldering and Tinusaur
Another two-day workshop about microcontrollers, soldering, and Tinusaur

Gifts

On quite a few occasions colleagues of ours bundled Tinusaur Starter 2 kits as part of event gifts or prizes. What a great idea to give something to people that they can use to improve their knowledge and skills.

By Hobbyists

The last on the list but with the highest slice of the pie are the hobbyists. The number of boards we’ve shipped worldwide will soon reach the number 2000 and most of them go to people who would like to learn and make things with microcontrollers and create internet-of-things. The Tinusaur is the perfect start.

Supporters

We ran 2 Indiegogo crowdfunding campaigns. One – very successful, and the other one – semi-successful. That helped us a great deal. First, it proved that the Tinusaur project is something that people like and want to use, and second, it allowed us to start the production on a bit larger scale.

What’s Missing?

We would like, with the help of sponsors, to be able to send Tinusaur kits in parts of the world where people may not be able to afford to buy them. The Tinusaur is very, very inexpensive but still … it may not fit in the budget for some people.

So, if you’d like to help please get in touch with us. We’re open for ideas.