Lat Lon - cropped decimal points using Tiny library with Ublox7 GPS

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);

    }
    
  }
}

Serial.print(gps.location.lat(),6)

That should work, and print the result to 6 decimal places (the last 1 or 2 digits won't be accurate). However your code does not contain that line. Please post the code that prints the wrong result.

Aside: it is a terrible idea to use Strings on an AVR-based Arduino (Uno, etc.). Strings cause memory problems and random crashes. Use C-strings (zero terminated character arrays) instead, if you must do string manipulation.

Thank you very much.

The code Serial.print(gps.location.lat(),6) prints out latitude, with six decimal point when not in a string [that is, just as a line in the programme]. But when it in a string, the serial just prints out number '6'. Using Serial.print(gps.location.lat(), as in the code sent earlier prints out the data, but only to two decimal places.

On your helpful aside, I use strings because I have seen others use them [I am a bit limited in my knowledge of coding], but if there is a better way, I am up for it. What I am trying to do is rig up a flight system for a high altitude balloon. Strings seemed something I could use to extract bits from the GPS, link them up and send them to a Radiometrix and an SD card.

I will look into using 'C-strings (zero terminated character arrays) instead, if you must do string manipulation', but any other suggestions would be greatly appreciated.

Thanks very much for taking the trouble to comment.

Regards,

Colin.

For a balloon instrument package, you definitely want to avoid problematic Strings. However, you don't need to use C-strings or Strings. You can always print (to the serial monitor, SD card, etc.) using a series of statements like this:

Serial.print(gps.date.value());
Serial.print(",");
Serial.print(gps.hdop.value());
Serial.print(",");
...
Serial.print(gps.location.lat(),5);
Serial.println(); //terminates entire output line

Some people call this "Arduino speak".

Also, the function sprintf() provides a number of elegant ways to combine this all into one statement, but it does not by default support floating point numbers (like latitude) on standard Arduinos.

Yes, definetly no need for Strings.

TinyGPS++ is well able to 'extract' all the data you need from the GPS and then writing that data to SD card is as easy as using a series of SD.print() commands.

You could assemble all the stuff you want to send to SD into a buffer, and just send that to SD, but there is no need to.

I have published high altitude balloon tracker code that uses snprintf() to assemble GPS and sensor data into a single buffer for transmission using FSK RTTY, the data is in the format of a CSV type string, example;

$$$$TENPARTS1,4579,05:44:59,55.45521,-6.18658,40,0,0,5,401,3669,8,Y,9,1*7E35

And its easy to send that to SD, if you insist.

jremington, srnet,

Many thanks for all the very helpful comments and suggestions. Much appreciated. I will explore these options and continue learning.

Colin.