Reverse Geocache code problems.

I am mostly a hardware guy so this software stuff is difficult for me. I am learning but it is slow. I suspect I am missing something obvious. Any help would be greatly appreciated.

I am working on building a reverse geocache box.
I found this coded example which I modified to use my LCD screen. I have been working with it with minor success but I have run into a few problems.

here is the code. I am using Arduino 18 with the servo library from Arduino 16.

I have highlighted 2 parts of the code. The first part is where the program is searching for a gps signal. My understanding is that it should say “Seeking signal” for 5 min then display no signal and shutdown unless it finds a signal.

what the program does for me is flash seeking signal then no signal every few seconds until it finds a signal and moves on to the next part of the code. I don’t have a polou switch yet so it wont shut down but I suspect it would if I had one connected.

What can I do to fix that chunk of code so it works as it is supposed to.

The second chunk of code that is highlighted prevents the code from being compiled so i have it commented out. Any ideas as to what is wrong with it or if it is even needed?

/*
Code written by Allen Burt - youevolve@buidsomething.net

Original build and concept and the TinyGPS and NewsoftSerial libraries – Mikal Hart – arduiniana.org
Also thanks to Mikal for guiding me out of a corner I had painted myself into.

Thank you, also, to the arduino community for all the code examples which have guided me.

Huge thank you to my wife for loving geeks and putting up with my new obsession.

———————————-

Due to a conflict with NewSoftSerial(actually, all Serial libraries) and the Arduino 017
Servo library you MUST use either Arduino 016 (or earlier) OR copy the Servo library from
an earlier version to the Arduino 017 Libraries folder. If you experience random movement
of the servo, this bug is the issue.

This code assumes that you have a 4800-baud serial GPS device hooked up on pins 2(rx)
and 3(tx) and a serial LCD display on pin 1 using kit LCD117b from Modern Device Company

New installations must have the EEPROM cleared.

Use this code to clear the EEPROM registers on fresh installs and new puzzle sessions.
EEPROMCLEAR code:

#include <EEPROM.h>

void setup()
{
// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i < 512; i++)
EEPROM.write(i, 0);

// turn the LED on when we're done
digitalWrite(13, HIGH);
}

void loop()
{
}

*
*/
#include <NewSoftSerial.h>
#include <TinyGPS.h>
#include <EEPROM.h>
#include <Servo.h>

// Initiates a function command to the display
void serCommand() {
  Serial.print(0xFE, BYTE);
}
// Resets the display, undoing any scroll and removing all text
void clearLCD() {
   serCommand();
   Serial.print(0x01, BYTE);
}
// Starts the cursor at the beginning of the first line (convienence method for goTo(0))
void selectLineOne() {  //puts the cursor at line 0 char 0.
   serCommand();   //command flag
   Serial.print(128, BYTE);    //position
}

// Starts the cursor at the beginning of the second line (convienence method for goTo(16))
void selectLineTwo() {  //puts the cursor at line 0 char 0.
   serCommand();   //command flag
   Serial.print(192, BYTE);    //position
}


Servo myservo; // create servo object to control a servo
TinyGPS gps;
NewSoftSerial nss(2, 3);
float gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);
int address = 0; //address of EEPROM byte we will be writing to
byte value; // number of program cycles
int offPin = 8; // Pololu off line connected to digital pin 8;
int newvalue; //placeholder for incrementing program cycles
float dest_latitude = 41; // latitude
float dest_longitude = -88; // longitude
float radius = 3956.6;
const float two = 2.0;
unsigned long timer = 0;


void setup()

{
  
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(offPin, OUTPUT); // sets the digital pin connected to the Pololu as output
value = EEPROM.read(address); // read a byte from the current address of the EEPROM

Serial.begin(9600); //Display runs at 9600 baud
nss.begin(4800); // GPS runs at 4800 baud

delay (3000); //wait a few seconds for the screen to boot up
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print("   Welcome to"); 
delay(10);
selectLineTwo(); // cursor to first character of line 1
delay(10);
Serial.print("   the Game...");
delay(4000);
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print( "    ");
Serial.print(value, DEC); //print the stored attempt counter
delay (10);
Serial.print( " of 50");
delay (10);
selectLineTwo(); // cursor to first character of line 1
delay(10);
Serial.print("    Attempts");
delay(5000);

myservo.write(90); // make sure the servo is in the locked position
newvalue = ++value; //add one to the program cycle counter
EEPROM.write(address, newvalue); //write the new value to EEPROM

if (value >= 51) //if we have used up all our turns, print message and shut down
{
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print("Game Over");
delay(15000); // wait for 15 seconds
digitalWrite(offPin, HIGH); // Sends the signal to the Pololu switch to turn off the arduino
}
}

[glow]void loop()
{
bool newdata = false;
{
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print("Seeking Signal");
delay(10);

do //keep feeding the GPS and counting the time until we get a lock or run out of time
{
feedgps();
if (feedgps()){
newdata = true;
}
timer = millis();
delay(1000);

}
while ((newdata = false) && (timer < 300000)); //Look for a signal for 5 minutes if (timer >= 300000){ // if no signal in 5 minutes, power down
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print("No Signal");
delay(5000);
digitalWrite(offPin, HIGH); // Sends the signal to the Pololu switch to turn off the arduino
}[/glow]

if (feedgps()){
newdata = true;
}
if (newdata) // if we get data, print the distance to target
{
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print("Distance");
delay(10);
selectLineTwo(); // cursor to first character of line 1
delay(10);

Serial.print(gpsdump(gps));
Serial.print(" Miles");

if (gpsdump(gps) <= 1.00) { //set this to the desired distance to target unlock “zone.”
// Remember, you may have poor signal and get some drift in your location.


clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
delay(10);
Serial.print("    Success!");
delay(1000);
myservo.write(160);
delay(1000);
myservo.write(90);
clearLCD(); // clear the LCD
delay(10);
selectLineOne(); // cursor to first character of line 0
Serial.print("    Lock  #1");
delay(10);
selectLineTwo(); // cursor to first character of line 1
Serial.print("   Disengaged");
delay(1000);
myservo.write(0);
delay(1000);
myservo.write(90);
clearLCD(); // clear the LCD
selectLineOne(); // cursor to first character of line 0
Serial.print("    Lock  #2");
selectLineTwo(); // cursor to first character of line 1
Serial.print("   Disengaged");
delay(1000);

clearLCD(); // clear the LCD
selectLineOne(); // cursor to first character of line 0
Serial.print(" The box is now");
selectLineTwo(); // cursor to first character of line 1
Serial.print("    unlocked");
delay(15000); // wait 15 seconds
digitalWrite(offPin, HIGH); // Sends the signal to the Pololu switch to turn off the arduino
}
else {
delay(60000); // wait for 1 minute
digitalWrite(offPin, HIGH); // Sends the signal to the Pololu switch to turn off the arduino
}
}
}

void printFloat(double number, int digits) //this void sequence from the TinyGPS library

{
// Handle negative numbers
if (number < 0.0)
{
Serial.print("-");
number = -number;
}

[glow]// Round correctly so that print(1.999, 2) prints as “2.00[ch8243]
//double rounding = 0.5;
//for (uint8_t i=0; i 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;[/glow]
}


float gpsdump(TinyGPS &gps)

{

float flat, flon, d;
unsigned long age, date, time, chars; //look at using date and time as well for unlock conditions!

feedgps();

gps.f_get_position(&flat, &flon, &age); // look at using the age of the data to confirm how good the signal lock is.

/*
Thanks to arduino forum member Alligator for this version of the Haversine formula for distance calculation
*/

float delta_lat = radians(dest_latitude - flat);
float delta_lon = radians(dest_longitude - flon);
float a = square(sin(delta_lat/two)) + cos(radians (flat)) * cos(radians (dest_latitude)) * square(sin(delta_lon/two));
float c = two * asin(sqrt(a));
d = radius * c;
return d;

}

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

I couldn’t check it compiled, but it looks like you’ve got a spurious opening parenthesis on line 143 which is most likely what’s stopping the second piece of highlighted code compiling. On line 161 it looks like a line break has gone missing and the if statement that checks the 5 minutes has passed has been commented out.

while ((newdata = false) && (timer < 300000)); //Look for a signal for 5 minutes if (timer >= 300000){ // if no signal in 5 minutes, power down

should become

while ((newdata = false) && (timer < 300000)); //Look for a signal for 5 minutes 
if (timer >= 300000){ // if no signal in 5 minutes, power down

I got the first part of the code to work correctly thank you!
The second part still compiles with an error

“error: expected `;’ before numeric constant”
It highlights the following line.

// Round correctly so that print(1.999, 2) prints as “2.00[ch8243]
double rounding = 0.5;
for (uint8_t i=0; i 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;

for (uint8_t i=0; i [glow]some test[/glow] 0; [glow]possibly do something to "i" here[/glow])