Tracking System.

Hello,

I’m trying to get my SIM900 GPRS to work with my shielded EM 406a !!. I’ve tried attaching both gps shield and gprs shields on top of each other on top of my arduino uno and it keeps outputting welcome, they’re working separately, but not together !. Is the hardware connection connected correctly ??. And, what software modifications do you guys suggest ?!!. Any help would be greatly appreciated. .

// In order for this sketch to work, you will need to download 
// TinyGPS and SoftwareSerial library from arduiniana.org and put them 
// into the libraries folder in your ardiuno directory.
#include <SoftwareSerial.h>
#include "Arduino.h"
#include <TinyGPS.h>
#include <SoftwareSerial.h>

// Define which pins you will use on the Arduino to communicate with your 
// GPS. In this case, the GPS module's TX pin will connect to the 
// Arduino's RXPIN which is pin 3.
#define RXPIN 2
#define TXPIN 3
SoftwareSerial mySerial(7, 8);

// This is the serial rate for your terminal program. It must be this 
// fast because we need to print everything before a new sentence 
// comes in. If you slow it down, the messages might not be valid and 
// you will likely get checksum errors.
// Set this value equal to the baud rate of your terminal program
#define TERMBAUD  115200

// Set this value equal to the baud rate of your GPS
#define GPSBAUD  4800

// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the SoftwareSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);

// This is where you declare prototypes for the functions that will be 
// using the TinyGPS library.
void getgps(TinyGPS &gps);

// In the setup function, you need to initialize two serial ports; the 
// standard hardware serial port (Serial()) to communicate with your 
// terminal program an another serial port (SoftwareSerial()) for your 
// GPS.
void setup()
{
 
  //GPS configuration 
  // Sets baud rate of your terminal program
  Serial.begin(TERMBAUD);
  // Sets baud rate of your GPS
  uart_gps.begin(GPSBAUD);
  
  Serial.println("");
  Serial.println("GPS Shield QuickStart Example Sketch v12");
  Serial.println("       ...waiting for lock...           ");
  Serial.println("");
  mySerial.begin(19200);

  //GPRS configuration
  Serial.println("Config SIM900...");
  delay(2000);
  Serial.println("Done!...");
  mySerial.flush();
  Serial.flush();

  // attach or detach from GPRS service 
  mySerial.println("AT+CGATT?");
  delay(100);
  toSerial();


  // bearer settings
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(2000);
  toSerial();

  // bearer settings
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"viva.bh\"");
  delay(2000);
  toSerial();

  // bearer settings
  mySerial.println("AT+SAPBR=1,1");
  delay(2000);
  toSerial();
}

// This is the main loop of the code. All it does is check for data on 
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences, 
// then jumps to the getgps() function.
void loop()
{
  Serial.println("Welcome!...");
  float lat, lon;
  while(uart_gps.available())     // While there is data on the RX pin...
  {
      int c = uart_gps.read();    // load the data into a variable...
      if(gps.encode(c))      // if there is a new valid sentence...
      {
        getgps(gps, lat, lon);         // then grab the data.
		 if (Serial.available())
			switch(Serial.read())
			{
			case 't':
			SendTextMessage(lat,lon);
			break;
			case 'd':

			break;
			case 'h':

			break;
			case 's':

			break;
			} 
    }
  }
 
  if (mySerial.available())
    Serial.write(mySerial.read());
}

void SendTextMessage(float lat, float lon)
{
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+97333515924\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.print("lat= ");//the content of the message
  mySerial.print(lat);
  mySerial.print(" ,lon= ");//the content of the message
  mySerial.print(lon);
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps, float &kan, float &lon)
{
  // To get all of the data into varialbes that you can use in your code, 
  // all you need to do is define variables and query the object for the 
  // data. To see the complete list of functions see keywords.txt file in 
  // the TinyGPS and SoftwareSerial libs.
  
  // Define the variables that will be used
  float latitude, longitude;
  // Then call this function
  gps.f_get_position(&latitude, &longitude);
  // You can now print variables latitude and longitude
  Serial.print("Lat/Long: "); 
  Serial.print(latitude,5); 
  Serial.print(", "); 
  Serial.println(longitude,5);  
  // Here you can print statistics on the sentences.
  unsigned long chars;
  unsigned short sentences, failed_checksum;
  gps.stats(&chars, &sentences, &failed_checksum);
  //Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
  //Serial.println(); Serial.println();
}
void toSerial()
{
  while(mySerial.available()!=0)
  {
    Serial.write(mySerial.read());
  }
}

What has this problem got to do with a "Tracking system"?
Are you running out of RAM?
What happens if you move your constant strings into PROGMEM?

(Is,,,, there ; something !! wrong with //// your punctuation keys? )

#include <SoftwareSerial.h>
#include "Arduino.h"
#include <TinyGPS.h>
#include <SoftwareSerial.h>

Maybe you need to include SoftwareSerial.h several more times.

// Define which pins you will use on the Arduino to communicate with your 
// GPS. In this case, the GPS module's TX pin will connect to the 
// Arduino's RXPIN which is pin 3.
#define RXPIN 2
#define TXPIN 3
SoftwareSerial mySerial(7, 8);

Well, which is it? Pins 2 and 3 or pins 7 and 8?

// Initialize the SoftwareSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);

Never mind. I see. You are trying to use two instances of SoftwareSerial. I recommend that you find a padded wall to keep banging your head against.

Get a Mega.

PaulS:

#include <SoftwareSerial.h>

#include “Arduino.h”
#include <TinyGPS.h>
#include <SoftwareSerial.h>



Maybe you need to include SoftwareSerial.h several more times.



// Define which pins you will use on the Arduino to communicate with your
// GPS. In this case, the GPS module’s TX pin will connect to the
// Arduino’s RXPIN which is pin 3.
#define RXPIN 2
#define TXPIN 3
SoftwareSerial mySerial(7, 8);



Well, which is it? Pins 2 and 3 or pins 7 and 8?



// Initialize the SoftwareSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);



Never mind. I see. You are trying to use two instances of SoftwareSerial. I recommend that you find a padded wall to keep banging your head against.

Get a Mega.

Not really, I got it to work with the UNO !!. I guess you need to update your info cuz it seems to be outdated !.

I guess you need to update your info cuz it seems to be outdated !.

Which part? I KNOW that you are not able to get data from the GPS while sending data with the GPRS. With a Mega, sending data on one serial port would not interfere with receiving data on another port.

MAGMAM:
Not really, I got it to work with the UNO !!. I guess you need to update your info cuz it seems to be outdated !.

You can create two instances of SoftwareSerial, but you can only use one of them at a time. This is not useful if you want to be able to receive from two devices independently, or send and receive at the same time.