Go Down

Topic: Tutorial/Tips: 8x8 LED Matrix + Attiny2313 using Mega ADK (Read 7500 times) previous topic - next topic


Hey everyone!

This is my first topic and post and I hope that some of you find it useful! Well I've learned a lot from this forum and thought it was time to give something back! =)..

My first problem that I kinda bumped in was that I wanted to use my Mega ADK R3 to program a ATtiny2313 with the help of the ArduinoISP sketch. I got a lot of problems with the communication between the ATtiny2313 and the Mega ADK. I disabled the auto-reset feature with the help of a 10uF capacitor but still got the "sync" error and the Device signature error. And all the information that I found was kinda related to the arduino UNO or Duemilanove, nothing useful about the MEGA or MEGA ADK. What I discovered is that the avrdude that comes with Arduino IDE 1.0.1 misses some config files. So what I did is I downloaded and installed WinAVR from http://sourceforge.net/projects/winavr/files/. After that I connected the arduino mega as the following schematic and typed the following in cmd.exe.
Code: [Select]
avrdude -c stk500v1 -P com9 -p t2313 -b 19200 -v -v
Note that the arduino mega contains an unmodified version of the ArduinoISP sketch.

Avrdude was able to communicate with the ATtiny2313 and it gave me the right device signature.

After that was done I reopened Arduino IDE 1.0.1 and successfully burned the "bootloader"/fuses for ATtiny2313 8MHz internal oscillator with "arduino-tiny" installed.

I wanted my ATtiny2313 to display a message on the LED matrix but bumped in the lacking SRAM volume.So what I did is modify my sketch to put all of my large arrays in the flash memory using the PROGMEM library. After successfully uploading the sketch to ATtiny2313, I connected the LED Matrix and power supply as the following schematic.

And here is the arduino sketch:

Code: [Select]
LEDMATTINY_DISP by Baselsw 2012. This code uses a ATtiny2313 to directly drive a 8x8 LED matrix.

Please use this code as you wish!! =D Enjoy!


#include <avr/pgmspace.h>

