SIMCOM SIM900 module is shutting down when connecting with GPS Shield

Hi,

I stacked SIMCOM SIM900 GSM GPRS shield to Arduino Uno and stacked Arduino GPS Shield to SIM900. When i power on SIM900, signal light is blinking for few seconds and going off. But when i connect only SIM900 to Arduino Uno (without Arduino GPS) it works perfectly. I dont see any wrong in the Arduino GPS also because when I connect GPS alone to Arduino Uno (without SIM900) it is working perfectly.

Any help is appreciated. If anybody has any working sample code, can you please provide.

If it isn't a code issue, which is hard to rule out, since you didn't post your code, and it isn't a pin conflict issue, which is hard to rule out since you didn't post your code or any links to the hardware, then it must be a power issue. How are you powering the two shields?

Thank you for the reply. I am thinking it is software issue. Attached is the image for how i stacked Arduino UNO, GSM/GPRS and GPS shields. Below is my complete code. In this code i am just sending one text msg in setup method and in the loop method i am just printing lat/longs for testing purpose. My end goal is to collect lat/longs for every second and send to server by calling some web service.

But after loading below code, GPS device is not signal and sometimes after unplugging USB cable and power on manually GPRS shield is not getting signal and signal LED is going off

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <String.h>

SoftwareSerial gprsSerial(7, 8);

int RXPin = 3;
int TXPin = 2;

int GPSBaud = 9600;

TinyGPSPlus gps;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);
static void smartdelay(unsigned long ms);

static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (gpsSerial.available())
gps.encode(gpsSerial.read());
} while (millis() - start < ms);
}

void setup()
{
// Start the Arduino hardware serial port at 9600 baud
Serial.begin(115200);

// Start the software serial port at the GPS's default baud
gpsSerial.begin(GPSBaud);
delay(1000);
gprsSerial.begin(19200);
delay(1000);
SendTextMessage();
}

void loop()
{
// This sketch displays information every time a new sentence is correctly encoded.
while (gpsSerial.available() > 0)
if (gps.encode(gpsSerial.read()))
displayInfo();

// If 5000 milliseconds pass and there are no characters coming in
// over the software serial port, show a "No GPS detected" error
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected"));
while(true);
}
}

