srnet:
Using the first fix as the location is not a good idea, you likley need to wait a good minute or more for the location to stabilise. And then detecting a movement of as little as 3.3m might be ambitious. Variations of 3-10m in position are not unusual for a stationary GPS.
Also depends where the GPS actually is, what is the application ?
I am trying to write an application for marine use
I want to save the first good fix and then compare the saved coords to the current coords the gps has.
please see my latest code
I know its wrong
but I dont know how to fix it.
#include <TinyGPS++.h> // Include the TinyGPS++ library
TinyGPSPlus gps; // Create a TinyGPSPlus object
#define GPS_BAUD 9600 // GPS module baud rate
#define ARDUINO_GPS_RX 14 // GPS TX, Arduino RX pin
#define ARDUINO_GPS_TX 13 // GPS RX, Arduino TX pin
// Define the serial monitor port. On the Uno, and Leonardo this is 'Serial'
// on other boards this may be 'SerialUSB'
#define SerialMonitor Serial
double GPSlock()
{
float initialLat;
float initialLng;
while (Serial1.available() > 0) {
gps.encode(Serial1.read());
}
if ( gps.satellites.value() >= 1 && gps.hdop.hdop() <= 6 && gps.sentencesWithFix() > 1) {
float initialLat = gps.location.lat();
float initialLng = gps.location.lng();
SerialMonitor.print("initialLat: ");
Serial.println(initialLat, 6);
SerialMonitor.print("initialLng: ");
Serial.println(initialLng, 6);
}
return initialLat; initialLng;
}
void setup() {
SerialMonitor.begin(9600);
Serial1.begin(GPS_BAUD);
}
void loop() {
Serial.println(GPSlock());
delay(1000);
}
A function can return only one value. The statement after the first semicolon does nothing.
return initialLat; initialLng;
If you make these two variables global (declare them outside of any function), then all parts of your program can access them.
float initialLat;
float initialLng;
You really need to brush up on (or learn) the basics of C/C++ programming. We strongly recommend to study the examples that come with the Arduino IDE, and relevant examples of the many on-line programming tutorials.
yantypas:
I am trying to write an application for marine use
I want to save the first good fix and then compare the saved coords to the current coords the gps has.
please see my latest code
I know its wrong
but I dont know how to fix it.
The code in post 13 did not give you a clue? Hummm, well I tried.
thank you very much for sharing you knowledge with me.
I am still trying to make it work but I fail. I cannot understand how you manage to save the fix on - lGPS_Lat0, lGPS_Lon0, tempLat, tempLon - separately!
I have been altering the code (I tried to use TinyGPSPlus::distanceBetween to calc the distance because I am interested in distances less than a meter (cm).
long scale=10000000UL;
long lat = gps.location.rawLat().deg*scale+gps.location.rawLat().billionths/100UL;
if(gps.location.rawLat().negative) lat=-lat;
long lon = gps.location.rawLng().deg*scale+gps.location.rawLng().billionths/100UL;
if(gps.location.rawLng().negative) lon=-lon;
If you are using a Uno/Mega (8/16 bit) you will lose precision.
yantypas:
I have been altering the code (I tried to use TinyGPSPlus::distanceBetween to calc the distance because I am interested in distances less than a meter (cm).
GPS isn't that accurate. On a good day, you can get a position within three meters, but it may be substantially worse. Try leaving your GPS in place and have it spit out its position. Usually the position drifts gently and occasionally leaps multiple meters away. Trying to do anything with centimeters is going to be impractical.
Differential GPS will do better, but I suspect even that would not give you the accuracy you're looking for.
wildbill:
GPS isn't that accurate. On a good day, you can get a position within three meters, but it may be substantially worse.
I frequently test GPSs in my garden, 3m is indeed good and a 10m variation is not that unusual.
If there was a cunning wheeze way of using code (with non differential GPSs) to improve on that much, you would assume everyone would be doing it and\or the code would be built into the GPS .......................
It's super accurate if you're using RTK - i.e. you need a base station transmitting position corrections. Without it, Sparkfun's version boasts 2.5m accuracy, which is probably best case.
your templat and templong are your last position. If your last position is zero and your current position is something, then you've traveled a great distance.
thank you againg for taking the time to help me!
Really really appreciate your messages. I know very little about coding and arduino and you helped me a lot!
I think this works.. Im nit sure because my breadboard/wires dont work well and I have ti fix them by hand in order to get values. But I managed to set BASE coords (tempLat & tempLong) at some point..
Please see below:
(I think its the right version of code)