Data size Notes

Hey all. This was originally going to be a possible bug report, but I just figured out the issue, and thought I'd share it.

I have this program with a lot of data, and i at first was initializing it as in the following program:

void setup() {
  for( int i=2 ; i<13 ; i++ )
  {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  delay( 100 );
  digitalWrite( 3, HIGH );
  delay( 100 );
  digitalWrite( 3, LOW );
}

int myData[349]= {
  /* 348 - LED blinks */
  /* 349 - LED doing strange things */
  /* 350 - LED is solid */
  /* 400 - LED doesn't blink */
  /* change that to [20][20] to make the Arduino NG not work */
  /* change that to static int pattern[ whatever]; and it works fine */
};

I found that the data at around the above sizes causes the above issues.

However, If i define the data as "static", it works great!

  static int myData[4096] = {
   /* data list */
  }

It works just fine.

I'm assuming that this will store the data in ROM space rather than limited RAM space.

Just a heads up for any of you who might be seeing issues with large data sizes.

:smiley:

I'm assuming that this will store the data in ROM space rather than limited RAM space.

I doubt it, since this would mean you can't modify the values, which means they'd be constant.

A static variable is one whose memory is allocated once per program execution. An automatica variable (which is the default and opposite of static) gets its memory allocated each time the function in which it is declared is called.

In practice on most systems static variables are allocated on the heap, while automatic variables are on the stack. I have no idea how gcc allocates memory on the Atmel, but you may be seeing something caused by the automatic (i.e., non-static) variable overflowing the stack.

-j

Arrgggghhhh! can't type!

An automatica variable

That should read: An automatic variable

-j

You should be able to do something like this:

const char foo[] PROGMEM = "Foo";

to store an array only in program memory (flash) and not in RAM. See: avr-libc: <avr/pgmspace.h>: Program Space Utilities for more details.

Aaah!

perfect!

well, it does'nt make sens to me.

if i read the document in the link, I am unable to find the code example.

const char foo[] PROGMEM = "Foo";

Should i just use that line and replace foo with my own variName?

Pretty much. You might also want to change the type, if, for example, you're storing ints instead of chars, which would mean you need to initialize the array with something like: { 10, 20, 30, 40 } instead of "Foo".

I think I may have the same problem ... can anyone explain why this code does not work but if I remove one line from the array it works just fine.

char gen_shps[][72] = {
  "oooggooo ooggggoo oggggggo ooggggoo oggggggo gggggggg oooyyooo oooyyooo", //x-mas tree
  "oooggooo ooggggoo oggggggo ooggggoo oyooooyo oyooooyo oyyyyyyo yoorrooy", //x-mas bell
  "oorrrroo orrrrrro oorrrroo ooorrooo oooggogo ogogggoo oogggooo oooggooo", //flower #1
  "oorrrroo orooooro rogoogor roooooor rgoooogr rogoogor oroggoro oorrrroo", //smiley face
  "oooooooo orroorro roorroor roorroor roooooor orooooro oorooroo ooorrooo", //heart 
  "ooogoooo ooogyooo ooogyyoo ooogyyyo ooogoooo gggggggg oggggggo ooggggoo", //boat
  "ooorrooo oorooroo oorooroo ooorrooo oorooroo orooooro orrrrrro oorooroo", //girl
  "oooooooo googggoo gogooogo ggoooyog ggooooog gogooogo googggoo oooooooo", //fish
  "oooyyooo ooyooyoo oyyooyyo yooggooy yooggooy oyyooyyo ooyooyoo oooyyooo", //flower #2
  "oorrrroo orrrrrro oorrrroo ooyrryoo oyooooyo oyooooyo ooyooyoo oooyyooo" //ring
  };
  
void loop() {
  for (int i=0;i<10;i++) {
    show(gen_shps[i], shp_speed);
  }
}

I have also tried this ... but it reacts the same way....

char *gen_shps[] = {
  "oooggooo ooggggoo oggggggo ooggggoo oggggggo gggggggg oooyyooo oooyyooo", //x-mas tree
  "oooggooo ooggggoo oggggggo ooggggoo oyooooyo oyooooyo oyyyyyyo yoorrooy", //x-mas bell
  "oorrrroo orrrrrro oorrrroo ooorrooo oooggogo ogogggoo oogggooo oooggooo", //flower #1
  "oorrrroo orooooro rogoogor roooooor rgoooogr rogoogor oroggoro oorrrroo", //smiley face
  "oooooooo orroorro roorroor roorroor roooooor orooooro oorooroo ooorrooo", //heart 
  "ooogoooo ooogyooo ooogyyoo ooogyyyo ooogoooo gggggggg oggggggo ooggggoo", //boat
  "ooorrooo oorooroo oorooroo ooorrooo oorooroo orooooro orrrrrro oorooroo", //girl
  "oooooooo googggoo gogooogo ggoooyog ggooooog gogooogo googggoo oooooooo", //fish
  "oooyyooo ooyooyoo oyyooyyo yooggooy yooggooy oyyooyyo ooyooyoo oooyyooo", //flower #2
  "oorrrroo orrrrrro oorrrroo ooyrryoo oyooooyo oyooooyo ooyooyoo oooyyooo" //ring
  };