0

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");
}
  • You seem to be using different baud rates in each example. Which is the correct one? – Nick Gammon Aug 30 '15 at 21:18
  • Do you get a AT%10% error if you change your \rs with \ns? – Gerben Aug 31 '15 at 14:35
  • Sorry for the mix-up with the baud rates. They are actually irrelevant since both are correct, the codes are from two different examples. Unfortunately I was not able to resolve this problem using GSM.h. I stuck with SoftwareSerial.h but have found a reliable, reproducible solution to the problem. First, I now use` SIM900.print("AT+CNMI=1,2,0,0,0\r"); ` to initialize my SMS mode, it seems to enable properly every time. Second, after the read() from the SIM card I clear out the contents with SIM900.flush() which seems to prevent phantom messages from appearing. – Andrew Sep 3 '15 at 0:31
1

Check your baud rates. They appear to be different. That will cause problems.

  • They are two different codes, not meant to run together. But true, the baud rates for the top and bottom don't match, but that does not solve the problem. – Andrew Aug 31 '15 at 12:25
1

I used Mega 2560 connected to GSM shield as following:

  • GSM TX --- pin 10 on Mega
  • GSM RX --- pin 3 on Mega

  • GND to GND

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.