Hello,
I am trying to create a GPS data logger using a EM-406 GPS, Arduino Ethernet shield with SD card, and a Mega 2560. I have used the SD, TinyGPS and SoftwareSerial libraries and I have tried to make the code as basic as possible at this stage. I have created the following code, which compiles ok. When I open the serial port the data being printed is as follows. I have the GPS hooked up to pin 51.
0.000000, 0.000000
0.000000, 0.000000
0.000000, 0.000000
0.000000, 0.000000
etc
Where I was expecting to get the values of latitude and longitude to 6 decimal places.
Does anyone have any clues as to what I have missed in my programming?
Many thanks and Regards.
#include <SD.h>
#include "TinyGPS.h"
#include <SoftwareSerial.h>
TinyGPS gps;
SoftwareSerial ss(51, 3);
float fkmph;
float flat, flon, fix_age;
void setup()
{
ss.begin(4800);
Serial.begin(9600);
SD.begin(4);
pinMode(53, OUTPUT);
}
void loop()
{
while (ss.available())
{
int c = ss.read();
if (gps.encode(c))
{
// 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("GPSTEST.csv", FILE_WRITE);
myFile.print(flat,6);
myFile.print(",");
myFile.println(flon,7);
myFile.close();
Serial.print(flat,6);
Serial.print(",");
Serial.println(flon,7);
delay(500);
}