Pages: [1]   Go Down
Author Topic: 3x3 LED mulitplexing question  (Read 1002 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. It seems as if the pins are different. Here is my code, Im aware of the clock speed difference and Ive adjusted the delays and the delays appears to be fine.
Code:
byte leds[9][6] = {{LOW, HIGH, HIGH, HIGH, LOW, LOW},
                  {LOW, HIGH, HIGH, LOW, HIGH, LOW},
                  {LOW, HIGH, HIGH, LOW, LOW, HIGH},
                  {HIGH, LOW, HIGH, HIGH, LOW, LOW},
                  {HIGH, LOW, HIGH, LOW, HIGH, LOW},
                  {HIGH, LOW, HIGH, LOW, LOW, HIGH},
                  {HIGH, HIGH, LOW, HIGH, LOW, LOW},
                  {HIGH, HIGH, LOW, LOW, HIGH, LOW},
                  {HIGH, HIGH, LOW, LOW, LOW, HIGH}
};
byte n[9][9] = {{0,0,0,0,1,0,0,0,0},  // 1
               {1,0,0,0,0,0,0,0,1},  // 2
               {1,0,0,0,1,0,0,0,1},  // 3
               {1,0,1,0,0,0,1,0,1},  // 4
               {1,0,1,0,1,0,1,0,1},  // 5
               {1,0,1,1,0,1,1,0,1},  // 6
               {1,0,1,1,1,1,1,0,1},  // 7
               {1,1,1,1,0,1,1,1,1},  // 8
               {1,1,1,1,1,1,1,1,1}}; // 9
                                 
byte misc[11][9] = {{0,0,0,1,1,0,1,1,0},
                   {1,1,0,1,1,0,0,0,0},
                   {0,1,1,0,1,1,0,0,0},
                   {0,0,0,0,1,1,0,1,1},
                   {1,0,1,0,1,0,1,0,1},
                   {1,0,0,1,0,0,1,0,0},
                   {0,1,0,0,1,0,0,1,0},
                   {0,0,1,0,0,1,0,0,1},
                   {1,1,1,0,0,0,0,0,0},
                   {0,0,0,1,1,1,0,0,0},
                   {0,0,0,0,0,0,1,1,1}
                 };
                 
byte prop[4][9] = {{0,0,0,1,1,1,0,0,0},
                  {0,0,1,0,1,0,1,0,0},
                  {0,1,0,0,1,0,0,1,0},
                  {1,0,0,0,1,0,0,0,1}
                 };
                 
byte raider[4][9] = {{1,0,0,1,0,0,1,0,0},
                     {0,1,0,0,1,0,0,1,0},
                     {0,0,1,0,0,1,0,0,1},
                     {0,1,0,0,1,0,0,1,0},
                     };

void setup()
{
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
 
  clearLeds();
 
  digitalWrite(2, LOW); 
  digitalWrite(5, HIGH);
  delay(125);
  digitalWrite(2, HIGH); 
  digitalWrite(5, LOW);
  delay(125);
}

void loop()
{
  for( int repeat=0; repeat<10; repeat++)
  {
    for(int i=0; i<4; i++)
    {     
      for(int j=0; j<200; j++)
      {
        printPatern(raider[i]);
      }
    }
  }
 
  for( int repeat=0; repeat<10; repeat++)
  {
    int i = random(11);
    {     
      for(int j=0; j<250; j++)
      {
        printPatern(misc[i]);
      }
    }
  }
 
  for( int repeat=0; repeat<1; repeat++)
  {
    for(int i=0; i<3; i++)
    {
      for(int j=0; j<3; j++)
      {
        clearLeds();
        digitalWrite(i+2, LOW);
        digitalWrite(j+5, HIGH);
        delay(25);
      }
    }
  }
 
  for( int repeat=0; repeat<1; repeat++)
  {
    for(int i=0; i<9; i++)
    {     
      for(int j=0; j<200; j++)
      {
        printPatern(n[i]);
      }
    }
  }
 
  for( int repeat=0; repeat<10; repeat++)
  {
    for(int i=0; i<4; i++)
    {     
      for(int j=0; j<200; j++)
      {
        printPatern(prop[i]);
      }
    }
  } 
}

void clearLeds()
{
  digitalWrite(2, HIGH); 
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW); 
  digitalWrite(6, LOW); 
  digitalWrite(7, LOW);
}

void printPatern(byte* number)
{
  for(int i=0; i<9; i++)
  {
    if(number[i] == 1)
    {
      for(int j=0; j<6; j++)
      {
        digitalWrite(j+2, leds[i][j]);       
      }     
    }   

    delayMicroseconds(12.5);
  }
}
« Last Edit: September 05, 2012, 06:56:46 pm by punker12 » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1 - How much storage do your arrays need?
2 - How much SRAM does an ATtiny44 have?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Using a byte array when all you use is one bit is very wasteful. Try and see if you can just use single bits and save some space.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1 - How much storage do your arrays need?
2 - How much SRAM does an ATtiny44 have?

Not very much 2.5kb, and the attiny44 has 256B of SRAM.

Using a byte array when all you use is one bit is very wasteful. Try and see if you can just use single bits and save some space.

This code was borrowed for testing purposes, I plan to do something else with the chip. If I can get this code working on it then my other project will be a snap. Also space is not an issue.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. It seems as if the pins are different.

Of course the pins are different.  The 'core' you are using will map the Arduino pin names to physical pins.  You'll have to look at the documentation for the core you are using to find out what that mapping is.

The core should also take care of the timing so you shouldn't need to modify delays to get it to work.

Did you "burn a bootloader" to get the fuses set properly?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Not very much 2.5kb, and the attiny44 has 256B of SRAM.

By my reckoning, these arrays require 306 of your 256 bytes of SRAM.
Code:
byte leds[9][6] = {{LOW, HIGH, HIGH, HIGH, LOW, LOW},
                  {LOW, HIGH, HIGH, LOW, HIGH, LOW},
                  {LOW, HIGH, HIGH, LOW, LOW, HIGH},
                  {HIGH, LOW, HIGH, HIGH, LOW, LOW},
                  {HIGH, LOW, HIGH, LOW, HIGH, LOW},
                  {HIGH, LOW, HIGH, LOW, LOW, HIGH},
                  {HIGH, HIGH, LOW, HIGH, LOW, LOW},
                  {HIGH, HIGH, LOW, LOW, HIGH, LOW},
                  {HIGH, HIGH, LOW, LOW, LOW, HIGH}
};
byte n[9][9] = {{0,0,0,0,1,0,0,0,0},  // 1
               {1,0,0,0,0,0,0,0,1},  // 2
               {1,0,0,0,1,0,0,0,1},  // 3
               {1,0,1,0,0,0,1,0,1},  // 4
               {1,0,1,0,1,0,1,0,1},  // 5
               {1,0,1,1,0,1,1,0,1},  // 6
               {1,0,1,1,1,1,1,0,1},  // 7
               {1,1,1,1,0,1,1,1,1},  // 8
               {1,1,1,1,1,1,1,1,1}}; // 9
                                 
byte misc[11][9] = {{0,0,0,1,1,0,1,1,0},
                   {1,1,0,1,1,0,0,0,0},
                   {0,1,1,0,1,1,0,0,0},
                   {0,0,0,0,1,1,0,1,1},
                   {1,0,1,0,1,0,1,0,1},
                   {1,0,0,1,0,0,1,0,0},
                   {0,1,0,0,1,0,0,1,0},
                   {0,0,1,0,0,1,0,0,1},
                   {1,1,1,0,0,0,0,0,0},
                   {0,0,0,1,1,1,0,0,0},
                   {0,0,0,0,0,0,1,1,1}
                 };
                 
byte prop[4][9] = {{0,0,0,1,1,1,0,0,0},
                  {0,0,1,0,1,0,1,0,0},
                  {0,1,0,0,1,0,0,1,0},
                  {1,0,0,0,1,0,0,0,1}
                 };
                 
byte raider[4][9] = {{1,0,0,1,0,0,1,0,0},
                     {0,1,0,0,1,0,0,1,0},
                     {0,0,1,0,0,1,0,0,1},
                     {0,1,0,0,1,0,0,1,0},
                     };
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. It seems as if the pins are different.

Of course the pins are different.  The 'core' you are using will map the Arduino pin names to physical pins.  You'll have to look at the documentation for the core you are using to find out what that mapping is.

The core should also take care of the timing so you shouldn't need to modify delays to get it to work.

Did you "burn a bootloader" to get the fuses set properly?
Yes Im aware of this, I have changed them to match. I know that its not the same as the arduino. Ive looked to the documentation and matched accordingly. One section of the sketch works fine but the rest is all over the place. I haven't "bootloaded" it yet so I should do that and give it a try.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly.

Quote
Also space is not an issue.
It is an issue as dxw00d points out:-

Quote
these arrays require 306 of your 256 bytes of SRAM.

It works on the UNO because it has enough memory, it does not work on the Attiny44 because it does not have enough memory.

Quote
If I can get this code working on it then my other project will be a snap
Yes then you will have succeeded in fitting a quart into a pint pot.
http://en.wiktionary.org/wiki/you_can%27t_get_a_quart_into_a_pint_pot
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For future reference, how do I figure out how much ram is required for the script?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It won't give you the complete picture, but you can start by simply working out how much space all your variables need.

Code:
byte leds[9][6]
byte n[9][9]
byte misc[11][9]                
byte prop[4][9]                
byte raider[4][9]

So here, you have (9x6) + (9x9) + (11x9) + (4x9) + (4x9) = 306 bytes. Your loop variables will also require some storage space, as will any other variables used.
Logged

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey man! Unfortunately the attinies are just sort of "stupid". I've used the attiny84 (the same as yours but with 8KB of flash) in my project and it just seems that when you put allot of functions, loops, if's, for's, outputs and inputs it becomes exusted.

I don't know, thats my opinion on my experience.
Logged

Arduino Uno R3
Mac OSX Lion


Virginia
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know how familiar you are with using macros in C/C++, but they can make the task of storing constant bits in packed bytes a lot easier. Also, if you use the "const" keyword for arrays which should be constant, they should be stored in Flash area, not in SRAM, saving the precious SRAM space. Here is a small example of defining a graphic character using macros. This 8x8 pixel character (including space) uses only 8 bytes of constant Flash memory. Please note that I coded this on-the-fly and have not compiled it, so...

#define ROW(b7,b6,b5,b4,b3,b2,b1,b0) \
  (((b7)<<7)|((b6)<<6)|((b5)<<5)|((b4)<<4)|((b3)<<3)|((b2)<<2)|((b1)<<1)|b0)
static const byte Graphic[] =
{
  ROW(0,0,1,1,1,1,0,0),
  ROW(0,1,0,0,0,0,1,0),
  ROW(0,1,0,0,0,0,1,0),
  ROW(0,1,1,1,1,1,1,0),
  ROW(0,1,0,0,0,0,1,0),
  ROW(0,1,0,0,0,0,1,0),
  ROW(0,1,0,0,0,0,1,0),
  ROW(0,0,0,0,0,0,0,0),
};
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33362
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it just seems that when you put allot of functions, loops, if's, for's, outputs and inputs it becomes exusted.
Well what ever is happening it is not attributed to exhaustion, there is no such thing in electronics.
Logged

Pages: [1]   Go Up
Jump to: