I've been trying to control a relay with a GSM shield for an Arduino project. I haven't had any success with either the Software Serial or the GSM library. I've declared the GSM variable in debug mode and it gives me the error AT%13%. Using Software Serial, it hangs at SIM900.read(). The SIM card connects to the network, I can see that on the board - the LED flashes every 3 seconds and gives me signals for incoming calls and SMSs.
I can't tell if the error is with the SIM card, the connections to the Arduino board, the power supply (12V) or something completely different. Here are the two code examples I'm using with the different libraries.
Anyone else getting this error? What is the best way to make it go away?
Thanks in advance for any help!
SoftwareSerial.h
#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7, 8);
int Relay1 = A2;
int Relay2 = A3;
void setup()
{
Serial.begin(19200);
//Set up relay control pins
pinMode(Relay1, OUTPUT);
digitalWrite(Relay1, HIGH);
// wake up the GSM shield
SIM900.begin(19200);
delay(10000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// output contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
Serial.println("Ready...");
}
void loop()
{
//If a character comes in from the cellular module...
if(SIM900.available() >0)
{
inchar=SIM900.read();
Serial.println(inchar);
if (inchar=='#')
{...}
SIM900.println("AT+CMGD=1,20"); // delete all SMS
}
}
GSM.h - in this case I haven't even gotten past the .begin() command. This code is from the example at http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// initialize the library instances
GSM gsmAccess(true);
GSM_SMS sms;
GSM3_NetworkStatus_t gsmStatus;
// Array to hold the number a SMS is retreived from
char senderNumber[20];
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("SMS Messages Receiver");
char code = 'X';
Serial.flush();
gsmStatus = gsmAccess.begin(PINNUMBER,false,false);
int retrycount = 60;
while (gsmStatus != GSM_READY && retrycount-- > 0) {
delay(1000); // lower delay value could lead to unstable state
theGSM3ShieldV1ModemCore.manageReceivedData();
gsmStatus = gsmAccess.getStatus();
}
if (gsmStatus != GSM_READY) {
Serial.println("\n[ERR]: GSM connection failed\n");
Serial.flush();
gsmAccess.shutdown();
delay(250);
digitalWrite(3,LOW);
}
Serial.println(" [DONE]");
// connection state
boolean notConnected = true;
// Start GSM connection
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
{
notConnected = false;
}
else
{
Serial.println("\nNot connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
\r
s with\n
s?