Serial.write() prints a variable twice

I have this code:

    #include <TinyGPS++.h>
    #include <SoftwareSerial.h>
    #define GPS_RX_PIN 2
    #define GPS_TX_PIN 3
    TinyGPSPlus gps;
    SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN);
    void setup()
    char clat[11];
    char clng[11];
    void loop()
            bool isGpsLocationValid = false;
                while (ss.available()>0)
                    char c = byte(;
                    if (gps.encode(c)) 
                        if (gps.location.isValid())
                            dtostrf(, 11, 6, clat);
                            dtostrf(gps.location.lng(), 11, 6, clng);
                            isGpsLocationValid = true;
            } while (isGpsLocationValid == false);

Now when all is done, the clng value is printed twice in the serial monitor.
The value i get is in this format:

    27.275869  15.151013

As you can see, clng is printed twice. Any ideas why is that?

OK, i found the problem. I guess this is an issue with the TinyGPS++ library. When using, the output is 27.275869 15.151013, instead of just 27.275869.

So when also using gps.location.lng(), oi get the double longitute....

The problem is not with TinyGPS++, because just returns a single floating point number. Rather, you have not reserved enough space in your character strings for the terminating 0 character, so they run together. Make the strings at least 12 bytes long.


The dtostre() function converts the double value passed in val into an ASCII representation that will be stored under s. The caller is responsible for providing sufficient storage in s.