Maximum Array Size?

Hey there, been trying to debug a program of mine for the longest time, and seem to have found what I think is the problem, but cant find any literature on the subject. With the arduino, is there some sort of maximum array size? Or am I just not using the pointers right?

Im working on a program for the infamous Nokia LCD screen, more specifically the text write functions on it.
The function itself appears to work fine, as long as the array size isn't too large. It will work perfectly for my small font array, and my medium font array, but not the whole large font array or the combined arrays. (the idea was to have all 3 fonts in one array then just access the needed bytes with pointers. )

The max appears to be about 880 elements in the array

When i run it with what appears to be too many values in the array, it loops through the void setup part of the code, and never makes it to the void loop. (was able to tell with the serial print commands)

Here is the code with just part of the large font in there (this is the maximum number of elements before it does the little loop thing)

void typeSingle(char charVal, int x, int y, int size, int tColor, int bColor)
{

  //Font tables 
  byte font[] = {
    0x08, 0x0B, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // columns rows bytes
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    // space
    0x00, 0x00, 0x00, 0xE0, 0xEC, 0x6F, 0x7F, 0xC0, 0x01, 0x00, 0x00,    // !
    0x00, 0x00, 0x38, 0xE0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1E, 0xE0,    // "
    0x00, 0x40, 0x84, 0xFF, 0xFC, 0x87, 0x08, 0xFF, 0xF9, 0x0F, 0x11,    // #
    0x00, 0x80, 0x0D, 0xF6, 0x90, 0xC4, 0x64, 0x26, 0xE3, 0x0D, 0x36,    // $
    0x00, 0x20, 0x0C, 0x63, 0x30, 0x00, 0x03, 0x30, 0x30, 0x83, 0x31,    // %
    0x00, 0xE0, 0x80, 0x6F, 0xC4, 0x27, 0x27, 0xEE, 0xF9, 0x46, 0x04,    // &
    0x00, 0x00, 0x04, 0xE0, 0x01, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00,    // '
    0x00, 0x00, 0x00, 0x3C, 0xF8, 0xE7, 0x70, 0x01, 0x02, 0x00, 0x00,    // (
    0x00, 0x00, 0x00, 0x00, 0x04, 0xE8, 0x70, 0xFE, 0xC1, 0x03, 0x00,    // )
    0x00, 0x00, 0x01, 0x6B, 0xF0, 0x01, 0x07, 0x7C, 0xB0, 0x06, 0x04,    // *
    0x00, 0x80, 0x01, 0x0C, 0xF8, 0xC1, 0x0F, 0x18, 0xC0, 0x00, 0x00,    // +
    0x00, 0x00, 0x40, 0x00, 0x1E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,    // 
    0x00, 0x00, 0x01, 0x08, 0x40, 0x00, 0x02, 0x10, 0x80, 0x00, 0x04,    // -
    0x00, 0x00, 0x00, 0x00, 0x0C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00,    // .
    0x00, 0x70, 0x00, 0x07, 0x70, 0x00, 0x07, 0x70, 0x00, 0x07, 0x70,    // / 
    0x00, 0xE0, 0x9F, 0xFF, 0x05, 0x28, 0x46, 0x01, 0xFA, 0x9F, 0x7F,    // 0 
    0x00, 0x00, 0x80, 0x40, 0x04, 0xE6, 0x7F, 0xFF, 0x0B, 0x40, 0x00,    // 1
    0x00, 0x70, 0x90, 0x87, 0x65, 0x28, 0x46, 0x61, 0x1A, 0xDE, 0x61,    // 2  20
    0x00, 0x20, 0x90, 0x81, 0x85, 0x28, 0x44, 0x21, 0xFA, 0x9F, 0x77,    // 3
    0x00, 0x80, 0x03, 0x3C, 0x20, 0x23, 0x31, 0xFF, 0xFB, 0x5F, 0x02,    // 4
    0x00, 0x60, 0xBE, 0xF3, 0x8D, 0x28, 0x44, 0x21, 0xFA, 0x91, 0x87,    // 5
    0x00, 0xE0, 0x8F, 0xFF, 0x84, 0x2C, 0x44, 0x21, 0xFA, 0x81, 0x07,    // 6
    0x00, 0x00, 0x30, 0x80, 0x1D, 0xE8, 0x43, 0x78, 0x02, 0x1F, 0xE0,    // 7
    0x00, 0xE0, 0x9D, 0xFF, 0x85, 0x28, 0x44, 0x21, 0xFA, 0x9F, 0x77,    // 8
    0x00, 0x00, 0x9E, 0xF8, 0x45, 0x28, 0x42, 0x13, 0xF2, 0x1F, 0x7F,    // 9
    0x00, 0x00, 0x00, 0x00, 0x8C, 0x61, 0x0C, 0x00, 0x00, 0x00, 0x00,    // :
    0x00, 0x00, 0x40, 0x00, 0x1E, 0xE3, 0x18, 0x00, 0x00, 0x00, 0x00,    // ;
    0x00, 0x00, 0x01, 0x1C, 0xB0, 0xC1, 0x18, 0x83, 0x09, 0x08, 0x00,    // <
    0x00, 0x40, 0x02, 0x12, 0x90, 0x80, 0x04, 0x24, 0x20, 0x01, 0x00,    // =
    0x00, 0x10, 0x90, 0xC1, 0x18, 0x83, 0x0D, 0x38, 0x80, 0x00, 0x00,    // >
    0x00, 0x00, 0x18, 0xC0, 0x01, 0x68, 0x47, 0x7B, 0x02, 0x1E, 0x60,    // ?
    0x00, 0xE0, 0x9F, 0xFF, 0x05, 0x28, 0x4F, 0x49, 0xCA, 0x1F, 0x7C,    // @ 
    0x00, 0xF0, 0x87, 0x7F, 0x20, 0x06, 0x61, 0x88, 0xF9, 0xC7, 0x1F,    // A
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x2F, 0x44, 0x21, 0xFA, 0x9F, 0x77,    // B
    0x00, 0xC0, 0x0F, 0xFF, 0x0C, 0x2C, 0x40, 0x01, 0x1A, 0x98, 0x61,    // C
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x2F, 0x40, 0x03, 0xF3, 0x0F, 0x3F,    // D
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x2F, 0x44, 0x71, 0x1A, 0xD8, 0xE1,    // E
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x2F, 0x44, 0x70, 0x02, 0x18, 0xE0,    // F   40
    0x00, 0xC0, 0x0F, 0xFF, 0x0C, 0x2C, 0x42, 0x13, 0xF2, 0xD8, 0x67,    // G
    0x00, 0xF0, 0xBF, 0xFF, 0x81, 0x00, 0x04, 0x20, 0xF8, 0xDF, 0xFF,    // H
    0x00, 0x00, 0x80, 0x00, 0xFD, 0xEF, 0x7F, 0x01, 0x02, 0x00, 0x00,    // I
    0x00, 0x60, 0x80, 0x03, 0x04, 0x20, 0x40, 0xFF, 0xF3, 0x1F, 0x80,    // J
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x0F, 0x04, 0xF8, 0xF8, 0xDE, 0xC1,    // K
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x2F, 0x40, 0x01, 0x18, 0xC0, 0x01,    // L
    0x00, 0xF0, 0xBF, 0xFF, 0x01, 0x06, 0x18, 0x80, 0xF9, 0xDF, 0xFF,    // M
    0x00, 0xF0, 0xBF, 0xFF, 0x81, 0x03, 0x0E, 0x38, 0xF8, 0xDF, 0xFF,    // N
    0x00, 0xC0, 0x0F, 0xFF, 0x0C, 0x2C, 0x40, 0x03, 0xF3, 0x0F, 0x3F,    // O
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x2F, 0x44, 0x20, 0x02, 0x1F, 0x70,    // P 
    0x00, 0xE0, 0x9F, 0xFF, 0x05, 0xE8, 0x40, 0x03, 0xFA, 0x9F, 0x7F,    // Q
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x0F, 0x44, 0x38, 0xFA, 0xDF, 0x71,    // R
    0x00, 0x60, 0x98, 0xE3, 0x85, 0x29, 0x44, 0x31, 0xFA, 0x9C, 0x63,    // S
    0x00, 0x00, 0x38, 0x80, 0x05, 0xE8, 0x7F, 0x01, 0x02, 0x18, 0xE0,    // T
    0x00, 0xE0, 0xBF, 0xFF, 0x05, 0x20, 0x00, 0x01, 0xF8, 0x9F, 0xFF,    // U
    0x00, 0x80, 0x3F, 0xFE, 0x19, 0x60, 0x00, 0x06, 0xE0, 0x1F, 0xFE,    // V
    0x00, 0xC0, 0xBF, 0xFF, 0x1D, 0x80, 0x03, 0x07, 0xF8, 0x1F, 0xFF,    // W
    0x00, 0x30, 0xB0, 0xC3, 0x31, 0x03, 0x0F, 0xCC, 0x38, 0xDC, 0xC0,    // X
    0x00, 0x00, 0x38, 0xE0, 0x85, 0xE1, 0x07, 0x61, 0x00, 0x1E, 0xE0,    // Y
    0x00, 0x70, 0xB8, 0x87, 0x65, 0x28, 0x46, 0x61, 0x1A, 0xDE, 0xE1,    // Z 60
    0x00, 0x00, 0x80, 0xFF, 0xFD, 0x2F, 0x40, 0x01, 0x02, 0x00, 0x00,    // [
    0x00, 0x00, 0x1C, 0x70, 0xC0, 0x01, 0x07, 0x1C, 0x70, 0xC0, 0x01,    // \ 
    0x00, 0x00, 0x80, 0x00, 0x05, 0xE8, 0x7F, 0xFF, 0x03, 0x00, 0x00,    // ]
    0x00, 0x00, 0x04, 0x60, 0x00, 0x06, 0x60, 0x80, 0x01, 0x06, 0x10,    // ^
    0x00, 0x10, 0x80, 0x00, 0x04, 0x20, 0x00, 0x01, 0x08, 0x40, 0x00,    // _
    0x00, 0x00, 0x00, 0x40, 0x00, 0x0E, 0x60, 0x00, 0x00, 0x00, 0x00,    // ` 
    0x00, 0x60, 0x82, 0x27, 0x24, 0x21, 0x09, 0x7E, 0xF8, 0x41, 0x00,    // a
    0x00, 0x10, 0xA0, 0xFF, 0xF9, 0x2F, 0x08, 0x61, 0xF8, 0x81, 0x07,    // b
    0x00, 0xE0, 0x83, 0x3F, 0x04, 0x21, 0x08, 0x41, 0x18, 0x83, 0x08,    // c
    0x00, 0xE0, 0x81, 0x1F, 0x84, 0x21, 0x48, 0xFE, 0xFB, 0x5F, 0x00,    // d
    0x00, 0xE0, 0x83, 0x3F, 0x24, 0x21, 0x09, 0x49, 0xD8, 0x83, 0x0C,    // e
    0x00, 0x10, 0x82, 0xFF, 0xFC, 0x2F, 0x44, 0x20, 0x03, 0x0C, 0x00,    // f
    0x00, 0x90, 0xC7, 0x7E, 0x12, 0x92, 0x90, 0x7F, 0xF8, 0x07, 0x20,    // g
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x0F, 0x04, 0x40, 0xF8, 0xC3, 0x0F,    // h
    0x00, 0x00, 0x00, 0x00, 0x04, 0xE1, 0x6F, 0x7F, 0x0B, 0x00, 0x00,    // i
    0x00, 0x30, 0xC0, 0x01, 0x02, 0x10, 0x88, 0x7F, 0xFB, 0x1B, 0x00,    // j
    0x00, 0x10, 0xA0, 0xFF, 0xFD, 0x0F, 0x01, 0x1C, 0xB8, 0xC3, 0x18,    // k
    0x00, 0x00, 0x00, 0x00, 0x04, 0xE8, 0x7F, 0xFF, 0x0B, 0x00, 0x00,    // l
    0x00, 0xF0, 0x87, 0x3F, 0x80, 0xE0, 0x0F, 0x60, 0xF8, 0xC3, 0x0F,    // m
    0x00, 0x00, 0x84, 0x3F, 0xFC, 0x00, 0x08, 0x40, 0xF8, 0xC3, 0x0F,    // n 80

  };
  
  int i,j,color1,color2,charCode;
  byte mask,rowHold;
  byte *ptr;
  ptr = &font[0];

  switch (size) {
  case 1:
    break;
  case 2:
    *ptr=*ptr+582;
    break;
  case 3:
    *ptr=*ptr+1358;
    break;
  }

  unsigned int nCols = *ptr++; //pulls the number of columns out for the specified font size
  unsigned int nRows = *ptr++;
  unsigned int nBytes = *ptr++;
  Serial.println("rowHold");
  charCode=charVal-32;
  ptr=ptr+(charCode+1)*nBytes-3; //points to the appropriate character

  cmdOut(0x2A);  // sets the LCD to write to the correct size box
  dataOut(y);
  dataOut(y+nRows-1);
  cmdOut(0x2B);
  dataOut(x);
  dataOut(x+nCols-1);
  cmdOut(0x2C);
  for(i=0; i< nBytes; i++) {
    rowHold=*ptr++; //pulls out the byte of data to write
    Serial.println(rowHold,HEX);
    mask=B00000001;
    for (j=0; j<4;j++) {
      if ((rowHold & mask) == 0) // writes either foreground or background 2 pixels at a time
      {
        color1=bColor;
      }
      else
      {
        color1=tColor;
      }
      mask=mask<<1;
      if ((rowHold & mask) == 0)
      {
        color2=bColor;
      }
      else
      {
        color2=tColor;
      }
      mask=mask<<1;
      dataOut((color1>>4 & 0xFF));
      dataOut(((color1&0x0F)<<4) | ((color2 >> 8) & 0x0F));
      dataOut(color2 & 0xFF);
    }
  }
  cmdOut(0x25);
}

