Pages: [1]   Go Down
Author Topic: Displaying custom graphics on Adafruit 32x32 LED Matrix  (Read 1133 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using an Arduino Uno with this amazing 32x32 LED Matrix board & driver from Adafruit (product #607):
http://www.adafruit.com/products/607

I need to show a fast animation with icons that fill the screen and are displayed in a random order, but the method I'm using isn't working.

I was planing to use the matrix.drawPixel method that's part of the Adafruit library and create a series of arrays that represent the pixels for each icon. In other words, for 10 icons, I would have 10 arrays with 1024 elements each. I would then parse the array into 32 rows and columns.

Here's what an example array would look like:
const int icon1[]={
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,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1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,
  0,0,1,0,1,1,0,0,1,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,1,0,0,0,0,0,0,
  0,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0
};


And here's how I am parsing and displaying it:
void loop() {
 
   for(int i=0;i<1024;i++){
      int horiz = i%32;//find the H position
      int vert = round(i/32);//find the V position
       if(icon1 == 1) {
         matrix.drawPixel(horiz, vert, matrix.Color333(7, 0, 0));//if this is a "1" light up a pixel, otherwise do nothing
       }   
    }
 
  delay(500);
   matrix.fillScreen(matrix.Color333(0, 0, 0));//clear the screen
  delay(500);
}


What's happening is that this code is working for up to 64 elements in one array, and if I try to read any more than that the program doesn't load at all and I get a blank screen.

Any thoughts on what might be going on? (I'm thinking perhaps it's a memory issue?)
Any suggestions for a different way to do this?

Thanks in advance!
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, the code is

if(icon1==1)

I don't know how I managed to copy it differently.
Logged

Norfolk UK
Offline Offline
Edison Member
*
Karma: 66
Posts: 2479
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi carladiana,

Your probably running out of RAM as your arrays are quite big. There are several options you can use to reduce RAM/memory use.
Have a look at storing the array data in program memory (Flash) instead of RAM here. Also changing the data type used from 'const int icon1[]={' to 'const byte icon1[]={' will halve the memory usage. Another option is to pack the data more tightly, as your only storing binary 0/1 bits you can reduce 8 bytes down to just one byte.
Your currently using 2048 bytes to store 1024 elements, changing data type from int to byte will reduce this to 1024 bytes and bit packing will reduce this to just 128 bytes.
Logged

There is no such thing as a stupid question but there are a lot of inquisitive idiots.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm told by Adafruit that the libraries take up almost all the RAM, so this is likely the issue. I knew there was a way to compact the data, but wasn't sure what to search, so thank you for putting it so succinctly! I'll give all this a try and report back.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SO helpful!
Converted to bytes, and doubled the capacity as you had described, but that didn't get me far.

Went into PROGMEM and that opened a whole new world: http://www.arduino.cc/en/Reference/PROGMEM

Also have been getting up to speed on bit packing:
http://playground.arduino.cc/Code/BitMath#bit_pack

And I also found this great blog post, which describes all three approaches, so I'm trying a modification of this code, which seems to be working:
http://timewitharduino.blogspot.com/2011/06/how-to-define-fonts-and-bitmaps.html

Thank you, Riva!
Logged

Pages: [1]   Go Up
Jump to: