I need help capturing GPS data using NewSoftSerial.

Hi everyone,

I've tried every GPS tutorial out there and I haven't had any success yet. I get recognizable NMEA strings when I take out the ATMega chip and read the GPS data right into the serial monitor, but that's about it. What I'm shooting for is showing the latitude and longitude in the serial monitor after I've processed it in my code. I'm using an Uno.

When I run my code (with the chip in the Uno) this is what I get in the serial monitor:

Acquired Data

Lat/Long(10^-5 deg): 999999999, 999999999Lat/Long(float): 10000.00000, 10000.00000 Course(10^-2 deg): 999999999 Course(float): 10000000.00
(mph): 11507795.00 failed checksum: 0

Any ideas?

//Created October 14 2011
//Joshua Staker
//Referenced from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166042147/
//GPS reader Alternative Version (2)

#include <TinyGPS.h>
#include <NewSoftSerial.h>

#define rxGPSpin 2
#define txGPSpin 3

TinyGPS gps;
NewSoftSerial GPSSerial(rxGPSpin, txGPSpin, true); // sets up the pins for the GPS software serial


void gpsdump(TinyGPS &gps); //I'm not sure what these next three lines do, it was part of the TinyGPS example (try commenting them out after I've verified the code)
bool feedgps();
void printFloat(double f, int digits = 2);


int transistorBaseP = 13;                 // transistor base terminal connected to digital pin 13
int transistorBaseD = 11;  // transistor base of down button to digital pin 11
// int inPin = 12;   // xbee input connected to digital pin 12 (change this when I know how bee is interfaced)
// int analogValue5, val5;
int MAC = 0; // this is the address of the node to be communicated with
// NMEA gps(GPRMC); // initializes the GPS data connection (I'm avoiding this library)

void setup()
{
  Serial.begin(9600); // enables serial port. I may need to change this value to get everything to communicate at the proper rate
  pinMode(transistorBaseP, OUTPUT);      // sets the digital pin as output
  pinMode(transistorBaseD, OUTPUT);
  // pinMode(inPin, INPUT);      // sets the digital pin 12 as input
  pinMode(rxGPSpin, INPUT);
  pinMode(txGPSpin, OUTPUT);
  GPSSerial.begin(4800); // sets the software serial data rate
  Serial.print("Setup Complete");
 
}

void loop()
{
  
  // Every 5 seconds we print an update
  delay(4000);
  
    Serial.println("Acquired Data");
    Serial.println("-------------");
    gpsdump(gps);
    Serial.println("-------------");
    Serial.println();
 
}

void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
  
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print("."); 

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint; 
  } 
}


void gpsdump(TinyGPS &gps)
{
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  unsigned short sentences, failed;

  gps.get_position(&lat, &lon, &age);
  Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon); 
  
  
  
  feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors

  gps.f_get_position(&flat, &flon, &age);
  Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);

  feedgps();

  Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course());
  Serial.print(" Course(float): "); printFloat(gps.f_course()); Serial.println();
  Serial.print(" (mph): ");  printFloat(gps.f_speed_mph());

 feedgps();

  gps.stats(&chars, &sentences, &failed);
  Serial.print(" failed checksum: "); Serial.println(failed);
  
}

bool feedgps()
{
  while (GPSSerial.available())
  {
    if (gps.encode(GPSSerial.read()))
      return true;
  }
  return false;
}

I cleaned up the code a little by removing items not pertenent to my question. Any help would be great....

#include <TinyGPS.h>
#include <NewSoftSerial.h>

#define rxGPSpin 2
#define txGPSpin 3

TinyGPS gps;
NewSoftSerial GPSSerial(rxGPSpin, txGPSpin, true);


void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);


void setup()
{
  Serial.begin(9600);
  pinMode(rxGPSpin, INPUT);
  pinMode(txGPSpin, OUTPUT);
  GPSSerial.begin(4800); // sets the software serial data rate
  Serial.print("Setup Complete");
}

void loop()
{
  delay(4000);
   gpsdump(gps);
}

void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;
  
  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
    Serial.print("."); 

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    Serial.print(toPrint);
    remainder -= toPrint; 
  } 
}


void gpsdump(TinyGPS &gps)
{
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  unsigned short sentences, failed;

  gps.get_position(&lat, &lon, &age);
  Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon); 
  
 
  feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors

  gps.f_get_position(&flat, &flon, &age);
  Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);

  feedgps();

  Serial.print(" Course(10^-2 deg): "); Serial.print(gps.course());
  Serial.print(" Course(float): "); printFloat(gps.f_course()); Serial.println();
  Serial.print(" (mph): ");  printFloat(gps.f_speed_mph());

 feedgps();

  gps.stats(&chars, &sentences, &failed);
  Serial.print(" failed checksum: "); Serial.println(failed);
  
}

bool feedgps()
{
  while (GPSSerial.available())
  {
    if (gps.encode(GPSSerial.read()))
      return true;
  }
  return false;
}
  pinMode(rxGPSpin, INPUT);
  pinMode(txGPSpin, OUTPUT);

You told the NewSoftSerial object that these were it's pins. Why are you messing with them?

I get recognizable NMEA strings when I take out the ATMega chip and read the GPS data right into the serial monitor

Without the chip, the data is not being inverted. With the sketch running,

NewSoftSerial GPSSerial(rxGPSpin, txGPSpin, true);

says to invert it.

Why?