Go Down

Topic: Send Adafruit Breakout Rev3 GPS coordinates to Arduino GSM SIM900 Shield (Read 1 time) previous topic - next topic

vm1

We are attempting to send an SMS through our GSM shield with the coordinates we got from out GPS. Both components work fine separate, but merging the code does not get GPS or send SMS.

Any help would be appreciated.

#include <LiquidCrystal.h>
#include <Adafruit_GPS.h> //Load the GPS Library.
#include <SoftwareSerial.h> //Load the Software Serial Library. This library in effect gives the arduino additional serial ports

SoftwareSerial mySerial(7, 6); //Initialize SoftwareSerial, and tell it you will be connecting through pins : Tx: 7 and Rx: 6

Adafruit_GPS GPS(&mySerial); //Create GPS object
LiquidCrystal LCD(12,11,5,4,3,2);//already using PIN 2 & 3 for GPS

SoftwareSerial gsm (8,9);

String NMEA1;  //We will use this variable to hold our first NMEA sentence
String NMEA2;  //We will use this variable to hold our second NMEA sentence
String NMEA3;
char c;       //Used to read the characters spewing from the GPS module

int scrollCursor = 16 ; //screen width

void setup()  
{
 
 Serial.begin(115200);  //Turn on the Serial Monitor
 GPS.begin(9600);       //Turn GPS on at baud rate of 9600
 gsm.begin(9600); //turn GSm on

 
 GPS.sendCommand("$PGCMD,33,0*6D"); // Turn Off GPS Antenna Update
 GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); //Tell GPS we want only $GPRMC and $GPGGA NMEA sentences
 GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
 

 
 //setting up LCD
 LCD.begin(16,2); //set up 16 cols and 2 rows- roughly the whole screen

 delay(1000);  //Pause

 

}


void loop()                     // run over and over again
{
 mySerial.listen();
 
 //Serial.println("Data from GPS");
 while(mySerial.available() > 0)
 {
   readGPS();  //This is a function we define below which reads two NMEA sentences from GPS
 }


 Serial.println();

 LCD.setCursor(0,0);
 LCD.print("Latitude:");
 LCD.setCursor(0,1);
 LCD.print("Longitude:");

 

//1st line
 LCD.setCursor(9,0);
 LCD.print(GPS.latitudeDegrees);

 //2nd line
 LCD.setCursor(10,1);
 LCD.print(GPS.longitudeDegrees);
 
 delay(1000);

 
 //LCDDisplayCordinate();  //display cordinate on LCd

}
void readGPS()
{
 //This function will read and remember two NMEA sentences from GPS
 clearGPS();    //Serial port probably has old or corrupt data, so begin by clearing it all out
 while(!GPS.newNMEAreceived()) { //Keep reading characters in this loop until a good NMEA sentence is received
 c=GPS.read(); //read a character from the GPS
 }
GPS.parse(GPS.lastNMEA());  //Once you get a good NMEA, parse it
NMEA1=GPS.lastNMEA();      //Once parsed, save NMEA sentence into NMEA1

while(!GPS.newNMEAreceived())
{  //Go out and get the second NMEA sentence, should be different type than the first one read above.
 c=GPS.read();
 }
GPS.parse(GPS.lastNMEA());

NMEA2=GPS.lastNMEA();

while(!GPS.newNMEAreceived())
{ //Keep reading characters in this loop until a good NMEA sentence is received
 c=GPS.read(); //read a character from the GPS
}
 
 Serial.println(NMEA1);
 Serial.println(NMEA2);

 Serial.print("Location: ");
 Serial.print(GPS.latitude, 4);
 Serial.print(GPS.lat);
 
 Serial.print(", ");
 
 Serial.print(GPS.longitude, 4);
 Serial.println(GPS.lon);
 Serial.print("Location (in degrees, works with Google Maps): ");
 
 Serial.print(GPS.latitudeDegrees, 4);
 Serial.print(", ");
 Serial.println(GPS.longitudeDegrees, 4);

//call gsmInit() to send the message
 GsmInit();

 Serial.println("");

}

void clearGPS()
{  
 //Since between GPS reads, we still have data streaming in, we need to clear the old data by reading a few sentences, and discarding these
while(!GPS.newNMEAreceived()) {
 c=GPS.read();
 }
GPS.parse(GPS.lastNMEA());
while(!GPS.newNMEAreceived()) {
 c=GPS.read();
 }
GPS.parse(GPS.lastNMEA());

}

void LCDDisplayCordinate()
{


 //LCD.clear();
}

void sendSMS() {
 // AT command to set gsm to SMS mode
 gsm.print("AT+CMGF=1\r");
 delay(100);

 // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
 // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
 gsm.println("AT + CMGS = \"+XXXXXXXXXXXX\"");
 delay(100);
 
 // REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
 gsm.println("Message example from Arduino Uno.");
 delay(100);

 // End AT command with a ^Z, ASCII code 26
 gsm.println((char)26);
 delay(100);
 gsm.println();
 // Give module time to send SMS
 delay(5000);
}

void  GsmInit()
{
 //gsm.listen();
 // AT command to set gsm to SMS mode
 gsm.print("AT+CMGF=1\r");
 delay(100);

 // REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
 // USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
 gsm.println("AT + CMGS = \"xxxxxxxxxxx\"");
 delay(100);
 
 // REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
 gsm.println("Message example from Arduino Uno.");
 delay(100);

 // End AT command with a ^Z, ASCII code 26
 gsm.println((char)26);
 delay(100);
 gsm.println();
 // Give module time to send SMS
 delay(5000);
 
}


Go Up