News

Interfacing a MAX7219 Driven LED Matrix with ATtiny85

LED Matrix 8x8 MAX7219 Assembling

UPDATE 2022: The MAX7219LED8x8 library, now renamed to MAX7219tiny has now a new home at tinusaur.com/libraries/max7219tiny. Check also this MAX7219 & ATtiny85 tutorial to learn how the library works.

The MAX7219 controller manufactured by Maxim Integrated is a 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 than 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 1 to 8) 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.

The Blocktinu App for Windows version 1.2.1 is out

Blocktinu Windows App

We have just deployed a new version of the Blocktinu Windows application.

It is available for download from BLOCKTINU.com/downloads website.

WHAT’S NEW?

Besides some visual changes, there is a new button to upload some testing code to your Tinusaur Board with an EDUx4IO Shield. That is very convenient for testing if the board was assembled correctly even before you start writing some code.

A more detailed guide on how to setup Blocktinu on Windows is available as a PDF file for download at Blocktinu Tools – Windows Setup (slides).pdf.

We’d like to hear your opinion, so please drop a comment.

Blocktinu Tools – Windows Setup (slides)

Blocktinu Tools - Windows Setup (slides)

This is the first draft of the guide on how to setup the Blocktinu Tools under Windows.

Tinusaur Blocktinu Logo

The file in PDF format is available at this location: Blocktinu_Tools_for_Windows_Setup_Guide.pdf

Please, download it and take a look. If you feel that there’s missing something or wrong, please, let us know.

When we update the files we will commit changes in this repository: https://bitbucket.org/tinusaur/blocktinu-docs/.

UPDATE (2021): Bitbucket no longer hosts our project. 🙁

Our source code is available at
— https://gitlab.com/tinusaur
— https://github.com/tinusaur (mirror)

Check also the Guides section of our website.

Updated User Guides for the Main Board, Shield LEDx2 and EDUx4IO

Main Board Shields LEDx2 EDUx4IO

We have updated the user guides for how to assemble the Tinusaur Board, Shield LEDx2 and Shield EDUx4IO. They are all in PDF format and are available at the following links:

The collection of user guides is at tinusaur.org/guides.

Our plans are, once finalized, to convert those slides to video and upload them to YouTube – that appears to be more convenient for some people. Also, add some voice-over … maybe. 🙂

Tinusaur Workshop UNI4KIDS Drenta

We’d like to ask you to take a look at the user guides and if you think there’s something to be added or changed, please, leave a comment below this post.

 

 

Tinusaur Selected as Best National Digital Solution for International World Summits Awards in the Category Learning & Education

TINUSAUR was nominated as best national digital solution for BULGARIA for the international World Summit Awards

TINUSAUR SELECTED AS BEST NATIONAL DIGITAL SOLUTION FOR INTERNATIONAL WORLD SUMMITS AWARDS IN THE CATEGORY LEARNING & EDUCATION

Veliko Tarnovo/Salzburg, 2018-10-24

TINUSAUR was nominated as the best national digital solution for BULGARIA for the international World Summit Awards (WSA). The World Summit Awards are a global initiative selecting digital innovation making a positive impact on society. With this nomination in the Category Learning & Education TINUSAUR qualifies for evaluation among over 400 international projects by the WSA Jury 2018.

TINUSAUR was nominated as the best national digital solution for BULGARIA for the international World Summit Awards.

The Tinusaur is an educational platform and set of tools that focus on programming, robotics, and electronics and applying modern learning methods in an effort to present science and technology in an interesting and entertaining way to the students. It is a mixture of software and hardware. Here it is described in 3 simple steps: (1) you assemble your hardware yourself by soldering your board; then (2) you learn how to program it using puzzle-like blocks; then (3) you learn how to write C code. … After that, your imagination is the limit.

The Tinusaur project and its tools are currently being used in universities, schools, and as part of other educational initiatives all around the world. In such environments, the students get to keep their broads for themselves, take them home, play with them, make things and write programs. This is unlike many other similar products and solutions that are so expensive that there are just a few per class or school and the teachers keep them within the facilities.

The WSA nominees 2018 show the richness, diversity, and innovation of digital solutions on a global scale and prove how digital technology can improve society on each corner of the world. The WSA 2018 nominees will be evaluated based on seven fundamentals criteria: Content, Functionality, Design, Technology, Innovation, Impact and Global/UN value.

Each year, WSA nominees are selected by the WSA National Experts from more than 180 UN member states. The WSA National Experts nominate up to eight projects for each country – one for every WSA category.

A nomination to the WSA hence is already an award in itself – the qualification to compete and be presented on an international level and being the best practice in Learning & Education nationally.

About the Tinusaur OOD

The Tinusaur OOD, the Bulgarian company established earlier in 2018, is currently selling products and generates revenue that ensures the future of the project. It received an investment from 2 private individuals and has developed plans for the next 2 and 5 years as part of the planning for the next round if funding.

About the WSA

The World Summit Award is a global initiative within the framework of the United Nations World Summit on the Information Society (WSIS). WSA is the only ICT event worldwide, that reaches the mobile community in over 180 countries. WSA highlights digital content improving society and focusses on local content with global relevance.

Visit us on www.worldsummitawards.org, Facebook and Twitter, #WSA18

Media Contact World Summit Award:
Manuela Wagner
Network Development & Communications,
World Summit Awards
manuela@worldsummitawards.org
+43.660.630408.7

 

How to Assemble Your Tinusaur Shield LEDx2 – Guide (slides)

Tinusaur Shield LEDx2 - Assembling (slides)
Shield LEDx2 Assembled

We have just finished another guide – this time about how to assemble your Tinusaur Shield LEDx2.

The file in PDF format is available at this location:  Tinusaur Shield LEDx2 – Assembling (slides).

Please, download it and take a look. If you feel that there’s missing something or wrong, please, let us know.

When we update the files we will commit changes in this repository: https://gitlab.com/tinusaur/shield-ledx2-docs/.

We have just made Blocktinu Windows app better

Here are the changes:

  • Fixed bug that caused an error message when there is a  space in the name of the HEX file or in the path to your user folder.

Now, the juicy part …

Blocktinu Windows Desktop Application

This is the first version of the Blocktinu Windows Desktop Application.

  • How, as part of the app, there are 2 pre-compiled programs that you could conveniently use to test your newly assembled board.
    1. Just an empty app that will allow you to see if the binary code goes from the your computer (if drivers have been installed correctly) through the USBasp ISP programmer and, into the microcontroller. That could also be used to check if the board has been assembled correctly.
    2. The other one is a simple app that will make any LED connected (through a resistor, of course) to any of the 5 available I/O pins – PB0, PB1, PB2, PB3, PB4 – blink. That could be used to test if the boards and the shields have been assembled correctly.

Using these 2 pre-compiled programs does not require anything that just pressing the “Upload” buttons on the screen – no writing code, no compiling, building or downloading.

The latest version is available for download at: https://bitbucket.org/tinusaur/blocktinu-tools-win/downloads/blocktinu-tools-1.1.1-install.zip

More and up to date information is also available at blocktinu.com.

Please, let us know what do you think.

Tinusaur Board 3 STD – Assembling (slides)

This is the Tinusaur Board 3 STD Assembling Guide. It is at the moment in PDF format but the plans are to generate a video and add a voice-over.

The file is located here: Tinusaur Board 3 – Assembling (slides).pdf
(NOTE: File name was changed and link updated here)

We would like to ask you to download it and take a look. If you think that something should be added or changed please leave a comment below this post.

We’re already working on similar guides for all other boards, bundles, and kits.