Dear community members,
I am working on a project that uses an Arduino Ethernet R3 combined with a Telefonica GPS/GPRS shield. The board is connected to a Linux laptop using a PL2303 based board (serial to USB). The arduino is powered with an external adapter delivering 7.5V at 1A.
I am struggling to get the SendSMS example working. I filled in the PIN and activated debugging of the GSM class. This gives me the following output:
SMS Messages Sender
AT%13%
0 9>AT%13%%13%%10%OK%13%%10%
AT+CPIN=3511%13%
9 44>AT+CPIN=3511%13%%13%%10%+CPIN: READY%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
44 75>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%SMS Messages Sender
SMS Messages Sender
SMS Messages Sender
AT%13%
0 9>AT%13%%13%%10%OK%13%%10%
AT+CPIN=3511%13%
9 44>AT+CPIN=3511%13%%13%%10%+CPIN: READY%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
44 75>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
SMS Messages Sender
SMS Messages Sender
The script appears to crash on the GSM.begin() function, while connecting to the network. It then resets and tries again.
I also tested the Telefonica shield on an Arduino UNO R2 and used the exact same code as with the Ethernet. This works perfectly and gives the following output:
SMS Messages Sender
AT%13%
0 9>AT%13%%13%%10%OK%13%%10%
AT+CPIN=3511%13%
9 44>AT+CPIN=3511%13%%13%%10%+CPIN: READY%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
44 75>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
75 106>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
106 9>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
9 40>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
40 71>AT+CGREG?%13%%13%%10%+CGREG: 0,2%13%%10%%13%%10%OK%13%%10%
AT+CGREG?%13%
71 102>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
AT+IFC=1,1%13%
102 5>AT+IFC=1,1%13%%13%%10%OK%13%%10%%13%%10%Call Ready%13%%10%
AT+CMGF=1%13%
5 21>AT+CMGF=1%13%%13%%10%OK%13%%10%
AT+CLIP=1%13%
21 37>AT+CLIP=1%13%%13%%10%OK%13%%10%
ATE0%13%
37 48>ATE0%13%%13%%10%OK%13%%10%
AT+COLP=1%13%
48 54>%13%%10%OK%13%%10%
GSM initialized
Enter a mobile number: 0464000000
Now, enter SMS content: SENDING
Message:
Hello word!
AT+CMGS="0464000000"%13%
54 58>%13%%10%>
Hello word!%26%%13%
54 76>%13%%10%> %13%%10%+CMGS: 5%13%%10%%13%%10%OK%13%%10%
COMPLETE!
Enter a mobile number:
And this is the code used on both boards:
#include <GSM.h>
#define PINNUMBER "3511"
// initialize the library instance
GSM gsmAccess(true); // include a 'true' parameter for debug enabled
GSM_SMS sms;
void setup()
{
// initialize serial communications
Serial.begin(9600);
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while(notConnected)
{
delay(1000);
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop()
{
Serial.print("Enter a mobile number: ");
char remoteNumber[20]; // telephone number to send sms
readSerial(remoteNumber);
Serial.println(remoteNumber);
// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNumber);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}
int readSerial(char result[])
{
int i = 0;
while(1)
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar == '\n')
{
result[i] = '\0';
Serial.flush();
return 0;
}
if(inChar!='\r')
{
result[i] = inChar;
i++;
}
}
}
}
Can anyone explain this behavior? Why does is work on the regular Arduino UNO, but not on the Ethernet?