I don't know if its needed for me to post the whole code or not, let me know if you want it all.

The total amount of RAM is 2K, if you reach this limit you can try to move the big arrays to PROGMEM. Google Arduino PROGMEM to get the details .

Ah, that would make sense. Figured it was something simple like this.

That was what i was initially trying to do, but seemed to get a lot of errors referring to the pointers being variables and pointing to a constant. Is there a simple workaround for this?

might try this lib - http://arduiniana.org/libraries/flash/-

Thanks! ill give that a quick read.

Appreciate the help!

With the arduino, is there some sort of maximum array size?

Certainly there is alimit. First you have to be aware of what memory area is used for all your variables, arrays, stack space for function call. Its the SRAM memory space. How big is it? one a 328p based board like a Uno there is 2k bytes total, mega based boards have 8k avalible. There is a way to have the compiler save constant string data into FLASH memory and that can free up programs that are using too much SRAM space.

So it's kind of up to you to be aware of the limit. I don't think the compiler gives any kind of error or warning when you try and use too much SRAM, but there is a way with some command line tools to see how much space the variables and arrays take up, but not what your stack space may end up needing at run time.

Welcome to the world of micro-controllers. They are kind of like real computers, just resource limited. :wink:

Haha, far too accustomed to programming with 8 GB of flash and a 1 TB HDD, just didnt seem to matter :slight_smile:

didnt realize it allocated things to SRAM rather than flash, just saw the 6k bytes of 32kb used and thought I was okay.

Another option is to use external memory like EEPROM which can be accessed almost as if it is an array.

e.g. - Arduino Playground - I2CEEPROM -

didnt realize it allocated things to SRAM rather than flash, just saw the 6k bytes of 32kb used and thought I was okay.

Problem is FLASH is slow to write fast to read, fine for uploading the program as you only need to do that once per program load. SRAM is fast read/write, so where you need your variables and arrays placed. Again constant strings in your program can be stored in flash and read back as the program requires.

Don't be bummed, the restrictions will make you a 'better' programmer as you will care about efficient use of the resources avalible. :wink:

Haha, far too accustomed to programming with 8 GB of flash and a 1 TB HDD, just didnt seem to matter

You mean that you are far too accustomed to letting the operating system manage you being a resource hog.

Not that there's anything wrong with that. In my day job, I am, too. 8)