Strange NMEA Data from Ultimate GPS

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
blinkerton
 
Posts: 7
Joined: Fri Jan 24, 2014 7:08 pm

Strange NMEA Data from Ultimate GPS

Post by blinkerton »

Hello, I have a Trinket Pro reading data from an Ultimate GPS module and writing NMEA strings to an SD card. When I plot the $GPGGA strings however, I get a macro grid like layout, where each vertex is actually comprised of a smaller set of points, also in a grid pattern.
Screen Shot 2015-05-17 at 1.57.39 AM.png
Screen Shot 2015-05-17 at 1.57.39 AM.png (269.84 KiB) Viewed 300 times
Screen Shot 2015-05-17 at 2.37.07 AM.png
Screen Shot 2015-05-17 at 2.37.07 AM.png (13.13 KiB) Viewed 300 times
Here is the code adapted from adafruit gps examples:

Code: Select all

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <SD.h>

#define TFT_CS     16
#define TFT_RST    17
#define TFT_DC     18
#define SD_CS      19

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

Adafruit_GPS GPS(&Serial);


void setup()  
{
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);

  if (!SD.begin(SD_CS))
    tft.println("sdErr");
}

uint32_t timer = millis();

void loop()
{
  char c = GPS.read();

  if (GPS.newNMEAreceived()) {  
    if (!GPS.parse(GPS.lastNMEA()))
      return;
  }

  if (timer > millis())
    timer = millis();

  if (millis() - timer > 5000) {
    timer = millis();
      
    if (GPS.fix) {
      File dataFile = SD.open("nmea.txt", FILE_WRITE);
      if (dataFile) {
        dataFile.println(GPS.lastNMEA());
        dataFile.close();
      }
    }
  }
}
Any insight would be helpful, thanks.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Strange NMEA Data from Ultimate GPS

Post by adafruit_support_rick »

How many of those sentences have a valid fix? You probably want to modify the sketch to only save the ones with a valid fix

User avatar
blinkerton
 
Posts: 7
Joined: Fri Jan 24, 2014 7:08 pm

Re: Strange NMEA Data from Ultimate GPS

Post by blinkerton »

Based on my understanding of how the Adafruit_GPS library works, the clause

Code: Select all

if (GPS.fix) {
should already be skipping data without a valid fix right? That said, of the 261 recorded $GPGGA and $GPRMC sentences, 66 have an invalid fix (0), 39 have a regular fix (1) and 156 have a DGPS fix (2).

What confuses me is that with a GPS update rate of once per second and saving a sentence every 5 seconds, hiking 5 miles NNW up a river valley over a 3 hour period shows a stair step plot moving exclusively in cardinal directions, rather than moving obliquely on a NNW heading.

I've attached the nmea.txt file in case that helps.
Thanks
Attachments
NMEA.TXT
(120.47 KiB) Downloaded 163 times

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Strange NMEA Data from Ultimate GPS

Post by adafruit_support_rick »

You'e only got a handful of position updates in there ($GPRMC and $GPGGA). The rest are mostly $GPVTG
The RMC and GGA messages are getting lost somehow - probably they're getting corrupted. Turn off everything but RMC messages and see what you get.

User avatar
blinkerton
 
Posts: 7
Joined: Fri Jan 24, 2014 7:08 pm

Re: Strange NMEA Data from Ultimate GPS

Post by blinkerton »

Thanks for your help, I figured out the issue--I was parsing the lat/lon values as ddmm.ssss not ddmm.mmmm

For anyone interested in not making the same parsing mistake, here is the working parsing algorithm (js/node):

Code: Select all

//convert nmea lat or lon string (ddmm.mmmm) to fixed precision float (dd.ddddd)
function parseDM(latLonStr, direction) {
    var match = /(\d{2,})(\d{2}\.\d+)/.exec(latLonStr);
    return convertToD(parseInt(match[1]), parseFloat(match[2]), direction);
}

function convertToD(degrees, minutes, direction) {
    var dd = degrees + minutes/60;
    if(direction == "S" || direction == "W")
        dd *= -1;
    return parseFloat(dd.toFixed(5));
}
Here is refined code for Trinket Pro + Ultimate GPS + TFT/SD that will save a reading to SD every 5 seconds

Code: Select all

#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#include <SD.h>

#define TFT_CS     16
#define TFT_RST    17
#define TFT_DC     18
#define SD_CS      19

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);
Adafruit_GPS GPS(&Serial);

void setup()  
{
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
//  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand("$PMTK220,5000*1B");
  
  tft.initR(INITR_144GREENTAB);
  tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
  tft.fillScreen(ST7735_BLACK);

  if (!SD.begin(SD_CS))
    tft.println("sdErr");
    
  OCR0A = 0xAF;
  TIMSK0 |= _BV(OCIE0A);
}

SIGNAL(TIMER0_COMPA_vect) {
  GPS.read();
}

void loop()
{
  if (!GPS.newNMEAreceived())
    return;

  if (!GPS.parse(GPS.lastNMEA()))
    return;
  
  if (!GPS.fix)
    return;
  
  File dataFile = SD.open("nmea.txt", FILE_WRITE);
  if (!dataFile)
    return;

  dataFile.println(GPS.lastNMEA());
  dataFile.close();
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”