Hi...
What I'm trying to do, is convert thedata I get from the gps (altitude and latitude) in a string. I am using the arduino library but I am failing to put the data into a variable that has the same amount of caracters i recieve...
the code is:
#include <TinyGPS.h>
TinyGPS gps;
int cont=0;
void setup()
{
Serial.begin(115200);
Serial.println("Sats Latitude Longitude ");
Serial.println(" (deg) (deg) ");
Serial.println("-------------------------");
Serial1.begin(9600);
}
void loop()
{
float flat, flon;
unsigned long age, date, time, chars = 0;
unsigned short sentences = 0, failed = 0;
print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
gps.f_get_position(&flat, &flon, &age);
print_f(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6);
print_f(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
Serial.println();
smartdelay(1000);
if (cont==20)
{exit(0);}
}
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (Serial1.available())
gps.encode(Serial1.read());
} while (millis() - start < ms);
}
static void print_int(unsigned long val, unsigned long invalid, int len)
{
char sz[32];
if (val == invalid)
strcpy(sz, "*******");
else
sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i)
sz = ' ';
-
if (len > 0)*
-
sz[len-1] = ' ';*
-
Serial.print(sz);*
-
smartdelay(0);*
}
static void print_f(float val, float invalid, int len, int prec)
{ -
if (val == invalid)*
-
{*
-
while (len-- > 1)*
_ Serial.print('*');_ -
Serial.print(' ');*
-
}*
-
else*
-
{*
-
Serial.print(val, prec);*
-
int vi = abs((int)val);*
-
int flen = prec + (val < 0.0 ? 2 : 1); // . and -*
-
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;*
-
for (int i=flen; i<len; ++i)*
-
{*
-
Serial.print(' ');*
-
}*
-
}*
-
smartdelay(0);*
-
cont++;*
}
What I what is to put the data in a String like: String latitude
and be able to print it: Serial.print(latitude)