'Guide' me please ;) GPS+WaveShield

Hello,

I’m working on a new project. It’s for a geocache (for those who don’t know what that is seehttp://www.geocaching.com

I want to create an ‘audiotour’ with storytelling on specific GPS coordinates.
In the example is what I have so far and it is working. (see at the bottom of the page)

The only thing i’m concerned about is data loss a a battery disconnect or empty battery if they’re half way.
(They need to bring their own 9V battery)

As shown here, the sketch keeps track if a certain waypoint (specific GPS coordinate) is reached. And it is stored in an ‘int’
At the end all waypoints are checked if they were al reached.

//WayPoint info
int reachedWP1=false;
int reachedWP2=false;
int reachedWP3=false;
//Check if WP is reached------------------------------------
   if (distanceToWP1 <= radius && reachedWP1==false && reachedWP2==false && reachedWP3==false){
    reachedWP1=true;
    playcomplete("RE.WAV");
  }
   else{
   }
    
   if (distanceToWP2 <= radius && reachedWP1==true && reachedWP2==false && reachedWP3==false){
    reachedWP2=true;
    playcomplete("MI.WAV");
   } 
   
   if (distanceToWP3 <= radius && reachedWP1==true && reachedWP2==true && reachedWP3==false){
    reachedWP3=true;
    playcomplete("LA.WAV");
   }

But it is reset if the battery is disconnected.
Is there way to store those vallues? But at the end it should be reseted for the next player.
The EEPROM has a limited lifetime, but could I also use theSD card of theWaveShield?
And if so, how should I do this?

I hope someone could get me out… Thanks.
(Oh, and sorry for the messy coding… still trying things out)

First half of thecode: (sorry it’s long…)

//GPS
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
//WaveShield
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
//WaveShield
SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time
/*
   This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   9600-baud serial GPS device hooked up on pins 9(rx) and 8(tx).
*/
static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

//WayPoint info
int reachedWP1=false;
int reachedWP2=false;
int reachedWP3=false;
int radius=10; //Radius to point zero of the coordinate.
//WayPoint Coordinates
static const double WP1_LAT = 51.933397, WP1_LON = 5.147241;
static const double WP2_LAT = 51.933159, WP2_LON = 5.147750;
static const double WP3_LAT = 51.933543, WP3_LON = 5.147471;

void setup()
{
  
  Serial.begin(9600);
  ss.begin(GPSBaud);
  
  //WaveShield Pinouts:
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  //WaveShield Setup:
  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  //if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
  playcomplete("8.WAV");
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");

  Serial.println(F("SpiderWick Geocache"));
  Serial.println(F("Davy Uittenbogerd 2014"));
  Serial.print(F("TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println();
  Serial.println(F("Latitude   Longitude   Course Speed Card  Distance Course Card  Distance Course Card  Distance Course Card    Reached WP?  "));
  Serial.println(F("(deg)      (deg)       --- from GPS ----  ------ to WP1 ------  ------ to WP2 ------  ------ to WP3 ------  -WP1--WP2--WP--"));
  Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop(){
     
  // printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  //printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  //printInt(gps.location.age(), gps.location.isValid(), 5);
  //printDateTime(gps.date, gps.time);
  //printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);

//WayPoint1----------------------------------

  unsigned long distanceToWP1 =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      WP1_LAT, 
      WP1_LON);
  printInt(distanceToWP1, gps.location.isValid(), 9);

  double courseToWP1 =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      WP1_LAT, 
      WP1_LON);

  printFloat(courseToWP1, gps.location.isValid(), 7, 2);

  const char *cardinalToWP1 = TinyGPSPlus::cardinal(courseToWP1);

  printStr(gps.location.isValid() ? cardinalToWP1 : "*** ", 6);


  //WayPoint2------------------------------------
  
  unsigned long distanceToWP2 =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      WP2_LAT, 
      WP2_LON);
  printInt(distanceToWP2, gps.location.isValid(), 9);

  double courseToWP2 =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      WP2_LAT, 
      WP2_LON);

  printFloat(courseToWP2, gps.location.isValid(), 7, 2);

  const char *cardinalToWP2 = TinyGPSPlus::cardinal(courseToWP2);

  printStr(gps.location.isValid() ? cardinalToWP2 : "*** ", 6);

  
  //WayPoint3------------------------------------
  
  unsigned long distanceToWP3 =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      WP3_LAT, 
      WP3_LON);
  printInt(distanceToWP3, gps.location.isValid(), 9);

  double courseToWP3 =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      WP3_LAT, 
      WP3_LON);

  printFloat(courseToWP3, gps.location.isValid(), 7, 2);

  const char *cardinalToWP3 = TinyGPSPlus::cardinal(courseToWP3);

  printStr(gps.location.isValid() ? cardinalToWP3 : "*** ", 6);
//  Serial.println();

Second half of thecode:

//Check if WP is reached------------------------------------
   if (distanceToWP1 <= radius && reachedWP1==false && reachedWP2==false && reachedWP3==false){
    reachedWP1=true;
    playcomplete("RE.WAV");
  }
   else{
   }
    
   if (distanceToWP2 <= radius && reachedWP1==true && reachedWP2==false && reachedWP3==false){
    reachedWP2=true;
    playcomplete("MI.WAV");
   } 
   
   if (distanceToWP3 <= radius && reachedWP1==true && reachedWP2==true && reachedWP3==false){
    reachedWP3=true;
    playcomplete("LA.WAV");
   }
   
//Print out for debugging:
    Serial.print (reachedWP1);
    Serial.print ("     ");
    Serial.print (reachedWP2);
    Serial.print ("     ");
    Serial.print (reachedWP3);
    Serial.println();
  
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}



//WAVESHIELD

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
//int freeRam(void)
//{
//  extern int  __bss_end; 
//  extern int  *__brkval; 
//  int free_memory; 
//  if((int)__brkval == 0) {
//    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
//  }
//  else {
//    free_memory = ((int)&free_memory) - ((int)__brkval); 
//  }
//  return free_memory; 
//} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}


// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying) {
  // do nothing while its playing
  }
ss.begin(GPSBaud);
}

void playfile(char *name) {
  ss.end();
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  }
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file "); Serial.print(name); return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV"); return;
  }
  
  // ok time to play! start playback
  wave.play();
}

Anyone?