i have just tried another sketch as per below and it generates a serial2 error
i am spending days search the web trying supposed solutions and none of them work each having one error on another its totally frustrating when i am following the steps exactly
I want to be able to store geo fence co ordinates on the arduino so that as the unit detects entering one of the geo fences then the unit alerts via light flash or sound
sadly despite my tenacity i am getting no where fast
the sketch is as follows
#include <Arduino.h>
#include “NMEAGPS.h”
NMEAGPS gps;
gps_fix fix; // the current GPS fix
HardwareSerial & gps_port = Serial2; // an alias
NeoGPS::Location_t home( 254139360L, 682662360L ); // degrees * 10,000,000
const float thresholdDistance = 1.00; //km
uint8_t gpsSeconds; // for counting elapsed time instead of using delay
void setup()
{
Serial.begin(9600);
Serial.println(“Hello!”);
gps_port.begin(9600);
} // setup
void loop()
{
while (gps.available( gps_port )) {
fix = gps.read(); // save the latest
// Instead of delay, count the number of GPS fixes
gpsSeconds++;
if (gpsSeconds >= 3) {
gpsSeconds = 0;
displayInfo();
checkDist();
}
}
} // loop
void displayInfo()
{
Serial.print("Position: ");
if (fix.valid.location) {
Serial.print("lat: “); Serial.print(fix.latitude(), 6); Serial.print(” ");// print latitude
Serial.print("lon: "); Serial.println(fix.longitude(), 6); // print longitude
} else
Serial.println( ‘?’ );
} //end displayInfo()
void checkDist()
{
if (fix.valid.location) {
float dist = fix.location.DistanceKm( home );
if (dist >= thresholdDistance )
{
Serial.print("Subject is ");
Serial.print(dist - thresholdDistance, 6);
Serial.println("KM beyond threshold");
}
else
{
Serial.println("Subject within threshold, no worries!");
}
}
}