I am trying to create simple bike speedo with trip meter that uses GPS.
I have problem though with distance calculating
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 8, TXPin = 7;
static const uint32_t GPSBaud = 9600;
double lastLat;
double lastLng;
double tripT = 000.0;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop()
{
while (ss.available() > 0)
if (gps.encode(ss.read())){
storeCurrentLoc();
delay(1000);
displayTrip();
}
void displayTrip(){
double tripA =
TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
lastLat,
lastLng) / 1000;
tripT = tripT + tripA;
Serial.print("Trip:");
Serial.print(" ");
Serial.println(tripT);
}
void storeCurrentLoc(){
lastLat = gps.location.lat();
lastLng = gps.location.lng();
}
Unfortunately no matter how fast and how I go the trip shows always 0.
Speed, Time, long and lat etc is displayed correctly, speed rises and slows, lat and long changes with the location but Trip is always 0.
Is it because 1s is to small of a time for it to change?