Unable to Get a lock with GPS unit

Hi everyone,

I’m working on creating a reverse geocaching puzzle box like the one seen here ( arduiniana (dot) org /projects/the-reverse-geo-cache-puzzle/) for my girlfriend as part of a Christmas present. I have an Arduino Uno hooked up to my GPS unit ( sparkfun (dot) com /products/465) via the NewSoftSerial and TinyGPS libraries. I seem to be unable to get any sort of lock on after trying the GPS in different locations (right now it’s sitting on my windowsill). If I just run a NewSoftSerialTest I get back the following:

$GPRMC,141458.099,V,,,,,,,021106,,*26
$GPGGA,141459.095,,,,,0,00,,,M,0.0,M,,0000*56
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,141459.095,V,,,,,,,021106,,*2B
$GPGGA,141500.097,,,,,0,00,,,M,0.0,M,,0000*59
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,141500.097,V,,,,,,,021106,,*24
$GPGGA,141501.101,,,,,0,00,,,M,0.0,M,,0000*56
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,12,20,00,000,,10,00,000,,31,00,000,,27,00,000,*7C
$GPGSV,3,2,12,19,00,000,,07,00,000,,04,00,000,,24,00,000,*76
$GPGSV,3,3,12,16,00,000,,28,00,000,,26,00,000,,29,00,000,*78
$GPRMC,141501.101,V,,,,,,,021106,,*2B
$GPGGA,141502.095,,,,,0,00,,,M,0.0,M,,0000*59
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,141502.095,V,,,,,,,021106,,*24
$GPGGA,141503.095,,,,,0,00,,,M,0.0,M,,0000*58
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,141503.095,V,,,,,,,021106,,*25
$GPGGA,141504.101,,,,,0,00,,,M,0.0,M,,0000*53
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,141504.101,V,,,,,,,021106,,*2E
$GPGGA,141505.097,,,,,0,00,,,M,0.0,M,,0000*5C
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPRMC,141505.097,V,,,,,,,021106,,*21
$GPGGA,141506.097,,,,,0,00,,,M,0.0,M,,0000*5F
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,3,1,12,20,00,000,,10,00,000,,31,00,000,,27,00,000,*7C
$GPGSV,3,2,12,19,00,000,,07,00,000,,04,00,000,,24,00,000,*76
$GPGSV,3,3,12,16,00,000,,28,00,000,,26,00,000,,29,00,000,*78

My test code for the TinyGPS library is as follows:

TinyGPS gps;
//NewSoftSerial nss(2, 3)
NewSoftSerial nss(9, 8);

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

void setup()
{
  Serial.begin(115200);
  nss.begin(4800);
  
  Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS));
  Serial.println();
}

void loop()
{
  
  bool newdata = false;
  unsigned long start = millis();
  
  Serial.println("Looping...");
  
  // Every 5 seconds we print an update
  while (millis() - start < 5000)
  {
    if (feedgps())
    {
      newdata = true;
    }
    delay(1000);
  }
  Serial.println("Checking for newData");
  if (newdata)
  {
    Serial.println("Acquired Data");
    Serial.println("-------------");
    gpsdump(gps);
    Serial.println("-------------");
    Serial.println();
  }
  else
  {
    Serial.println("No new data");
  }
}

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

It never even gets to gpsdump() which is why I didn’t include that bit of code (it’s also the same code that is in test_with_gps_device.pde).

I’ve let it run for about 20 minutes now and I still have no lock. I know my rx/tx ports define in my NewSoftSerial are correct, so that is not the issue.

Any ideas? Please help!

PS. Sorry about breaking up the URL links. Since this is my first post it wouldn't let me include them.

Can you take the GPS outside? With a full sky view mine usually locks within a minute or two.

I took it outside today and using NewSoftSerial I could see it locking on in about 10 seconds. If I use the TinyGPS example, feedgps() returns false constantly and never updates. Though, if I bypass the if( feedgps() ) statement I'm able to print out valid data after about 10 seconds. Maybe I should just check for valid data a different way....?

Good evening!

I'm glad to see you're building a puzzle box. That should prove fun!

What I think you should try first is removing that delay(1000) from the loop. Whenever you add delay()s to looping code structures like this, you risking losing asynchronous data. Think about how many characters arrive from the GPS in the space of that 1 second. At 4800 baud that's perhaps as many as 480 characters, and since the NewSoftSerial buffer can only hold 64, you are losing more than 1/2 of the data from the GPS.

It's not that the GPS is not getting a lock; it's just that TinyGPS is not able to calculate a valid position from the incomplete data that it sees. TinyGPS discards any incomplete NMEA sentences or sentences whose checksum is wrong, and I'm guessing that all of yours are.

Good luck, and please let us know how the gift works out. (I collect puzzle box stories; there are some great ones out there.)

Mikal

Mikal,

Thank you so much for that advice! I did what you said and everything is working great! Sorry it has taken so long for me to reply, but it's been taking some time to get the physical aspect of the box put together. Coding/Arduino stuff is complete, now I just need to perfect the locking mechanism. Thanks so much for your help and the libraries you provide!

When I finish it I will post pictures and show off my horrible soldering job :-P

-Joe