void displayInfo()
{
String url = "Latitude = ";

if (gps.location.isValid())
{
Serial.println(gps.location.lat(), 6);
Serial.println(gps.location.lng(), 6);
url += String(gps.location.lat(), 6);

url += ", Longitude = ";
url += String(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}

if (gps.date.isValid())
{
url += ", Date = ";
url += gps.date.month();
url += "-";
url += gps.date.day();
url += "-";
url += gps.date.year();
}
else
{
Serial.print(F("INVALID"));
}

if (gps.time.isValid())
{
url += " ";
if (gps.time.hour() < 10)
url += "0";
url += gps.time.hour();

url += ":";
if (gps.time.minute() < 10)
url += "0";
url += gps.time.minute();

url += ":";
if (gps.time.second() < 10)
url += "0";
url += gps.time.second();

}
else
{
Serial.print(F("INVALID"));
}

Serial.println(url);
Serial.println();
//delay(1000);
smartdelay(3000);
}

void SendTextMessage()
{
gprsSerial.print("AT+CMGF=1\r");
delay(100);
gprsSerial.println("AT + CMGS = "+1xxxxxxxxxxx"");
delay(100);
gprsSerial.println("A test message new message 2!");
delay(100);
gprsSerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(100);
gprsSerial.println();
}

SoftwareSerial gprsSerial(7, 8);

Well, there is your problem. You should not be using the smiley face pin for SoftwareSerial.

Actually that is 8 not smiley. This posting editor converted ,8 to smiley face. So actually it is like this

SoftwareSerial gprsSerial(7, 8 ) ;

This posting editor converted ,8 to smiley face.

It did that because you failed to use code tags, as you are supposed to. Read the stickies at the top of the forum.

I still suspect that your two power hogs are causing the Arduino voltage to drop when they are started, resetting the Arduino.

Now at least i am able to on GSM/GPRS module manually. But with new issue. If i give gprsSerial.begin(19200); in setup method i am not getting GPS data, but if i comment gprsSerial.begin(19200); then GPS data is coming. Is there anything wrong with the baud?

void setup()
{
// Start the Arduino hardware serial port at 9600 baud
Serial.begin(115200);

// Start the software serial port at the GPS's default baud
gpsSerial.begin(GPSBaud);
delay(1000);
gprsSerial.begin(19200);
delay(1000);
SendTextMessage();
}

You can only have one SoftwareSerial listening at a time. When you start the gpsrSerial, the Arduino stops listening to the gpsSerial.

Here is a similar app. It shows how to listen to the GPS until it has a good location. Then it listens to the SIM900 while it sends the location to a website. Then it goes back to listening to the GPS.

BTW, SoftwareSerial is very inefficient. It blocks interrupts for long periods of time. This can interfere with your sketch or with other libraries. It cannot transmit and receive at the same time.

AltSoftSerial is the best software serial library, but it can only be used on pints 8 & 9 (of an UNO).

If you can't use those pins, my NeoSWSerial library is almost as efficient. It can transmit and receive at the same time, and it supports baud rates 9600, 19200 and 38400.

I would also suggest my NeoGPS library. It is smaller, faster and more accurate than all other libraries. Here is a version of your sketch that uses NeoGPS and NeoSWSerial:

#include <NMEAGPS.h>
#include <NeoSWSerial.h>

NeoSWSerial gprsSerial(7, 8);
bool okToSendMessage = true;

int RXPin = 3;
int TXPin = 2;

int GPSBaud = 9600;

NMEAGPS gps;
gps_fix fix; // all the GPS information fields in one struct
bool    firstFixIgnored = false;

NeoSWSerial gpsSerial(RXPin, TXPin);

void setup()
{
  // Start the Arduino hardware serial port at 9600 baud
  Serial.begin(115200);

  gprsSerial.begin(19200);

  gpsSerial.begin(GPSBaud);
}

void loop()
{
  while (gps.available( gpsSerial )) {
    fix = gps.read();

    if (firstFixIgnored) {
      displayInfo();

      // Only send one message after reset
      if (okToSendMessage) {
        SendTextMessage();
        okToSendMessage = false;
      }
    } else {
      firstFixIgnored = true;
    }
  }

  // If 5000 milliseconds pass and there are no characters coming in
  // over the software serial port, show a "No GPS detected" error
  if ((millis() > 5000) && (gps.statistics.chars < 10))
  {
    Serial.println( F("No GPS detected") );
    while(true);
  }
}

void displayInfo()
{
  Serial.print( F("Latitude = ") );

  if (fix.valid.location)
    Serial.print( fix.latitude(), 6 );
  Serial.print( F(", Longitude = ") );
  if (fix.valid.location)
    Serial.print( fix.longitude(), 6 );

  Serial.print( F(", Date = ") );

  if (fix.valid.date)
  {
    Serial.print( fix.dateTime.month );
    Serial.print( '-' );
    Serial.print( fix.dateTime.day );
    Serial.print( '-' );
    Serial.print( fix.dateTime.year );
  }

  if (fix.valid.time)
  {
    Serial.print( ' ' );
    if (fix.dateTime.hours < 10)
      Serial.print( '0' );
    Serial.print( fix.dateTime.hours );
    
    Serial.print( ':' );
    if (fix.dateTime.minutes < 10) 
      Serial.print( '0' );
    Serial.print( fix.dateTime.minutes );
    
    Serial.print( ':' );
    if (fix.dateTime.seconds < 10) 
      Serial.print( '0' );
    Serial.print( fix.dateTime.seconds );
    
  }

  Serial.println();
}

void SendTextMessage()
{
  gprsSerial.listen();

  gprsSerial.print("AT+CMGF=1\r");   
  delay(100);
  gprsSerial.println("AT + CMGS = \"+1xxxxxxxxxxx\"");
  delay(100);
  gprsSerial.println("A test message new message 2!");
  delay(100);
  gprsSerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  gprsSerial.println();

  gpsSerial.listen();
  firstFixIgnored = false;
}

Your original sketch used 13632 bytes of program space and 695 bytes of RAM.
The NeoGPS sketch uses 10406 bytes of program space and 529 bytes of RAM, a significant savings.

If you'd like to try it, you can get NeoGPS from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries.... NeoSWSerial can be downloaded from the link above.

It you never read the responses from the GPRS device, and you could change one of their baud rates to match the other one, you would not have to call listen() to switch between them. You only have to listen to the GPS. And then you could use just one NeoSWSerial variable:

    NeoSWSerial gpsSerial( 3, 8 );
    #define gprsSerial gpsSerial // they're the same!

This one variable could be used to receive on pin 3 (from GPS) and transmit on pin 8 (to GPRS). But, like I said, the baud rates would have to be the same.

Cheers,
/dev

Thank you so much for your help and explanation. I will try these options

I am just using below sketch to see if i can use AltSoftSerial. But looks like nothing is printing in Serial monitor except "AltSoftSerial Test Begin". It supposed to print "Hello World" also right? Is there anything wrong or with my Arduino UNO?

#include <AltSoftSerial.h>

AltSoftSerial altSerial;

void setup() {
Serial.begin(9600);
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(9600);
altSerial.println("Hello World");
}

void loop() {
char c;

if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}

Attached is the image for how i stacked Arduino UNO, GSM/GPRS and GPS shields. Below is my complete code. In this code i am just sending one text msg in setup method and in the loop method i am just printing lat/longs for testing purpose. My end goal is to collect lat/longs for every second and send to server by calling some web service.
....................
But after loading below code, GPS device is not signal and sometimes after unplugging USB cable and power on manually GPRS shield is not getting signal and signal LED is going off

Very nice picture, but it does nothing to answer the question about the power supply. What you write rather suggets you have a power problem, or are just about to, and no amount of coding is going to fix that. So what are you really doing in that arena?

My issue is resolved. Looks like it is software issue not hardware. Many thanks to /dev. I tried to use AltSoftSerial but for some reason did not get results as i expected and finally used /dev suggested code and it worked.