So im using GY-NEO6MV2 GPS Module and an Arduino UNO for my project. Im using TinyGPS++ library v. 0.92 to get data from the module. I can print the location data to serial monitor without a problem with the example skecth(FullExample). But im having trouble storing data to variables. If i try to store them to a float variable like this
float lat = gps.location.lat();
float long = lat = gps.location.lat();
and print them to serial monitor i can't get the full data. Instead of printing something like this 00.000000 it prints 00.00
So i tried using dtsurf function to store them in Strings. And i changed example sketch a little bit.
This is the code
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 6, TXPin = 3;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(115200);
ss.begin(GPSBaud);
}
void loop()
{
Serial.println(printFloat(gps.location.lat(), gps.location.isValid(), 11, 6));
Serial.println(printFloat(gps.location.lng(), gps.location.isValid(), 12, 6));
smartDelay(1000);
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);
}
String printFloat(float val, bool valid, int len, int prec)
{
char out[15];
if (!valid)
{
while (len-- > 1)
Serial.print('*');
Serial.print(' ');
}
else
{
//Serial.print(val, prec);
dtostrf(val, 8, 6, out);
return out;
}
smartDelay(0);
}
when i try to print them like this. It prints characters randomly. After few seconds it freezes.
I want to do something like this.
Serial.println(lat);
And use that variable in other places.