Problem including a table

Hey guys,

I have little problem with the code I included at the bottom of the post. The file I include is a .CSV file which contains some integers.
The code works as long as the file doesn't contain too many values. However once the file gets bigger it just stops working.
Basically I would like to include a table with 4000 integers into some project, but I can't get that to work. Even in some really code like the one I included.
Am I overlooking something?

Kind regards;
Budhalol

int myTable [] = {
#include "ward.h"
};  
int i=0;
void setup(){
Serial.begin(9600);
}
void loop(){
  for (i=0;i<=10;i++){
  Serial.println(myTable[i]);
  }
}

Put the table in PROGMEM

Am I overlooking something?

The limited RAM available

As your program executes, the amount of SRAM available ebbs and flows. As your definition of the array size increases, available SRAM shrinks to the point where the program can crash. You can get an approximation of the free memory using:

int freeMemory() {
  int free_memory;

  if ((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__heap_start);
  } else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
    free_memory += freeListSize();
  }
  return free_memory;
}

and call freeMemory() from within loop().

and call freeMemory() from within loop().

Always assuming there's enough RAM left over from your huge array...

Ok, thanks guys.

I put the table into the progmem and it works now. However I ran into another problem.

int myTable [] PROGMEM = {
#include "table.h"
};  
int i=0;

void setup(){
Serial.begin(9600);
i=0;
}

void loop(){
  i=999;
  Serial.println(myTable[i]);
  delay(200);}

This code works fine, it just prints the thousandth value over and over again.

This however

int myTable [] PROGMEM = {
#include "table.h"
};  
int i=0;

void setup(){
Serial.begin(9600);
i=0;}

void loop(){
  i=0;
  while(i<4000)
  {Serial.println(myTable[i]);
  delay(200);
  i++;}
}

This should print all the values one by one, but it doesn't. It just prints 'random' numbers.

When you move data from SRAM to PROGMEM, you need to use the pgm_read_XXX functions to read the data from where you moved it to!

Allright thanks PaulS, I've got it working now

value = pgm_read_word_near(myTable+i);  
  Serial.println(value);

much appreciated