Reverse Geocache code problems.


i hardware guy software stuff difficult me.  i learning slow.  i suspect missing obvious.  any appreciated.

i working on building reverse geocache box.
i found coded example modified use lcd screen.  i have been working with minor success have run few problems.

here code.  i  using arduino 18 servo library arduino 16.

i have highlighted 2 parts of code.  the first part program searching gps signal.  my understanding should "seeking signal" 5 min display no signal , shutdown unless finds signal.

what program me flash seeking signal no signal every few seconds until finds signal , moves on next part of code.  i don't have polou switch yet wont shut down suspect if had 1 connected.  

what can fix chunk of code works supposed to.

the second chunk of code highlighted prevents code being compiled have commented out.  any ideas wrong or if needed?


 

code: [select]
/*
code written allen burt - youevolve@buidsomething.net

original build , concept , tinygps , newsoftserial libraries - mikal hart - arduiniana.org
also mikal guiding me out of corner had painted myself into.

thank you, also, arduino community code examples have guided me.

huge thank wife loving geeks , putting new obsession.

-----------------------

due conflict newsoftserial(actually, serial libraries) , arduino 017
servo library must use either arduino 016 (or earlier) or copy servo library from
an earlier version arduino 017 libraries folder. if experience random movement
of servo, bug issue.

this code assumes have 4800-baud serial gps device hooked on pins 2(rx)
and 3(tx) , serial lcd display on pin 1 using kit lcd117b modern device company

new installations must have eeprom cleared.

use code clear eeprom registers on fresh installs , new puzzle sessions.
eepromclear code:

#include <eeprom.h>

void setup()
{
// write 0 512 bytes of eeprom
for (int = 0; < 512; i++)
eeprom.write(i, 0);

// turn led on when we're done
digitalwrite(13, high);
}

void loop()
{
}

*
*/
#include <newsoftserial.h>
#include <tinygps.h>
#include <eeprom.h>
#include <servo.h>

// initiates function command display
void sercommand() {
 serial.print(0xfe, byte);
}
// resets display, undoing scroll , removing text
void clearlcd() {
  sercommand();
  serial.print(0x01, byte);
}
// starts cursor @ beginning of first line (convienence method goto(0))
void selectlineone() {  //puts cursor @ line 0 char 0.
  sercommand();   //command flag
  serial.print(128, byte);    //position
}

// starts cursor @ beginning of second line (convienence method goto(16))
void selectlinetwo() {  //puts cursor @ line 0 char 0.
  sercommand();   //command flag
  serial.print(192, byte);    //position
}


servo myservo; // create servo object control 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 writing to
byte value; // number of program cycles
int offpin = 8; // pololu off line connected digital pin 8;
int newvalue; //placeholder incrementing program cycles
float dest_latitude = 41; // latitude
float dest_longitude = -88; // longitude
float radius = 3956.6;
const float 2 = 2.0;
unsigned long timer = 0;


void setup()

{
 
myservo.attach(9); // attaches servo on pin 9 servo object
pinmode(offpin, output); // sets digital pin connected pololu output
value = eeprom.read(address); // read byte current address of eeprom

serial.begin(9600); //display runs @ 9600 baud
nss.begin(4800); // gps runs @ 4800 baud

delay (3000); //wait few seconds screen boot up
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print("   welcome to");
delay(10);
selectlinetwo(); // cursor first character of line 1
delay(10);
serial.print("   game...");
delay(4000);
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print( "    ");
serial.print(value, dec); //print stored attempt counter
delay (10);
serial.print( " of 50");
delay (10);
selectlinetwo(); // cursor first character of line 1
delay(10);
serial.print("    attempts");
delay(5000);

myservo.write(90); // make sure servo in locked position
newvalue = ++value; //add 1 program cycle counter
eeprom.write(address, newvalue); //write new value eeprom

if (value >= 51) //if have used our turns, print message , shut down
{
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print("game over");
delay(15000); // wait 15 seconds
digitalwrite(offpin, high); // sends signal pololu switch turn off arduino
}
}

[glow]void loop()
{
bool newdata = false;
{
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print("seeking signal");
delay(10);

do //keep feeding gps , counting time until lock or run out of time
{
feedgps();
if (feedgps()){
newdata = true;
}
timer = millis();
delay(1000);

}
while ((newdata = false) && (timer < 300000)); //look signal 5 minutes if (timer >= 300000){ // if no signal in 5 minutes, power down
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print("no signal");
delay(5000);
digitalwrite(offpin, high); // sends signal pololu switch turn off arduino
}[/glow]

if (feedgps()){
newdata = true;
}
if (newdata) // if data, print distance target
{
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print("distance");
delay(10);
selectlinetwo(); // cursor first character of line 1
delay(10);

serial.print(gpsdump(gps));
serial.print(" miles");

if (gpsdump(gps) <= 1.00) { //set desired distance target unlock "zone."
// remember, may have poor signal , drift in location.


clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
delay(10);
serial.print("    success!");
delay(1000);
myservo.write(160);
delay(1000);
myservo.write(90);
clearlcd(); // clear lcd
delay(10);
selectlineone(); // cursor first character of line 0
serial.print("    lock  #1");
delay(10);
selectlinetwo(); // cursor first character of line 1
serial.print("   disengaged");
delay(1000);
myservo.write(0);
delay(1000);
myservo.write(90);
clearlcd(); // clear lcd
selectlineone(); // cursor first character of line 0
serial.print("    lock  #2");
selectlinetwo(); // cursor first character of line 1
serial.print("   disengaged");
delay(1000);

clearlcd(); // clear lcd
selectlineone(); // cursor first character of line 0
serial.print(" box now");
selectlinetwo(); // cursor first character of line 1
serial.print("    unlocked");
delay(15000); // wait 15 seconds
digitalwrite(offpin, high); // sends signal pololu switch turn off arduino
}
else {
delay(60000); // wait 1 minute
digitalwrite(offpin, high); // sends signal pololu switch turn off arduino
}
}
}

void printfloat(double number, int digits) //this void sequence tinygps library

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

[glow]// round correctly print(1.999, 2) prints "2.00[ch8243]
//double rounding = 0.5;
//for (uint8_t i=0; 0)
//serial.print(".");

// extract digits remainder 1 @ 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 @ using date , time unlock conditions!

feedgps();

gps.f_get_position(&flat, &flon, &age); // @ using age of data confirm how signal lock is.

/*
thanks arduino forum member alligator version of haversine formula distance calculation
*/

float delta_lat = radians(dest_latitude - flat);
float delta_lon = radians(dest_longitude - flon);
float = square(sin(delta_lat/two)) + cos(radians (flat)) * cos(radians (dest_latitude)) * square(sin(delta_lon/two));
float c = 2 * 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 compiled, looks you've got spurious opening parenthesis on line 143 what's stopping second piece of highlighted code compiling. on line 161 looks line break has gone missing , if statement checks 5 minutes has passed has been commented out.

code: [select]
while ((newdata = false) && (timer < 300000)); //look signal 5 minutes if (timer >= 300000){ // if no signal in 5 minutes, power down

should become

code: [select]
while ((newdata = false) && (timer < 300000)); //look signal 5 minutes
if (timer >= 300000){ // if no signal in 5 minutes, power down


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Reverse Geocache code problems.


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums