Thank you all for your replies! Sorry I haven’t posted any code in this thread. I was posting everything from a mobile device with no access to my code. I was just trying to make sense of a precision issue. I did some testing and here is what i have found.
First thanks to jRemmington for pointing out that print defaults to 2 decimal places! That solved it for me when i was able to give it a shot in my code.
I am printing to the Serial Monitor for debugging currently(tracking a random NMEA setting issue) and here were my results.
Declaring my CorrectedLat and CorrectedLon values as “FLOAT” and using Serial.print(((float)CorrectedLat),6); allows me to see all the decimal places. When i logfile.print(((float)CorrectedLat),6): allows me to print it to the SD card.
When i used unsigned long it was ok to print the Lat to SD, but not the negative Lon value. This did not work in the Serial Monitor. I tried int, long, char etc with varying results but none of them worked.
Below is my code. I am new to this and this is a very basic sketch that took me a lot of head scratching and late nights to figure out. No real checks or intelligence in the sketch, just a basic brute setup that allows me to take my UP501 GPS module, Sparkfun uSD shield and my Uno r3 and write GPS RMC data at 10hz to my uSD card. I have a long list of things i want/will be adding to it but I kept it simple as I am stepping through it. I have SoftwareSerial.h commented out and I am using gSoftSerial right now. I did increase the buffer size of SS to 128. The sketch works with both SoftwareSerial and gSoftSerial with the same results as far as I can tell, just have to change the gSoftSerial gpsSerial(2,3) to SoftwareSerial gpsSerial(2,3).
If someone finds this and decides to use it(and happens to have the same GPS module) there are a few things that need to be clarified. The UP501 is a 3.3v module not 5v. It is wired up using the 3.3v to both VDD and the battery backup for now. TX goes to dig pin2 and RX goes to dig pin3 via a 10k Resistor Divider so you don’t send it 5v when sending commands.
#include <SPI.h>
#include <SdFat.h>
#include <TinyGPS.h>
//#include <SoftwareSerial.h>
#include <gSoftSerial.h>
long lat, lon;
unsigned long fix_age, date, time, speed, altitude, course;
float CorrectedSpeed, CorrectedLon, CorrectedLat;
const int chipSelect = 8;
//#define PMTK_SET_NMEA_BAUDRATE_38400 "$PMTK251,38400*1F" // Set Baud Rate to 38400
#define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
#define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" // only RMC data
File logfile;
gSoftSerial gpsSerial (2,3); // create gps sensor connection
TinyGPS gps; // create gps object
SdFat SD; // create SD object
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
gpsSerial.begin(9600);
gpsSerial.println(PMTK_SET_NMEA_OUTPUT_RMCONLY); // turn on only RMC
gpsSerial.println(PMTK_SET_NMEA_UPDATE_10HZ); // turn on 10Hz
while (!Serial) {
; // wait for serial port to connect.
}
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
char filename[15];
strcpy(filename, "data_00.txt");
for (uint8_t i=0; i<100; i++) {
filename[5] = '0' + i/10;
filename[6] = '0' + i%10;
if (!SD.exists(filename)) {
break;
}
}
logfile = SD.open(filename, FILE_WRITE);
if(!logfile) {
Serial.print("Couldnt create ");
Serial.println(filename);
while (1) {}
}
Serial.print("Writing to ");
Serial.println(filename);
logfile.println("latitude, longitude, speed, time");
}
void loop() {
while(gpsSerial.available()>0){ // check for gps data
// char c = gpsSerial.read(); // read gps data into char c
// Serial.print(c); // pring NMEA RMC strings to the Serial Monitor, this is here to figure if its passing all NMEA sentences or just RMC for debug
if (gps.encode(gpsSerial.read())){
gps.get_position(&lat, &lon, &fix_age); // get GPS lat, lon and fix age variables
gps.get_datetime(&date, &time, &fix_age); // get GPS date, time and fix age, when i tried to omit the date variable i had bad results
speed = gps.speed(); // get speed value in 100th of a knot from TinyGPS
CorrectedSpeed = speed * 0.0115; // convert speed to mph
CorrectedLon = lon * 1E-6; // Convert Longitude to a normal value for GPS Visualizer
CorrectedLat = lat * 1E-6; // Convert Latitude to a normal value for GPS Visualizer
// Serial.print(((float)CorrectedLat),6);Serial.print(",");Serial.print(((float)CorrectedLon), 6);Serial.print(",");Serial.println(time); // print data to serial monitor for debug
logfile.print(((float)CorrectedLat),6);logfile.print(","); // print CorrectedLat to SD with 6 decimal places
logfile.print(((float)CorrectedLon),6);logfile.print(","); // print CorrectedLon to SD with 6 decimal places
logfile.print(CorrectedSpeed);logfile.print(","); // print CorrectedSpeed to SD
logfile.println(time); // print time string from RMC, no conversion yet
logfile.flush(); // flush to push the data to the SD without having to close it
}
}
}