3D array problems

I'm having some problems with a 3D array i've created for my data, the array looks like this, repeated 127 times

byte chars[127][8][7]={
  {
    {
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
    ,{
      0,0,0,0,0,0,0    }
  }
  ,

and I'm trying to use the values but the program just doesn't work when I try. the current program is as below but no data gets printed and no matter what the code is if it involves trying to read or write to the array none of it works.

void setup(){
  Serial.begin(9600);
}
void loop(){
  for(int r=0;r<8; r++){
    for(int character=0;character<127;character++){
      for(int c=0;c<7;c++){
        Serial.print(chars[character][r][c], DEC);
      }
    }
    Serial.println();
  }
}

I have no idea what's wrong any help would be greatly appreciated. :slight_smile:

127 * 8 * 7 = 7112 bytes

Which processor do you have?

Have you thought about using PROGMEM?

Could your innermost elements be a single byte rather than a byte for each value? Are they just 1 bit values (1 or 0) ?

I'm using the 328 which has approx 32000 bytes so the memory shouldnt be a problem. When it is compiled it only uses about 10000 bytes. What is the difference between normal variables and progmem?

I'm using the 328 which has approx 32000 bytes so the memory shouldnt be a problem

Your tables go into RAM memory, unless you tell the compiler otherwise.
Memory is your problem.

The AVR has two separate memory spaces (Harvard architecture) - a ROM (flash) memory for program, and RAM for variables, stack, registers etc.
RAM is a much smaller space.
There is a lot about PROGMEM over at the main site.

32K is the flash memory (PROGMEM) - you only have 2K of RAM.

Unless you specify the array constatnt to live as read only data in PROGMEM it will go in RAM.

You will find lots of threads here on getting your static data into flash rather than RAM by searching for 'Arduino PROGMEM'

snap!

So if I add the progmem command I shouldn't have a problem. Thanks guys I'll try it when I get home :slight_smile:

So if I add the progmem command I shouldn't have a problem

well, it is a little more complicated than that - you also have to explicitly fetch the data using the PROGMEM read methods described with the PROGMEM tutorial.
Did you also read the comment about bit-packing your data to reduce memory requirements?

Thanks i'll look through the tutorial later. I will see how I can rig my hardware so I might be able to bit pack the data to save memory. Thanks for all your help :slight_smile: