Problem with Getting Data from Neo-6m GPS Service

Hi Arduino community!

I have been trying to get my Neo-6M GPS to work with my Arduino Uno for a week now. I have read just about every thread related to the Neo-6M GPS on the entire internet and I found my solution by mere accident! I am wondering if one of the genius' here can help me understand why my change to my code made it work...?

My setup is very simple. I have one of these:

Ublox NEO-6M GPS Module

And it's connected to my Arduino Uno through the following connections:

Vcc from Ublox --> 5V Pin on Uno
Rx from Ublox --> Pin 3 on Uno
Tx from Ublox --> Pin 4 on Uno
Ground from Ublox --> Ground on Uno.

And this is my very simple code...

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

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(9600);
  ss.begin(GPSBaud);
}

void loop(){
  Serial.println(gps.satellites.value());
  
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" Longitude= "); 
      Serial.println(gps.location.lng(), 6);
    }
  }
  delay(2000)
}

I tried all week with many different ideas to get it working: I tried playing around with the GPSBaud value from 9600 to 115200 and that didn't do anything. I stood outside in my garden looking like an idiot trying to get better "signal" for my GPS and that didn't do anything too.

But in the end, it was the "delay(2000)" bit. I removed that from the code and it worked instantly. Can someone please tell me why this made it work? Did I need to store the gps.location.lng and lat to a variable and print that instead of printing direct from the output of the gps.location function?

Best wishes,

Lewis Norris

gps.encode() returns true or false. Why are you ignoring that value?

The delay() means that nothing happens. You are not reading serial data, so data gets lost. Therefore, what IS passed to gps.encode() rarely comprises a valid sentence.

I am aware that gps.encode returns a true or false value but what do you mean I am ignoring it?

LewisNorris:
I am aware that gps.encode returns a true or false value but what do you mean I am ignoring it?

Are you using it? Are you saving it? No and no means that you are ignoring it.

LewisNorris:
But in the end, it was the "delay(2000)" bit. I removed that from the code and it worked instantly. Can someone please tell me why this made it work?

If there is a character available in the serial buffer, you read this one character and pass it on to the GPS encode process.

Then you wait 2 seconds.

What do you think happens to the maybe 2000 characters the GPS has put out whilst you waiting ?

PaulS:
Are you using it? Are you saving it? No and no means that you are ignoring it.

Thank you for the kind help...