I modified a published script [below] to create lat, lon, satelites, altitude etc strings which I then concatinated in a string that could be sent to an SD Card [and in the future to a Radiometrix].
The project does what I want, but the Serial and SD print out only show Lat Lon data to two decimal points. How might I fix this?
I should mention that:
a) when I use a simple code, say: Serial.print(gps.location.lat()), I get the full range of decimal points;
b) when I use the code: Serial.print(gps.location.lat(),6), which should force a six decimal point output, the Serial print simply shows '6'.
Colin.
/*
Rui Santos
Complete Project Details http://randomnerdtutorials.com
Based on the example TinyGPS++ from arduiniana.org
SD card attached to SPI bus as follows:
** MOSI - pin 11 [DI]
** MISO - pin 12 [D0]
** CLK - pin 13
** CS - pin 10 (for MKRZero SD: SDCARD_SS_PIN)
*/
///////////SD////////////
#include <SD.h>
#include <SPI.h>
////////////////////////////
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
//#include <util/delay.h>////////////////inlusion
const int chipSelect = 10;
static const int RXPin = 8, TXPin = 9;
static const uint32_t GPSBaud = 9600;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
/////////////////STRING//////////////////////
String Alt;/////////////intro
String Lat = "invalid";/////////////intro
String Lon = "";/////////////intro
String Sat;////////////////////
String Date = "invalid";
String Day;////////////////////////
String Month;////////////////////////
String Year;////////////////////////
String Hour;////////////////////////
String Min;////////////////////////
String Sec;////////////////////////
String HDOP;/////////////////////////
String Concat = ""; //////////intro
int CS = 10;
int LED = 2;
int LEDa = 3;
// The serial connection to the GPS device
///////////////////////////////////////////////////
void setup() {
pinMode(CS, OUTPUT);/////////CS
pinMode(LED, OUTPUT);//led INDICATOR
pinMode(LEDa, OUTPUT);//led INDICATOR
Serial.begin(9600);
//delay_ms(500);
delay(500);
ss.begin(GPSBaud);
///////////////SD Card////////////////////////
//connect to the sd card
if (!SD.begin(CS));
{
Serial.println("Card Failure");
}
}
void loop() {
// This displays information every time a new sentence is correctly encoded.
while (ss.available() > 0) {
gps.encode(ss.read());
if (gps.location.isUpdated()) {
//////////////////////////////////////////////
//////////////////////////////////////////////
//write newest info to SD Card
Concat = Date + "," + Hour + "," + Min + "," + Lat + "," + Lon + "," + Alt + "," + Sat + "," + HDOP;
if (Lat != "invalid")
digitalWrite(LEDa, HIGH);
else
digitalWrite(LEDa, LOW);
//Open CS Datafile
delay(100);
File dataFile = SD.open("LOG.csv", FILE_WRITE);
if (dataFile)
{
dataFile.println(Concat);
Serial.println(Concat);
dataFile.close();
}
else
{
Serial.println("\nCouldn't open Log file");
}
Alt = (gps.altitude.meters());
Lat = (gps.location.lat());
Lon = (gps.location.lng());
Sat = gps.satellites.value();
Day = gps.date.day();
Month = gps.date.month();
Year = gps.date.year();
Hour = gps.time.hour();
Min = gps.time.minute();
Sec = gps.time.second();
HDOP = gps.hdop.value();
Date = gps.date.value();
Concat = (Date + "," + Hour + "," + Min + "," + Lat + "," + Lon + "," + Alt + "," + Sat + "," + HDOP);
delay(100);
}
}
}