NeoGPS -- Trying to access FIX data in my sketch

I am trying to write a sketch that will eventually print lat and lon to a 2x16 lCD but for now I am just printing to the debug port. I am using NMEA_isr.ino as a starting point with a few mods. So far I am unable to access any of the fix data in my sketch. I started by trying to simply print latitude to the debug serial port after trace_all does it’s thing in loop(). The printout from trace_all is good but my new line of code only prints out zero.

I tried a similar approach with modifications to NMEA.ino and in that sketch I am able access the fix data and print it as I desire. But I really want to use the interrupt.

Here is what I did to NMEA_isr.ino to try and make this work:
I added one line after static NMEAGPS gps; as follows:

static NMEAGPS   gps; 
	static gps_fix  fix_data;

and in loop() I added 2 lines after trace_all as follows:

trace_all( DEBUG_PORT, gps, gps.read() );
    	fix_data = gps.read();
    	DEBUG_PORT.println(fix_data.latitudeL());

I obviously don’t understand something fundamental here, but if someone can point me in the right direction on this I would sure appreciate it.

Here is the modified NMEA_isr.ino

#include <Arduino.h>
#include "NMEAGPS.h"

//======================================================================
//  Program: NMEA_isr1.ino
//
//  Prerequisites:
//     1) NMEA.ino works with your device
//
//  Description:  This minimal program parses the GPS data during the 
//     RX character interrupt.  The ISR passes the character to
//     the GPS object for parsing.  The GPS object will add gps_fix 
//     structures to a buffer that can be later read() by loop().
//======================================================================

#if defined( UBRR1H )
  // Default is to use NeoSerial1 when available.  You could also
  #include <NeoHWSerial.h>
  // NOTE: There is an issue with IDEs before 1.6.6.  The above include 
  // must be commented out for non-Mega boards, even though it is
  // conditionally included.  If you are using an earlier IDEs, 
  // comment the above include.
#else  
  // Only one serial port is available, uncomment one of the following:
  //#include <NeoICSerial.h>
  #include <NeoSWSerial.h>
  //#include <SoftwareSerial.h> /* NOT RECOMMENDED */
#endif
#define RX_PIN 2
#define TX_PIN 3
#include "GPSport.h"

#include "Streamers.h"
#ifdef NeoHWSerial_h
  #define DEBUG_PORT NeoSerial
#else
  #define DEBUG_PORT Serial
#endif

// Check configuration

#ifndef NMEAGPS_INTERRUPT_PROCESSING
  #error You must define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
#endif

static NMEAGPS   gps;
static gps_fix  fix_data;


//--------------------------

static void GPSisr( uint8_t c )
{
  gps.handle( c );

} // GPSisr

//--------------------------

void setup()
{
  // Start the normal trace output
  DEBUG_PORT.begin(9600);
  while (!DEBUG_PORT)
    ;

  DEBUG_PORT.print( F("NMEA_isr1.INO: started\n") );
  DEBUG_PORT.print( F("fix object size = ") );
  DEBUG_PORT.println( sizeof(gps.fix()) );
  DEBUG_PORT.print( F("NMEAGPS object size = ") );
  DEBUG_PORT.println( sizeof(gps) );
  DEBUG_PORT.println( F("Looking for GPS device on " USING_GPS_PORT) );

  trace_header( DEBUG_PORT );

  DEBUG_PORT.flush();

  // Start the UART for the GPS device
  gps_port.attachInterrupt( GPSisr );
  gps_port.begin( 9600 );
}

//--------------------------

void loop()
{

  while (gps.available()) {
    // Print all the things!
    trace_all( DEBUG_PORT, gps, gps.read() );
    fix_data = gps.read();
    DEBUG_PORT.println(fix_data.latitudeL());
 
  }

  if (gps.overrun()) {
    gps.overrun( false );
    DEBUG_PORT.println( F("DATA OVERRUN: took too long to use gps.read() data!") );

  }
}

if someone can point me in the right direction on this I would sure appreciate it.

Yep, you are calling read twice:

       trace_all( DEBUG_PORT, gps, gps.read() );
     fix_data = gps.read();

The first read pulls the latest fix out of the queue and prints the data. The second read gets an empy fix. Instead, do this:

    fix_data = gps.read();
        trace_all( DEBUG_PORT, gps, fix_data );

Just like with Serial, you can only read what's there. :wink:

Cheers,
/dev

That fixed it. Thanks for your help /dev and thanks for NeoGPS. I am struggling because I have zero experience with C++, but I am way ahead of where I was before I discovered your library. No more checksum errors and questionable fix data!!