Hello everyone, I'm using this GPS Shield with Arduino Due.
I extract GPS data with this code.
#include "TinyGPS.h"
TinyGPS gps;
#define GPS_TX_DIGITAL_OUT_PIN 5
#define GPS_RX_DIGITAL_OUT_PIN 6
long startMillis;
long secondsToFirstLocation = 0;
#define DEBUG
float latitude = 0.0;
float longitude = 0.0;
int yeargps;
byte monthgps, daygps, hourgps, minutegps, secondgps, hundredths;
unsigned long age;
void setup()
{
#ifdef DEBUG
Serial.begin(19200);
#endif
// Serial1 is GPS
Serial1.begin(9600);//38400//9600);
// prevent controller pins 5 and 6 from interfering with the comms from GPS
pinMode(GPS_TX_DIGITAL_OUT_PIN, INPUT);
pinMode(GPS_RX_DIGITAL_OUT_PIN, INPUT);
startMillis = millis();
Serial.println("Starting");
}
void loop()
{
readLocation();
}
//--------------------------------------------------------------------------------------------
void readLocation(){
bool newData = false;
unsigned long chars = 0;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (Serial1.available())
{
int c = Serial1.read();
Serial.print((char)c); // if you uncomment this you will see the raw data from the GPS
++chars;
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
//else
//Serial.println("Fixing position");
}
}
if (newData)
{
// we have a location fix so output the lat / long and time to acquire
if(secondsToFirstLocation == 0){
secondsToFirstLocation = (millis() - startMillis) / 1000;
Serial.print("Acquired in:");
Serial.print(secondsToFirstLocation);
Serial.println("s");
}
unsigned long age;
gps.f_get_position(&latitude, &longitude, &age);
if (age == TinyGPS::GPS_INVALID_AGE)
Serial.println("No lock detected!");
else
Serial.println("GPS locked, data is valid !");
latitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : latitude;
longitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : longitude;
Serial.print("Location: ");
Serial.print(latitude, 6);
Serial.print(" , ");
Serial.print(longitude, 6);
Serial.println("");
gps.crack_datetime(&yeargps, &monthgps, &daygps, &hourgps, &minutegps, &secondgps, &hundredths, &age);
if (age == TinyGPS::GPS_INVALID_AGE)
Serial.println("Invalid datetime data");
else
{
Serial.print("Year: ");
Serial.print(yeargps);
Serial.print(", month: ");
Serial.print(monthgps);
Serial.print(", Day: ");
Serial.println(daygps);
Serial.print(hourgps);
Serial.print(":");
Serial.print(minutegps);
Serial.print(":");
Serial.println(minutegps);
Serial.print("Hundredths: ");
Serial.println(hundredths);
}
}
if (chars == 0){
// if you haven't got any chars then likely a wiring issue
Serial.println("Check wiring");
}
else if(secondsToFirstLocation == 0){
// still working
}
}
It is an example obtained from http://davidhoulding.blogspot.com.es/2014/06/gps-location-sensing-with-arduino-mega.html with a little modifications
The serial output obtained is:
Starting
$GPGGA,173156.000,3806.7776,N,00054.5494,W,1,15,0.7,37.8,M,50.5,M,,0000*77
$GNGSA,A,3,25,12,02,31,14,29,24,32,,,,,1.4,0.7,1.2*20
$GNGSA,A,3,79,88,78,82,80,81,70,,,,,,1.4,0.7,1.2*20
$GPGSV,3,1,10,25,66,357,51,12,37,060,49,02,25,067,48,31,28,313,33*75
$GPGSV,3,2,10,14,37,287,31,29,64,201,30,24,26,132,28,32,40,252,25*71
$GPGSV,3,3,10,06,04,033,,26,01,270,*7A
$GLGSV,3,1,09,79,59,005,44,88,40,039,38,78,47,081,35,82,23,189,31*66
$GLGSV,3,2,09,80,14,311,29,81,67,140,25,70,11,308,23,77,01,113,38*66
$GLGSV,3,3,09,69,08,256,*5A
$GNRMC,173156.000,A,3806.7776,N,00054.5494,W,0.00,311.25,080317,,,A*6D
$GNZDA,173157.000,08,03,2017,,*41
Acquired in:1s
GPS locked, data is valid !
Location: 38.112961 , -0.909157
Year: 2000, month: 0, Day: 0
17:31:31
Hundredths: 0
The last NMEA trace is ok, it contain correct day, month and year but the gps.crack_datetime function don't work properly and I can't find where is the error in this function.
Can any one help me to correct it?
Thanks, best regards.