gps

how to send gps data (lat , long) with sim900a using arduino ???

gps code :

#include <SoftwareSerial.h>

SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;

char sentence[sentenceSize];

void setup()
{
Serial.begin(9600);
gpsSerial.begin(9600);
}

void loop()
{
static int i = 0;
if (gpsSerial.available())
{
char ch = gpsSerial.read();
if (ch != ‘\n’ && i < sentenceSize)
{
sentence = ch;

  • i++;*
  • }*
  • else*
  • {*
    _ sentence = ‘\0’;_
    * i = 0;*
    * displayGPS();*
    * }*
    * }*
    }
    void displayGPS()
    {
    * char field[20];*
    * getField(field, 0);*
    * if (strcmp(field, “$GPRMC”) == 0)*
    * {*
    * Serial.print("Lat: ");*
    * getField(field, 3); // number*
    * Serial.print(field);*
    * getField(field, 4); // N/S*
    * Serial.print(field);*

* Serial.print(" Long: ");*
* getField(field, 5); // number*
* Serial.print(field);*
* getField(field, 6); // E/W*
* Serial.println(field);*
* }*
}
void getField(char* buffer, int index)
{
* int sentencePos = 0;*
* int fieldPos = 0;*
* int commaCount = 0;*
* while (sentencePos < sentenceSize)*
* {*
* if (sentence[sentencePos] == ‘,’)*
* {*
* commaCount ++;*
* sentencePos ++;*
* }*
* if (commaCount == index)*
* {*
* buffer[fieldPos] = sentence[sentencePos];*
* fieldPos ++;*
* }*
* sentencePos ++;*
* }*
* buffer[fieldPos] = ‘\0’;*
}
gsm code :
void setup()
{
Serial.begin(9600);
delay(5000);
}
void loop()
{
Serial.println(“AT”);
delay(1000);
Serial.println(“AT+CMGF=1”);
delay(1000);
Serial.println("AT+CMGS=“1234567890"”); //CHANGE TO DESTINATION NUMBER
delay(1000);
Serial.print(“hi”);
Serial.write(26);
delay(1000);
}
please help me
how can we use this two coddes ( gsm send gps data)

Use code-tags.

Do you understand the code you posted? If not, that’s the first thing you should spend your time on.

lg, couka

Here's a hint:

Read instructions prior to posting.

This is how you mash those two together.

#include <SoftwareSerial.h>

SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;

char sentence[sentenceSize];

void setup()
{
  Serial.begin(9600);
  gpsSerial.begin(9600);
}

void loop()
{
  static int i = 0;
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    if (ch != '\n' && i < sentenceSize)
    {
      sentence[i] = ch;
      i++;
    }
    else
    {
      sentence[i] = '\0';
      i = 0;
      displayGPS();
    }
  }
}

void displayGPS()
{
  char field[20];
  getField(field, 0);
  if (strcmp(field, "$GPRMC") == 0)
  {
    // Set up the SMS
    Serial.println("AT");
    delay(1000);
    Serial.println("AT+CMGF=1");
    delay(1000);
    Serial.println("AT+CMGS=\"1234567890\""); //CHANGE TO DESTINATION NUMBER
    delay(1000);

    // Send the GPS data
    Serial.print("Lat: ");
    getField(field, 3);  // number
    Serial.print(field);
    getField(field, 4); // N/S
    Serial.print(field);

    Serial.print(" Long: ");
    getField(field, 5);  // number
    Serial.print(field);
    getField(field, 6);  // E/W
    Serial.println(field);

    // End the SMS
    Serial.write(26);
    delay(1000);
  }
}

void getField(char* buffer, int index)
{
  int sentencePos = 0;
  int fieldPos = 0;
  int commaCount = 0;
  while (sentencePos < sentenceSize)
  {
    if (sentence[sentencePos] == ',')
    {
      commaCount ++;
      sentencePos ++;
    }
    if (commaCount == index)
    {
      buffer[fieldPos] = sentence[sentencePos];
      fieldPos ++;
    }
    sentencePos ++;
  }
  buffer[fieldPos] = '\0';
}

Here’s a really simple version that uses NeoGPS:

#include "NMEAGPS.h"
#include <SoftwareSerial.h>

NMEAGPS gps;

SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)

bool sendEmptyLocations = false; // CHANGE TO true IF YOU WANT TO SEND EMPTY LOCATIONS

void setup()
{
  Serial.begin(9600);
  gpsSerial.begin(9600);
}

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

    if (sendEmptyLocations || fix.valid.location)
    {
      // Set up the SMS
      Serial.println("AT");
      delay(1000);
      Serial.println("AT+CMGF=1");
      delay(1000);
      Serial.println("AT+CMGS=\"1234567890\""); //CHANGE TO DESTINATION NUMBER
      delay(1000);

      // Send the GPS data
      Serial.print("Lat: ");
      Serial.print(fix.latitude(),6);

      Serial.print(" Long: ");
      Serial.println(fix.longitude(),6);

      // End the SMS
      Serial.write(26);
      delay(1000);    // CHANGE TO LONGER INTERVAL
    }
  }
}

NeoGPS verifies the GPS checksum, so it throws away bad locations caused by data errors. It will also skip sending an empty location when you don’t have good satellite reception.

Cheers,
/dev

hi my name is Peyman . i have a problem in gps ( ublox Neo-6m ). how can we send the gps data ( lat , long ) using sim900a also use i2c gps is on a arduino ( master board) and gsm is on another arduino boaed ( slave board ) . can you help me ????? please send me the codes .......... please please