GSM hangs on gsm.begin()

From post I have read it's not a new problem but I still can't find a solution.

Using a SIM900 GSM GPRS Shield (the one featured in https://randomnerdtutorials.com/sim900-gsm-gprs-shield-arduino/) and the GSM.h library with the header:
/*
This file is part of the GSM3 communications library for Arduino
-- Multi-transport communications platform
-- Fully asynchronous
-- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
-- Voice calls
-- SMS
-- TCP/IP connections
-- HTTP basic clients

This library has been developed by Telefónica Digital - PDI -

  • Physical Internet Lab, as part as its collaboration with
    Arduino and the Open Hardware Community.

September-December 2012

My code just hangs when I call the gsm.begin() function.

To recap:
I can send SMS messages using my SIM on the GSM shield if I poke the GSM modem with AT commands directly from my Uno.
I conclude that my SIM card is unlocked, my separate GSM shield PSU is 'up for the job' and that I don't have a fundamental hardware or Arduino to shield hook up issue (I'm using the standard pin7 & 8).

The begin() call just goes into hyper space, never to return. What's going on?

I can do what I want to do, just using AT commands but the GSM library looks like it has a bundle of easy to use stuff in it.

I appreciate I am 'late to the table' on this one, but could someone please aim me at a solution, Many thanks.

my separate GSM shield PSU is 'up for the job' and that I don't have a fundamental hardware or Arduino to shield hook up issue

still clarify how is it powered? (2Amps I assume?)

a link to the library would help too

Hi
Yup - I have tried several PSUs, one rated at 5V 2A, another 12V 0,8A (yes I know that one was a bit lite).

The GSM library was the one that installed when I installed my Arduino IDE. It came with a README.adoc which stated:

= GSM Library for Arduino =

With the Arduino GSM Shield, this library enables an Arduino board to do most of the operations you can do with a GSM phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network.

For more information about this library please visit us at

== License ==
Copyright (c) 2012 Telefónica Digital - PDI - Physical Internet Lab

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

There was also a folder structure that included examples, extras and the scr - the location of the GSM.h and all the associated .cpp and .h files

OK, so this is the standard GSM library

Do you have a toggle switch on your SIM900 GSM GPRS Shield to say "use the external power supply" and if so, is it in the correct position?

what does this do?

#include <GSM.h>

#define PINNUMBER "" // your pin

GSM gsm;

void setup()
{
  // initialize serial communications
  Serial.begin(9600);

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsm.begin(PINNUMBER)==GSM_READY)  notConnected = false;
    else  {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
}

void loop() {}

Yup - my GSM shield power slider switch is in the External position - as in pushed in towards the MIN900 chip.

I'm, familiar with the code snippet - this is what hangs - this does not print "Not connected" or "GSM initialized" - the code just hangs at the gsm.begin() call.

I have PINNUMBER as "" - I do not believe my new GiffGaff SIM card is locked as I can make calls with the GSM modem by sending it AT commands, as in - these commands work OK using the <SoftwareSerial.h> library (I can't include this with GSM.h however as they seem to conflict) ...

#include <SoftwareSerial.h>

..
..
SoftwareSerial SIM900(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8
..
..

void sendTheMessage(String message){
  SIM900.println("AT+CMGF=1"); 
  delay(2000);
 
  // use international phone number format
  SIM900.println("AT+CMGS=\"" + mobile  + "\" "); 
  delay(2000); 

  // the message to send 
  SIM900.println(message); 
  delay(2000);

  // End AT command with a ^Z, ASCII code 26
  SIM900.println((char)26); 
  delay(2000);
}

I think it is an incompatibility between my version of the GSM shield and the library code - or a timing issue that I have no control over using the library. Hey, maybe it uses pins other than 7 and 8 to talk to the shield. I don't know as there's little definitive documentation I can find.

Still bruising my shins on this one.


please edit your post, select the code part and press the </> icon in the tool bar to mark it as code.

(also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)


There is some online documentation @ https://www.arduino.cc/en/Reference/GSM

the begin() call

returns status : ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED
you could try to change the code to see if there is actually something returned (if anything)

if it's stuck really in the begin() method, that might be because it has hidden parameters with default value, including synchronous=true which could lead to a potential infinite loop

// If synchronous, wait till ModemConfiguration is over
	if(synchronous)
	{
		// if we shorten this delay, the command fails
		while(ready()==0) 
			delay(1000); 
	}

You could add some debug information in the source code of the library.

The class that gets instantiated when you do GSM gsm; is the GSM3ShieldV1AccessProvider. If you look at the constructor there is a parameter you can pass to activate the debug mode. So you could try GSM gsm(true);. That could provide possibly useful info

Thanks for the tip on formatting posted code - edit done. (Sorry, I'm a newbie).
I tried the begin() method with the synchronous parameter set to false (default is true). I called this multiple times - it just returned 0 until I got bored.

I did try adding the debug parameter - as in GSM gsm(true) - I also tried to see what was being returned:

My current code:

#include <GSM.h>
//#include <SoftwareSerial.h> // this library conflicts with GSM.h and generates a compiler error
//SoftwareSerial SIM900(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8  - see above  - so can't set this up
#define PINNUMBER "" // I am convinced my SIM is unlocked as I can send SMS messages with it if I just use SoftwareSerial.h and use AT commands

// initialize the library instance
GSM gsmAccess(true); // include a 'true' parameter for debug enabled
GSM_SMS sms;

// char array of the telephone number to send SMS
// change the number 1-212-555-1212 to a number
// you have access to
char remoteNumber[20]= "+44[*my mobile here*]";
// char array of the message
char txtMsg[200]="Test";

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)  {
    if(gsmAccess.begin("",true,false)==GSM_READY){
    //if(gsmAccess.begin()==GSM_READY) {
      Serial.println("A");
      notConnected = false;
      }
    else {
      Serial.println("Not connected");
      Serial.println(gsmAccess.begin("",true,false));
      delay(1000);
    }
  }
  Serial.println("GSM initialized");
  sendSMS();
}
void loop()
{
// nothing to see here
}
void sendSMS(){
  Serial.print("Message to mobile number: ");
  Serial.println(remoteNumber);
  // sms text
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);
  // send the message - OK just don't not yet 
  //sms.beginSMS(remoteNumber);
  //sms.print(txtMsg);
  //sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
}

This is what serial output yields:

SMS Messages Sender
AT%13%Not connected
AT%13%2
AT%13%Not connected
AT%13%2
AT%13%Not connected

So the gsmAccessBegin is returning "2". Not sure really what this means. Is this progress?

I'll have a bash at inserting some debug lines in the library source code but loath to do this (many better men have trod here before).

OK - I tried something really basic.
With code as above, I powered down the GSM shield (un-jacked the power). The power select is in External position so GSM shield needs external power. There is no power light on GSM shield.
But what I found is the same output on the serial monitor.

SMS Messages Sender
AT%13%Not connected
AT%13%2
AT%13%Not connected
AT%13%2

My conclusion is that it is as if my Uno were not connected to GSM shield.
So some basic stuff - I populated pins on shield so I could piggy back this direct onto Uno.
My successful tests with AT commands and the <SoftwareSerial.h> , using the SoftwareSerial SIM900(7, 8); to set up coms with the shield on pins 7 and 8.
Am I missing something? What pins does the GSM.h library use to connect to the GSM shield? I assumed it was pins 7 and 8 as these fit snugly in a piggy back physical interconnect. Pin 9 for s/w control of shield power up also fit snugly.
If my pin interconnect was wrong, I'd get the same duff results.
This could be a simple pin issue - is the pin use of GSM.h documented anywhere?
I feel I am getting closer to a solution.

Ouch - I just followed the link "(https://www.arduino.cc/en/Reference/GSM)"
My GSM shield doesn't look like this one. Mine is as per link right at the start of my post eg https://randomnerdtutorials.com/sim900-gsm-gprs-shield-arduino/

I think I may be using the wrong pins - can anyone help?

This is what's expected by the GSM library

--> use of pin 2 and 3.

Are you stacking your module or using wires like documented here?


You could try wiring to pin 2 and 3 instead of 7 and 8

———— to previous questions ——————
the error code returned comes from this enum

enum GSM3_NetworkStatus_t { ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED, OFF};

so code 2 would be GSM_READY

the debug seems to indicate that there is no answer to the AT\r command. May be your module needs AT\r\n

When you got it working with SoftwareSerial and sending SMS, you were using println() to send the AT commands which adds "\r\n" at the end of the request.

May be that's enough of a difference... you could try modifying the library and edit the GSM3ShieldV1ModemCore.cpp, find all the occurrences of print("\r");and replace then with println()

Hi J-M-L
Many thanks for the suggestions - yes I am attempting to stack the shield onto the Uno - very neat solution as I can use documented pin9 to control a s/w GSM shield power up/down.
But I'll try using the wiring as per the RandomNerdTutorials.com then try connecting to pin 2,3 then start poking about in the .cpp file.
Lots of directions to explore. Many thanks.

alternatively you could use a generic SIM900 library... there are some floating around.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.