const int row[8]={ //Row pins
const int col[8]={ //Column pins

PROGMEM const byte font8x8[28][8] = { //Font matrix
    0x80, 0x60, 0x18, 0x14, 0x13, 0x3C, 0xC0, 0x00      }
  ,  // Code for char A 0
    0x00, 0xFF, 0x91, 0x91, 0x99, 0x66, 0x00, 0x00      }
  ,  // Code for char B 1
    0x78, 0x84, 0x82, 0x81, 0x81, 0x43, 0x00, 0x00      }
  ,  // Code for char C 2
    0x00, 0xFF, 0x81, 0x82, 0x82, 0x44, 0x38, 0x00      }
  ,  // Code for char D 3
    0x00, 0xFF, 0x89, 0x89, 0x89, 0x89, 0x00, 0x00      }
  ,  // Code for char E 4
    0x00, 0xFF, 0x09, 0x09, 0x09, 0x01, 0x00, 0x00      }
  ,  // Code for char F 5
    0x78, 0x84, 0x92, 0x91, 0x91, 0x51, 0x32, 0x00      }
  ,  // Code for char G 6
    0x00, 0xFF, 0x08, 0x08, 0x08, 0x08, 0xFF, 0x00      }
  ,  // Code for char H 7
    0x81, 0x81, 0xFF, 0x81, 0x81, 0x00, 0x00, 0x00      }
  ,  // Code for char I 8
    0x60, 0x80, 0x81, 0x81, 0xFF, 0x01, 0x01, 0x00      }
  ,  // Code for char J 9
    0x00, 0xFF, 0x18, 0x24, 0x42, 0x81, 0x00, 0x00      }
  ,  // Code for char K 10
    0x00, 0xFF, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00      }
  ,  // Code for char L 11
    0xC0, 0x38, 0x07, 0x38, 0xC0, 0x38, 0x07, 0xF8      }
  ,  // Code for char M 12
    0x00, 0xFF, 0x02, 0x0C, 0x10, 0x20, 0x40, 0xFF      }
  ,  // Code for char N 13
    0x00, 0x7C, 0x82, 0x81, 0x81, 0x81, 0x41, 0x3E      }
  ,  // Code for char O 14
    0x00, 0xFF, 0x21, 0x21, 0x1E, 0x00, 0x00, 0x00      }
  ,  // Code for char P 15
    0x00, 0x3C, 0x42, 0x81, 0xA1, 0x41, 0x81, 0x7E      }
  ,  // Code for char Q 16
    0x00, 0xFF, 0x11, 0x31, 0x4E, 0x80, 0x00, 0x00      }
  ,  // Code for char R 17
    0x00, 0x40, 0x86, 0x89, 0x89, 0x89, 0x71, 0x00      }
  ,  // Code for char S 18
    0x01, 0x01, 0x01, 0xFF, 0x01, 0x01, 0x01, 0x00      }
  ,  // Code for char T 19
    0x00, 0x7F, 0x80, 0x80, 0x80, 0x80, 0x7F, 0x00      }
  ,  // Code for char U 20
    0x00, 0x07, 0x78, 0x80, 0x78, 0x07, 0x00, 0x00      }
  ,  // Code for char V 21
    0xFF, 0xE0, 0x30, 0x18, 0x18, 0x70, 0xC0, 0xFF      }
  ,  // Code for char W 22
    0x81, 0x42, 0x24, 0x18, 0x24, 0x42, 0x81, 0x00      }
  ,  // Code for char X 23
    0x01, 0x06, 0xD8, 0x30, 0x0E, 0x01, 0x00, 0x00      }
  ,  // Code for char Y 24
    0xC1, 0xA1, 0x91, 0x89, 0x85, 0x83, 0x81, 0x00      }
  ,   // Code for char Z 25
    0x0E, 0x1F, 0x7F, 0xFE, 0xFE, 0x7F, 0x1F, 0x0E     }
  , // Code for HEART 26
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00    } // Code for SPACE 27

void setup() {               
  for(int i=0;i<8;i++){
    pinMode(row[i], OUTPUT);    //Set row pins as output
    pinMode(col[i],OUTPUT);     //Set column pins as output
    digitalWrite(row[i], LOW);   // turn off rows
    digitalWrite(col[i], HIGH);   // turn off columns

void display_char(int character ){
  for (int i=0;i<8;i++){ //Cycle through columns

    byte coldata = pgm_read_byte(&font8x8[character][i]); //read column data from PROGMEM
    digitalWrite(col[i],LOW); //Allow current flow in the i'th column
    for(int j=0;j<8;j++){ //cycle through row data

      int x = bitRead(coldata,j); //Read the first bit from the byte (coldata)
      digitalWrite(row[j],x);     // Set the row to 1 or 0

    delayMicroseconds(300);  //Delay for 300us between each segment/column. Don't go bellow 300us!!
    clearOutput(); //turn off display

void clearOutput(){
  for(int i=0;i<8;i++){
    digitalWrite(row[i],LOW); //Turn off rows
    digitalWrite(col[i],HIGH); //Turn off columns

void loop() {
  byte msg[]={8,27,26,27,20,27,9,0,2,10,11,8,13,4}; //Message to be displayed. Numbers corresponds to the position of each letter in the font matrix.
                                                    // In this case the message would be "I 'HEART' U JACKLINE"
for(int i = 0;i<14;i++){ // For each character in msg (total of 14 characters)
    int count=0;       
    display_char(msg[i]); //Show the same letter 250 times ~ 250*8*300us = 0.6s for each letter.
  delayMicroseconds(100); //Delay between each character for stability

And that's it!! I know this was kinda brief but I didn't want to go into a lot of details. If you got any questions I'll be more than happy to answer them!!

This is my finished product ;)!!


Go Up