0
votes

I am using CRIUS Neo-6 GPS module and I would like to send data from GPS via GSM module every 10 seconds. The piece of code I have looks like this:

if (Serial1.available() > 0)
if (gps.encode(Serial1.read()))
{

  double hour = gps.time.hour();
  double minute = gps.time.minute();
  double second = gps.time.second();

    Serial.println("Sending SMS:");
    GPRS.print("AT+CMGF=1\r");
    delay(100);
    GPRS.println("AT+CMGS= \"00*********\"");
    delay(100);
    GPRS.print("HOUR=");
    GPRS.print(hour);
    GPRS.print(" MINUTE=");
    GPRS.println(minute);
    GPRS.print(" SECOND=");
    GPRS.println(second);
    delay(100);
    GPRS.print((char)26);
    delay(100);
    GPRS.println();
    Serial.println("Text sent.");


  Serial.println();
 delay(10000);
}

Serial1 is a SoftwareSerial instance for communication with GPS module. Now this sends an SMS every 10 seconds but the data is messed up, it is like the time doesnt refresh always. I get something like:

HOUR=6.00 MINUTE=37.00 SECOND=54.00

HOUR=6.00 MINUTE=37.00 SECOND=54.00

HOUR=6.00 MINUTE=37.00 SECOND=54.00

HOUR=6.00 MINUTE=38.00 SECOND=15.00

and so on.. Its like always two or three identical SMS-es and then next one with 30 seconds gap. What should I change to always send latest gps time?

1

1 Answers

0
votes

1) Tell us what Arduino you are using. It looks like it might be a Mega.

2) Post your entire sketch and identify what libraries you are using. It looks like it might be TinyGPS++.

5) Don't use double. It's the same as float on the Arduino. But don't use float either. Just use int or unsigned char.

Now then. Did the example programs work? That would confirm that you have good satellite reception.

Next, did you know that your GPS sends several different kinds of messages each second? Not all messages contain a time field (see this table of messages vs. fields).

And finally, these lines will cause a lot of trouble:

delay(100);
  ...
delay(100);
  ...
delay(100);
  ...
delay(100);
  ...
delay(10000);[/code]

While the sketch is stopped at these delays, no GPS characters are being processed. But then you wait for just one message to get parsed with "if (gps.encode", and you send another SMS. The only message that got parsed probably did not have a time field, so you send the same time.

You should research ways to avoid using delay. Take a look at some posts on the Arduino forum, "Serial Input Basics" and "How to do several things at a time" in Useful Links.

Also, I wrote a better GPS library, called NeoGPS. It is much smaller and faster than TinyGPS++. The examples are structured better, too. NMEAtimezone.ino is closest to what you are doing. If you'd like to try it, be sure to follow the Installation instructions. You should try several programs as described, in this order: NMEA, NMEAdiagnostic and NMEAorder if necessary, and NMEAfused. Then try NMEAtimezone, and modify it for what you are doing.