I've integrated the TinyGPS in the previous code. For testing, I replaced gpsSerial by Serial and used the example NMEA sequences from the BasicExample.ino that comes with the library.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(9, 10);
TinyGPSPlus gps;
// sterretje: bigger buffer
const byte numChars = 128;
// sterretje end
char receivedChars[numChars];
boolean newData = false;
void setup()
{
Serial.begin(115200);
gpsSerial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop()
{
//sterretje: use new function name
gpsReceive();
//recvWithStartEndMarkers();
// sterretje end
showNewData();
}
// sterretje: rename function
void gpsReceive()
//void recvWithStartEndMarkers()
// sterretje end
{
static boolean recvInProgress = false;
static byte ndx = 0;
// sterretje: start and end marker adjusted
char startMarker = '
For $GPRMC,045251.000,A,3014.4275,N,09749.0626,W,0.51,217.94,030913,,,A*7D the result is
<<$GPRMC,045251.000,A,3014.4275,N,09749.0626,W,0.51,217.94,030913,,,A*7D
>>
HEX data
24 47 50 52 4D 43 2C 30 34 35 32 35 31 2E 30 30 30 2C 41 2C 33 30 31 34 2E 34 32 37 35 2C 4E 2C 30 39 37 34 39 2E 30 36 32 36 2C 57 2C 30 2E 35 31 2C 32 31 37 2E 39 34 2C 30 33 30 39 31 33 2C 2C 2C 41 2A 37 44 0D 0A
GPS data:
Location: 30.240457,-97.817710 Date/Time: 9/3/2013 04:52:51.00
================
For $GPGGA,045252.000,3014.4273,N,09749.0628,W,1,09,1.3,206.9,M,-22.5,M,,0000*6F I get an invalid date (at occasion?)
<<$GPGGA,045252.000,3014.4273,N,09749.0628,W,1,09,1.3,206.9,M,-22.5,M,,0000*6F
>>
HEX data
24 47 50 47 47 41 2C 30 34 35 32 35 32 2E 30 30 30 2C 33 30 31 34 2E 34 32 37 33 2C 4E 2C 30 39 37 34 39 2E 30 36 32 38 2C 57 2C 31 2C 30 39 2C 31 2E 33 2C 32 30 36 2E 39 2C 4D 2C 2D 32 32 2E 35 2C 4D 2C 2C 30 30 30 30 2A 36 46 0D 0A
GPS data:
Location: 30.240455,-97.817710 Date/Time: INVALID 04:52:52.00
================
I suspect a bug in the library but it might be expected behaviour; the BasicExample.ino code displays a date for every sequence but the GPGGA sequences in the example are missing a date field (which I think should be there). I verified this behaviour by changing the sequence so it starts with a GPGGA; the result for the first sequence now also shows an invalid date.
Original:
BasicExample.ino
Basic demonstration of TinyGPS++ (no device needed)
Testing TinyGPS++ library v. 1.0.2
by Mikal Hart
Location: 30.236640,-97.821456 Date/Time: 9/3/2013 04:51:03.00
Location: 30.236640,-97.821456 Date/Time: 9/3/2013 04:51:04.00
Location: 30.239700,-97.815856 Date/Time: 9/3/2013 04:52:00.00
Location: 30.239772,-97.815681 Date/Time: 9/3/2013 04:52:01.00
Location: 30.240457,-97.817710 Date/Time: 9/3/2013 04:52:51.00
Location: 30.240455,-97.817710 Date/Time: 9/3/2013 04:52:52.00
Done.
Modified (so a GPGGA sequence is the first):
BasicExample.ino
Basic demonstration of TinyGPS++ (no device needed)
Testing TinyGPS++ library v. 1.0.2
by Mikal Hart
Location: 30.236640,-97.821456 Date/Time: INVALID 04:51:04.00
Location: 30.239700,-97.815856 Date/Time: 9/3/2013 04:52:00.00
Location: 30.239772,-97.815681 Date/Time: 9/3/2013 04:52:01.00
Location: 30.240457,-97.817710 Date/Time: 9/3/2013 04:52:51.00
Location: 30.240455,-97.817710 Date/Time: 9/3/2013 04:52:52.00
Location: 30.236640,-97.821456 Date/Time: 9/3/2013 04:51:03.00
Done.
;
char endMarker = '\n';
// sterretje end
char rc;
while (gpsSerial.available() > 0 && newData == false)
{
rc = gpsSerial.read();
if (recvInProgress == true)
{
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
// sterretje: include end marker in received message
receivedChars[ndx] = rc;
ndx++;
// sterretje end
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker)
{
// sterretje: include start marker in received message
receivedChars[ndx] = rc;
ndx++;
// sterretje end
recvInProgress = true;
}
}
}
void showNewData()
{
if (newData == true)
{
Serial.print(F("<<"));
Serial.print(receivedChars);
Serial.println(F(">>"));
Serial.println(F("HEX data"));
for (uint8_t cnt = 0; cnt < strlen(receivedChars); cnt++)
{
if (receivedChars[cnt] < 0x10)
{
Serial.print(F("0"));
}
Serial.print(receivedChars[cnt], HEX);
Serial.print(F(" "));
}
Serial.println();
Serial.println(F("GPS data: "));
for (uint8_t cnt = 0; cnt < strlen(receivedChars); cnt++)
{
if (gps.encode(receivedChars[cnt]))
displayInfo();
}
Serial.println(F("================"));
newData = false;
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid())
{
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour());
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
For $GPRMC,045251.000,A,3014.4275,N,09749.0626,W,0.51,217.94,030913,,,A*7D the result is
§DISCOURSE_HOISTED_CODE_1§
For $GPGGA,045252.000,3014.4273,N,09749.0628,W,1,09,1.3,206.9,M,-22.5,M,,0000*6F I get an invalid date (at occasion?)
§DISCOURSE_HOISTED_CODE_2§
I suspect a bug in the library but it might be expected behaviour; the BasicExample.ino code displays a date for every sequence but the GPGGA sequences in the example are missing a date field (which I think should be there). I verified this behaviour by changing the sequence so it starts with a GPGGA; the result for the first sequence now also shows an invalid date.
Original:
§DISCOURSE_HOISTED_CODE_3§
Modified (so a GPGGA sequence is the first):
§DISCOURSE_HOISTED_CODE_4§