Hello again,
Well I have successfully got my GPS data logger working using a hardware serial port (Serial 3) of my Mega 2560. The data is written to the SD card of the Ethernet shield and the csv file is set up for the GPS Visualizer software.
Thanks again for your suggestions and advice.
The code below is my latest version.
Cheers
#include "TinyGPS.h"
#include <SD.h>
TinyGPS gps;
void setup()
{
Serial.begin(115200);
Serial3.begin(4800);
SD.begin(4);
pinMode(53, OUTPUT);
File myFile = SD.open("trip.csv", FILE_WRITE);
myFile.print("type,latitude,longitude,alt");
myFile.close();
Serial.print("type,latitude,longitude,alt");
}
void loop()
{
bool newdata = false; // check if data is coming in
if (feedgps())
newdata = true;
if (newdata)
{
unsigned long chars;
unsigned short sentences, failed;
// For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
// process new gps info here
long lat, lon;
unsigned long fix_age, time, date, speed, course;
unsigned long chars;
unsigned short sentences, failed_checksum;
// retrieves +/- lat/long in 100000ths of a degree
gps.get_position(&lat, &lon, &fix_age);
// time in hhmmsscc, date in ddmmyy
gps.get_datetime(&date, &time, &fix_age);
// returns speed in 100ths of a knot
speed = gps.speed();
// course in 100ths of a degree
course = gps.course();
float flat, flon;
// returns +/- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
float falt = gps.f_altitude(); // +/- altitude in meters
float fc = gps.f_course(); // course in degrees
float fk = gps.f_speed_knots(); // speed in knots
float fmph = gps.f_speed_mph(); // speed in miles/hr
float fmps = gps.f_speed_mps(); // speed in m/sec
float fkmph = gps.f_speed_kmph(); // speed in km/hr
File myFile = SD.open("trip.csv", FILE_WRITE);
myFile.print("T");
myFile.print(",");
myFile.print(flat,7);
myFile.print(",");
myFile.print(flon,7);
myFile.print(",");
myFile.println(falt);
myFile.close();
Serial.print("T");
Serial.print(",");
Serial.print(flat,7);
Serial.print(",");
Serial.print(flon,7);
Serial.print(",");
Serial.println(falt);
delay(500);
}
}
}
static bool feedgps()
{
while (Serial3.available())
{
if (gps.encode(Serial3.read()))
return true;
}
return false;
}