Ultimate GPS Logger Shield Coding Questions
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 5
- Joined: Mon Sep 27, 2010 1:15 pm
Ultimate GPS Logger Shield Coding Questions
Last summer (2013) I purchased the Ultimate GPS Logger Shield but I was not able to get it to reliably log RMC and GGA sentences to the card so I used the previous GPS Logger Shield kit (Version 1.1) shield which worked reliably. Now I am back trying to get the Ultimate GPS Logger Shield to work as it fits the watertight box better (smaller footprint without the wire jumpers for version 1.1). However I am having the same issue that Michael has been describing in detail. I could not get the suggested code revision to compile successfully to upload it to the Arduino Uno. Any other suggestions?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Ultimate GPS Logger Shield Coding Questions
What errors do you get?akrange wrote:I could not get the suggested code revision to compile successfully to upload it to the Arduino Uno.
-
- Posts: 5
- Joined: Mon Sep 27, 2010 1:15 pm
Re: Ultimate GPS Logger Shield Coding Questions
Sorry, I found I had a brace in the wrong place. When I fixed that the script compiled correctly. However when I uploaded it, the unit only logged the RMC sentences to the SD card. Is that what you expected to happen?
Script below:
Script below:
Code: Select all
#include <SPI.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <avr/sleep.h>
// Ladyada's logger modified by Bill Greiman to use the SdFat library
//
// This code shows how to listen to the GPS module in an interrupt
// which allows the program to have more 'freedom' - just parse
// when a new NMEA sentence is available! Then access data when
// desired.
//
// Tested and works great with the Adafruit Ultimate GPS Shield
// using MTK33x9 chipset
// ------> http://www.adafruit.com/products/
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO true
/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */
#define LOG_FIXONLY false
// Set the pins used
#define chipSelect 10
#define ledPin 13
File logfile;
// read a Hex value and return the decimal equivalent
uint8_t parseHex(char c) {
if (c < '0')
return 0;
if (c <= '9')
return c - '0';
if (c < 'A')
return 0;
if (c <= 'F')
return (c - 'A')+10;
}
// blink out an error code
void error(uint8_t errno) {
/*
if (SD.errorCode()) {
putstring("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(',');
Serial.println(card.errorData(), HEX);
}
*/
while(1) {
uint8_t i;
for (i=0; i<errno; i++) {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
}
for (i=errno; i<10; i++) {
delay(200);
}
}
}
void setup() {
// for Leonardos, if you want to debug SD issues, uncomment this line
// to see serial output
//while (!Serial);
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.begin(115200);
Serial.println("\r\nUltimate GPSlogger Shield");
pinMode(ledPin, OUTPUT);
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// see if the card is present and can be initialized:
//if (!SD.begin(chipSelect, 11, 12, 13)) {
if (!SD.begin(chipSelect)) { // if you're using an UNO, you can use this line instead
Serial.println("Card init. failed!");
error(2);
}
char filename[15];
strcpy(filename, "GPSLOG00.TXT");
for (uint8_t i = 0; i < 100; i++) {
filename[6] = '0' + i/10;
filename[7] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
logfile = SD.open(filename, FILE_WRITE);
if( ! logfile ) {
Serial.print("Couldnt create "); Serial.println(filename);
error(3);
}
Serial.print("Writing to "); Serial.println(filename);
// connect to the GPS at the desired rate
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For logging data, we don't suggest using anything but either RMC only or RMC+GGA
// to keep the log files at a reasonable size
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 or 5 Hz update rate
// Turn off updates on antenna status, if the firmware permits it
GPS.sendCommand(PGCMD_NOANTENNA);
Serial.println("Ready!");
}
void loop() {
while (mySerial.available())
{
char c = GPS.read();
if (GPSECHO)
if (c) Serial.print(c);
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trying to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
// Sentence parsed!
Serial.println("OK");
if (LOG_FIXONLY && !GPS.fix) {
Serial.print("No Fix");
return;
}
// Rad. lets log it!
Serial.println("Log");
char *stringptr = GPS.lastNMEA();
uint8_t stringsize = strlen(stringptr);
if (stringsize != logfile.write((uint8_t *)stringptr, stringsize)) //write the string to the SD file
error(4);
if (strstr(stringptr, "RMC")) logfile.flush();
Serial.println();
}
}
/* End code */
Last edited by adafruit_support_rick on Wed Jul 30, 2014 8:33 am, edited 1 time in total.
Reason: please use Code tags when posting code (</> button)
Reason: please use Code tags when posting code (</> button)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Ultimate GPS Logger Shield Coding Questions
I split this into a new topic so m1chael's topic doesn't get confusing.
No, it should log everything. Please post the Serial Monitor output you get from running this sketch.akrange wrote:However when I uploaded it, the unit only logged the RMC sentences to the SD card. Is that what you expected to happen?
-
- Posts: 5
- Joined: Mon Sep 27, 2010 1:15 pm
Re: Ultimate GPS Logger Shield Coding Questions
Adafruit_support _rick,
It took me a little while to realize you split this from Michael's topic. Below is the output by the serial monitor which looks good to my untrained eye:
However, when I look at the data being logged to the SD card, it is composed almost exclusively of RMC sentences, no GGA sentences.
It did record some GGA sentences after it started a new file (lost satellite contact?) below but then went back to just recording RMC sentences.
I did try uploading the script you suggested that michael try and I had same results of gibberish in the serial monitor and no data logged to SD card. I changed the baud rate (all combinations 4800, 9600, 14400 through 152,200) on the GPS chip as you suggested but that did not change the output to anything recognizable.
Thanks for your help>
It took me a little while to realize you split this from Michael's topic. Below is the output by the serial monitor which looks good to my untrained eye:
However, when I look at the data being logged to the SD card, it is composed almost exclusively of RMC sentences, no GGA sentences.
It did record some GGA sentences after it started a new file (lost satellite contact?) below but then went back to just recording RMC sentences.
I did try uploading the script you suggested that michael try and I had same results of gibberish in the serial monitor and no data logged to SD card. I changed the baud rate (all combinations 4800, 9600, 14400 through 152,200) on the GPS chip as you suggested but that did not change the output to anything recognizable.
Thanks for your help>
-
- Posts: 5
- Joined: Mon Sep 27, 2010 1:15 pm
Re: Ultimate GPS Logger Shield Coding Questions
It has been over a week since my last post but I have not heard anything since and had no answer to my last post. I see that Michael (who reported exactly the same problem was told to return his Ultimate GPS Logging shield for replacement. Is that the same suggestion for my problem? I am a researcher with a university and use these units in my research so if these GPS units are not going to work properly I would like to know so I can look at other options. Some answer to my post would be helpful.
Thanks
Thanks
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Ultimate GPS Logger Shield Coding Questions
I'll check to see what you should do. Sorry this got stuck in the cracks.
- adafruit2
- Posts: 22194
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Ultimate GPS Logger Shield Coding Questions
Hi, its been a bit of a while since we've looked at this library, but we're checking it out - it looks like the GGA messages are long and weren't fully parsed. we'll take more time on it today!
One thing to note is you have a bunch of debugging stuff on like GPSECHO - this makes the arduino work a lot harder since the debugging output takes time. i'd remove as much debugging details as possible. eg. turn off GPSECHO and turn on FIXONLY logging
One thing to note is you have a bunch of debugging stuff on like GPSECHO - this makes the arduino work a lot harder since the debugging output takes time. i'd remove as much debugging details as possible. eg. turn off GPSECHO and turn on FIXONLY logging
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Ultimate GPS Logger Shield Coding Questions
Sorry - it's my fault this dropped through the cracks. I don't know how I lost track of this thread.
m1chael had a different problem. It appears that adafruit2 is correct - the GGA sentences are not being fully parsed.
m1chael had a different problem. It appears that adafruit2 is correct - the GGA sentences are not being fully parsed.
- tdicola
- Posts: 1074
- Joined: Thu Oct 17, 2013 9:11 pm
Re: Ultimate GPS Logger Shield Coding Questions
I took a closer look and found a subtle race condition with the example--the problem is with resetting a received flag twice and in some cases missing an entire string of data because the flag was reset just after it was received. Writing to the SD card adds just enough time to the sketch to make the race condition easy to hit, and explains the somewhat random behavior since if the timing was a little different it could change which string was received.
I just merged in a fix to the shield_sdlog example, can you grab the latest version of the library here from github and give it a shot? https://github.com/adafruit/Adafruit-GPS-Library
I just merged in a fix to the shield_sdlog example, can you grab the latest version of the library here from github and give it a shot? https://github.com/adafruit/Adafruit-GPS-Library
- flybob
- Posts: 26
- Joined: Fri Dec 27, 2013 12:16 pm
Re: Ultimate GPS Logger Shield Coding Questions
I had the same problem. Parsing alone worked fine, but the logging sketch just parsed garbage. I tried the new uploaded code and it works fine. Thank you for the quick response.
Bob
Bob
- tdicola
- Posts: 1074
- Joined: Thu Oct 17, 2013 9:11 pm
Re: Ultimate GPS Logger Shield Coding Questions
Thanks for confirming it works. And one more quick update, there was a small bug in minute calculations that I just fixed. Grab the library one more time if you haven't grabbed it in the last 5 mins or so (you want this fix in the lib: https://github.com/adafruit/Adafruit-GP ... 2c9312a721 ).
- flybob
- Posts: 26
- Joined: Fri Dec 27, 2013 12:16 pm
Re: Ultimate GPS Logger Shield Coding Questions
Noticed one more small bug, The GPRMC data uses the $GPRMC sentence identifier but the parser leaves the "$" off the GPGGA sentence identifier. This causes the file to crash when processed by GPS Babel. Manually adding the "$" via notepad makes the output process correctly.
- flybob
- Posts: 26
- Joined: Fri Dec 27, 2013 12:16 pm
Re: Ultimate GPS Logger Shield Coding Questions
What check sum method is used in the Adafruit GPS library definitions. I want to mod the library to also allow a 10 second update rate as that is more suited for long route tracking. The chip supports down to 10 sec update rates. Once working I will be happy to forward to you to include if desired.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Ultimate GPS Logger Shield Coding Questions
The checksum is simple, just an XOR of all the bytes between the $ and the * (not including the delimiters themselves), and written in hexadecimal.
Please be positive and constructive with your questions and comments.