#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPSPlus object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
float average = 0;
float Alpha = 0.3;
float speed;
long start = 0;
void setup()
{
Serial.begin(9600);
ss.begin(GPSBaud);
lcd.init();
lcd.backlight();
}
void loop()
{
speed = gps.speed.kmph();
average = average * (1-Alpha) + speed * Alpha;
Serial.print(average);
if (millis()-start>=1000){
lcd.setCursor(0,0);
Serial.print(" -------- Dis: ");
Serial.print(average);
Serial.print("--------");
lcd.print(average);
start = millis();
}
Serial.println("");
smartDelay(100);
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
}
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}
when trying this code outside, when i start walking it takes 5 seconds to display a speed of 2-3 ish kmph instead of .3-5. It is a neo6mv2 gps, and i set it to 5hz in the u center application because i need that accuracy for the project i am working on. Does anybody know why it takes so long? Note, the serial also writes 9 ish messages per second.
The speed is determined from distance between successive locations divided by time, and is not very accurate if walking. The sensor probably uses smoothing or averaging over a period of several seconds to produce reasonably stable estimates.
ohh, idk why i thought it used the dopler effect to measure speed, so that why i thought it would be a real time speed. do you know i can make it use the doppler effect or am i just wrong in that regard
Doppler also has issues with accuracy, depending on conditions. It can also experience large jumps, so is filtered to get a smooth average. I would expect low end units could use both location delta and doppler to derive a speed, but that does not mean all low end units do.
The bottom line is that neither GPS location nor speed is as accurate as people think it might be.
Honestly I have no idea. There is not much research on the subject; there are not many applications were people need to accurately measure walking speed.