[HELP] Arduino MEGA 2560 + SIM900A module ?? Problem ??

Hi everyone!

I'm using sim900a library v305 from gsmlib.org (http://www.gsmlib.org/download.html)

It worked well with arduino UNO. (sms sending and receiving)

But when I use arduino MEGA 2560. I only can send the message from my arduino to my phone, and can't receive message from my phone. (I used pin 18, 19)

This library require arduino v1.0.6 or earlier with arduino MEGA.

This is the instruction when using library:

[1] How to switch between Arduino Mega and Arduino Uno?

Open GSM.h and comment-decomment the appropriate lines like below
e.g. for Arduino Mega
//#define UNO
#define MEGA

If you use Arduino Uno comment the line in HWSerial.h or decomment if
you are using Arduino Mega
e.g. for Arduino Mega
#define MEGA

Save and compile

[2] How to switch between the old shield (that uses 4 and 5 pins for
SoftwareSerial and the new (that used 2 and 3 pins)?

Open GSM.cpp and comment-decomment the appropriate lines like below
e.g. for the new one

//#define GSM_TXPIN 4
//#define GSM_RXPIN 5
#define GSM_TXPIN 2
#define GSM_RXPIN 3

Save and compile

Here is my code:

#include "SIM900.h"

#include <SoftwareSerial.h>

#include "sms.h"

#define but 7

SMSGSM sms;

char number[20];

char message[180];

char pos;

char *p;
byte i;

void setup()

{
pinMode(but,INPUT_PULLUP);

Serial.begin(9600);

if (gsm.begin(9600))

Serial.println("\nstatus=READY");

else Serial.println("\nstatus=IDLE");

};

void loop()

{
if (digitalRead(but) == 0){
Serial.println("pressed");
if (sms.SendSMS("xxxxxxxxxxxxx", "Arduino SMS"))
Serial.println("\nSMS sent OK");
}

pos=sms.IsSMSPresent(SMS_UNREAD);
Serial.println((int)pos);

if((int)pos>0&&(int)pos<=20)
{
Serial.print("NUOVO MESSAGGIO, POS=");
Serial.println((int)pos);
message[0]='\0';
sms.GetSMS((int)pos,number,message,180);
Serial.println(number);
Serial.println(message);

//p=strstr(message,"test");

if((String)message == "test")
{
Serial.println("PSWD IS RIGHT");
}

else
{
Serial.println("PSWD IS WRONG");
}

}

sms.DeleteSMS((int)pos);
delay(2000);

};

Here is debug: (arduino MEGA)

0
ATT: OK
RIC: NO STRING RCVDATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
ATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
ATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
ATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
ATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
+CMGL: 4,"
ATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
+CMGL: 4,"REC UNREAD","+84932311611","CONG DANH","15/05/25,00:01:19+28"

ATT: OK
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
+CMGL: 4,"REC UNREAD","+84932311611","CONG DANH","15/05/25,00:01:19+28"

OK

ATT: +CMGL:
RIC:
+CMT: "+84932311611","CONG DANH","15/05/25,00:01:19+28"
Hell
+CMGL: 4,"REC UNREAD","+84932311611","CONG DANH","15/05/25,00:01:19+28"

As you see: "REC UNREAD" at the bottom line ???? For arduino UNO it is "REC READ"

Like this: (for arduino UNO)

+CMGL: 1,"REC UNREAD","+84932311611","CO
ATT: OK
RIC:
+CMGL: 1,"REC UNREAD","+84932311611","CONG DANH","15/05/24,20:57:35+28"
Okkkkkkk

ATT: OK
RIC:
+CMGL: 1,"REC UNREAD","+84932311611","CONG DANH","15/05/24,20:57:35+28"
Okkkkkkk

OK

ATT: +CMGL:
RIC:
+CMGL: 1,"REC UNREAD","+84932311611","CONG DANH","15/05/24,20:57:35+28"
Okkkkkkk

OK

1
NUOVO MESSAGGIO, POS=1
ATT: +CMGR
RIC:
+CMGR: "REC READ","+84932311611","CONG DANH","15/05/24,20:57:35+28"
Okkkkkkk

OK

ATT: "REC UNREAD"
RIC:
+CMGR: "REC READ","+84932311611","CONG DANH","15/05/24,20:57:35+28"
Okkkkkkk

OK

ATT: "REC READ"
RIC:
+CMGR: "REC READ","+84932311611","CONG DANH","15/05/24,20:57:35+28"
Okkkkkkk

OK

+84932311611
Okkkkkkk
PSWD IS WRONG
ATT: OK
RIC:
OK

Hoping your advises :slight_smile: Thanks all !!