Reverse Geocache Box coding problem - PLEASE HELP

I made a Reverse Geocache Box based off of Mikal Hart’s design (http://archive.makezine.com/25/puzzlebox/) for an electronics course. I also based my design off of Tyler Cooper’s Adafruit guide (http://learn.adafruit.com/reverse-geocache-engagement-box/overview) since we both use an Adafruit Ultimate GPS receiver. One major difference in my design is that I’m using an ATMega328P microcontroller and an FTDI basic breakout to upload sketches.

I’m having an issue serially transmitting the GPS data from the GPS reciever to the TinyGPS library that processes the data to calculate the distance that the box is from its destination coordinates. It seems that the speed (baud rate?) of the serial data transmission on the “send” end is too slow, so the tinygps.encode() function doesn’t recognize any complete data sentences, which is required in order to determine the GPS receiver’s latitude and longitude. Attached is my code, I’ve changed the destination coordinates to the Empire State Building as an arbitrary location which can be used for testing. I would like the tinygps.encode() function to determine distance (in meters) between the box and its destination coordinates so this data can be displayed on the LCD for the user. Everything else inside the box such as the servo, the push button, sleep mode, etc. seems to work great.

Please help?

Also, I am still sort of a beginner at writing code/using Arduino so I’m open to any suggestions! Thank you.

ReverseGeocacheBoxForum.ino (9.22 KB)

This is dodgy:

void parse_gps()                                           // interpret GPS data if fix is found
{
  if (mySerial.available() > 0)
  {
    Serial.write(mySerial.read());                         // send raw GPS data to serial monitor    
    if (tinygps.encode(mySerial.read()))

Your initial read from my serial consumes a character from the GPS. That character never makes it to tinygps and worse, you’re mostly sending -1 to tinygps.

Try:

void parse_gps()                                           // interpret GPS data if fix is found
{
char ch;
  if (mySerial.available() > 0)
  {
  ch=mySerial.read()
    Serial.write(ch);                         // send raw GPS data to serial monitor
    
    if (tinygps.encode(ch))

Not compiled or tested.

Thank you very much! I will be testing this tomorrow and will come back if I have any other issues.

So I tested my revised code last night and it's still not completely working. I am able to obtain a GPS fix (the red LED on the GPS receiver stops flashing) and I can see the accurate GPS coordinate data in the serial monitor but my code seems to stop working at the tinygps.encode() function. The message on the LCD never changes from "Searching for GPS signal" and I'm not sure where to go from here.