GPS only works when I click Reset on Arduino

I cannot work this out!

My Ublox 7n GPS module will only print data in the serial monitor once when I either click reset on my Arduino Uno or reopen and close my Serial monitor.

So whenever I have the serial monitor open and click reset on my Arduino it quickly spits out all the data on it and then stops, same when I open the serial monitor after being closed.

Here is my code:

#include "TinyGPS++.h"
void displayInfo();
const unsigned long PUBLISH_PERIOD = 1000;
double latitude = 0, longitude = 0;
TinyGPSPlus gps;
unsigned long lastPublish = 0;

void setup()
{
  Serial.begin(9600);

}

void loop()
{

        while (Serial.available() > 0) {
              
          if (gps.encode(Serial.read())) {
            displayInfo();
        }
        }
//      latitude = gps.location.lat();
//      longitude = gps.location.lng();
//      Serial.println(gps.location.lat());
//      Serial.println(gps.location.lng());
//      Serial.println(latitude, 8);
//      Serial.println(longitude, 8);
      delay(1000);
      Serial.println("new");
}

void displayInfo()
{
  if (millis() - lastPublish >= PUBLISH_PERIOD) {
    lastPublish = millis();
      char buf[128];
      delay(1000);
      
      if (gps.location.isValid()) {
        snprintf(buf, sizeof(buf), "%lf,%lf", gps.location.lat(), gps.location.lng());
      //  Serial.println(buf);
      latitude = gps.location.lat();
      longitude = gps.location.lng();
      Serial.println(gps.location.lat());
      Serial.println(gps.location.lng());
      Serial.println(latitude, 8);
      Serial.println(longitude, 8);
      }
      else {
        Serial.println("no location");
      }
    }
  }

I’ve attached an image of my serial monitor, the gps data came through when I closed and reopened it.

Delete the line with the delay() call.

You have the GPS on the same serial port as the serial monitor ?

I've worked out the problem without a solution. For some reason when I connect the RX and TX pins on the module respectively to the RX and TX pins on the arduino, I get my location except that bug happens.

HOWEVER, if I flip the pins so RX->TX & TX-> RX I no longer have the bug ALTHOUGH it now prints 'no location'.

For some reason the location data is being lost when the pins are connected how they should be.

angusryan_:
I've worked out the problem without a solution. For some reason when I connect the RX and TX pins on the module respectively to the RX and TX pins on the arduino, I get my location except that bug happens.

HOWEVER, if I flip the pins so RX->TX & TX-> RX I no longer have the bug ALTHOUGH it now prints 'no location'.

For some reason the location data is being lost when the pins are connected how they should be.

See #2.

You do need to put the GPS on a different serial port to the serial monitor.

How do I do that ? (sorry still learning the way)

Also observed your profile and would love to have a quick small chat if you don't mind, you seem to have completed similar projects to what I am trying right now! (LoRa + GPS)

Take a look at the examples in the TinyGPS library folder.

On a UNO you will need to use software serial to read the GPS, just like the examples do.

the pps is flickering, I think its causing the problems. I ran the device example.

Follow the troubleshooting steps here;

GPS Tutorial

angusryan_ created a new thread for the PPS LED flickering thing: