Hi everyone,
I’m working on a project with a GSM shield and it seems that Arduino is running out of memory when I want to open a message on the shield (AT+CMGR command)
I explain:
I send a message to the shield, the arduino checks every 10s if a message has been received and if yes, open it. Another function (see below, thats GetMsg() function) gets the message. Because my circuit is already done, I can’t send information on serial, so I send back what GetMsg() to my phone. I always received the same message (only the date change):
AT+CMGR=1
+CMGR: “REC UNREAD”, “phone_number”, “” ", 18/09/23,1
So, as you can see, the message is cut, and I can’t see the content of the message.
I already have this problem before and solved it by deleting some strings in the program, but now, its doesn’t work anymore. When I compile, it tells that I used 52% for global variable, so about 1000 bytes is available for local variable. I used lots of strings and functions that return strings in my program; maybe that the problem, but I need them.
I tried to see the free memory during execution and it’s about 600 bytes.
I think it should be a memory issue but don’t understand where the problem is. Someone has any idea ?
Function to get message frome the gsm shield (found on Internet)
String GetMsg()
{
String inTxt = "";
char Car;
while (mySerial.available())
{
Car = mySerial.read();
inTxt = inTxt+Car;
}
return inTxt;
}
Function to check if a message has been received
void check_SMS(){
msg = "";
msg = GetMsg();
delay(500);
if (msg.indexOf("+CMTI:")>-1)
{
char numSMS = msg.substring(msg.indexOf(",")+1).toInt();
mySerial.print("AT+CMGR=");
mySerial.println(numSMS, DEC);
delay(1000);
msg = GetMsg();
delay(500);
if (numSMS >= 25)
{
mySerial.print("AT+CMGD=");
mySerial.println("1,4");
delay(2000);
}
String send_num = msg.substring(msg.indexOf(",")+1, msg.indexOf(",")+15);
//Serial.println(send_num);
if (send_num.equals(strcpy_P(buffer, (char*)pgm_read_word(&(num_table[0])))) || send_num.equals(strcpy_P(buffer, (char*)pgm_read_word(&(num_table[1])))))
{
state_msg(msg, send_num);
}
Function that do something based on the content of the message
void state_msg(String msg_received, String send_num)
{
//Clear only line 1
lcdClearLine(1);
lcd.print("Mem Et:");
lcd.setCursor(8, 1);
lcd.print(freeMemory());
delay(2000);
if (msg_received.indexOf("rst")>-1) resetFunc();
else
{
//Send back received message
send_SMS(msg_received, strcpy_P(buffer, (char*)pgm_read_word(&(num_table[0]))));
delay(4000);
}
}
Thanks