Not enough memory for local variables

Hi buddies,

I am using Arduino Nano Mega 328 to send picture via Multi Media Message with a GPRS module and a SIM card. Usually the picture is large, and if I define a char array, Arudino will tell me not enough memory.

The char array to store picture is 4051 bytes. I am trying to do it this way. First, define a const char array[4051] to use program memory to store the picture, then I define a char shortArray[1000]. Copy array[0~999] to short array, and send it to GPRS model, then repeat the action to copy array[1000~1999] to short array and send. so I can send the picture in four times with the array of 1000 bytes lenght.

But arduino still tell me not enough memory, who can help me? Thank you very much. I found if I remove the line “Serial.print(temp[j]);”,there will be no error.

const char hua[4051] = {   ...               };

int flag = 1;
//String smsContent;

void setup()
{
Serial.begin(9600);
Serial.flush();
}

void loop()
{
// put your main code here, to run repeatedly:
delay(1000);


if (flag == 1)
{
  //sendSMS(smsContent);
  //sendMMS(hua);
  Serial.println("AT+CMMSINIT");
  delay(1000);
  Serial.println("at+cmmscurl=\"mmsc.monternet.com\"");
  delay(1000);
  Serial.println("AT+CMMSCID=1");
  delay(1000);
  Serial.println("AT+CMMSPROTO=\"10.0.0.172\",80");
  delay(1000);
  Serial.println("AT+CMMSSENDCFG=6,3,0,0,2,4");
  delay(1000);
  Serial.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");
  delay(1000);
  Serial.println("AT+SAPBR=3,1,\"APN\",\"CMWAP\"");
  delay(1000);
  Serial.println("AT+SAPBR=1,1");
  delay(1000);
  Serial.println("AT+SAPBR=2,1");
  delay(1000);
  Serial.println("AT+CMMSEDIT=1");
  delay(1000);
  //Serial.println("AT+CMMSDOWN=\"PIC\",7955,40000");
  Serial.println("AT+CMMSDOWN=\"PIC\",1430,40000");
  delay(1000);

  int i = 0;
  int j=0;
  char temp[1000];
[color=red]  for (i=0;i<4;i++)
      for (j=0;j<1000;j++)
      {
        temp[j]=hua[i*1000+j];
        Serial.print(temp[j]);
      }
[/color]
  delay(1000);
  Serial.println("AT+CMMSRECP=\"15214535541\"");
  delay(1000);
  Serial.println("AT+CMMSSEND");
  delay(1000);


  flag = 0;
}


}
[\code]

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the "Code" icon above the posting area. It is the first icon, with the symbol: </>

You need to give your array the PROGMEM attribute to have it stored in program memory and not copied to RAM:

const char hua[4051] PROGMEM = {   0,  0, 0            };

See: Putting constant data into program memory (PROGMEM)

Be aware that using PROGMEM the picture will be stored at compile time, you won't be able to change it at runtime!

SukkoPera:
Be aware that using PROGMEM the picture will be stored at compile time, you won't be able to change it at runtime!

True,
however you can fetch a few pixels, do some transform in RAM and then display.
e.g. you can rotate colours between the PROGMEM and the display.

I'm kind-of hoping he isn't planning to store 4051 bytes in the RAM of an Atmega328.

Thanks for your replies. Now the code works. I am going to connect a commera to Arduino, read picture by serial port from it, and then send the picture by MMS. Now I am testing the second part of sending MMS. Usually the picture is large, so I will read the picture part by part from camera.