display gps coordinates display

hello folks,
i want display gps coordinates on my OLED 0.96 SSD1306 i2c, it doesn’t work, i have the 0.00000 on my screen in stead of the coordinate, i though that i have make a mistake on the code or on wiring, tested all individually and nothing showed up, i tried to search the origin of the problem an i found that when i remove display.begin(SSD1306_SWITCHCAPVCC, 0x3C); from the serial port display right coordinate value but went i add it (it’s a necessary element for the screen) the serial port show ******** that mean 0.000000, the code bellow is the tinygps++ fulltest that i modified.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h>
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>

    #define OLED_RESET 4
    Adafruit_SSD1306 display(OLED_RESET);
/*
   This sample code demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup()
{
  Serial.begin(115200);
  ss.begin(GPSBaud);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
      display.setTextSize(1); 
      display.setTextColor(1);
      display.setCursor(15,0);
      display.print("GPS coordinates");
      display.display();

  Serial.println(F("FullExample.ino"));
  Serial.println(F("An extensive example of many interesting TinyGPS++ features"));
  Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
  Serial.println(F("by Mikal Hart"));
  Serial.println();
  Serial.println(F("Sats HDOP Latitude   Longitude   Fix  Date       Time     Date Alt    Course Speed Card  Distance Course Card  Chars Sentences Checksum"));
  Serial.println(F("          (deg)      (deg)       Age                      Age  (m)    --- from GPS ----  ---- to London  ----  RX    RX        Fail"));
  Serial.println(F("---------------------------------------------------------------------------------------------------------------------------------------"));
}

void loop()
{
  static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printInt(gps.location.age(), gps.location.isValid(), 5);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);

          display.setTextSize(1); 
        display.setTextColor(1);
        display.setCursor(0,10);
        display.print("latitude:");
        display.print((float)(gps.location.lat()), 6);
        display.setCursor(0,20);
        display.print("longitude:");
        display.print((float)(gps.location.lng()), 6);
        display.display();
       

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();
  
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}

i though that the problem came from the library it self, i changed it to adafruit-gps but the same problem obscured.
please can some one help me solve my problem ?

Does your screen show the rest of the text correctly? Does the serial monitor show the correct values? What gps module do you have? Are you outside?

Hello, Thannk you for your reply
Yes i'm outside, m'y GPS module is a ublox 6m, yes the rest of the text display correctly, but the showed values on the sreen and the serial monitor is always 0.00000 but when i upload the fulltest exemple without the modification the serial monitor display the correct values, it"s weard, GPS alone work correctly GPS+display doesn't work ....

Why does the code to display to the serial port take into account the fact that there may not be valid data, while the code to display on the SSD1306 does not?

Why do you ignore the fact that any given character read from the GPS may indicate the end of a sentence?

hello, thank you for your reply
it’s a test code, i already have added a condition on my main code but it didn’t work, to find the orgine of the problem i eliminate all the unnecessary elements including testing the validity of the coordinates.
the GPS fonction : gps.location.lat() and gps.location.lng() return a double type variable i convert it on to float and display the variable, can you please more explain how can add the character that indicate the end of the sentence.

can you please more explain how can add the character that indicate the end of the sentence.

The GPS sends the character. The encode() function returns true when that character is fed to it. You should not be ignoring the return value from encode().