The GPS example from Tiny Library not work on MEGA2560

TinyGPS is ancient, it does not support GPSs that put out GNGGA and GPRMC sentences.

In any case there would be nothing to print as the GPS does not have a fix and there is no position reported. Take the GPS outside.

Try the examples from the latest copy of TinyGPSplus.

Great!
Thank you.

shanren,
Much info in your post. I can make some comments but it's up to you to find the faults and fix.

At para 1 each character from the monitor is being sent to the GPS. It's only necessary to send data to the GPS to give it configuration commands. Many users don't even connect the GPS RX pin to the Arduino.

It is also reading any character received from the GPS and sending it to the monitor. That is working and we see your raw NMEA sentences. It is very useful to be able to view the raw sentences before they are processed by the sketch.

Three points to note about the sentences:

  1. the GPS is producing sentences so it is doing what it is meant to do
  2. the sentences are unpopulated, i.e., they contain no data derived from the satellites; so there is nothing for the sketch to process
  3. That TXT sentence that contains "ANTENNA OK" keeps repeating. I don't think it's supposed to do that. That should only appear once when you power up. (Has anyone seen this TXT msg repeating as a normal behaviour?) Something might be causing it to do a kind of partial reboot and I don't think it will get any satellite signals until that is fixed. Undervoltage to the GPS might be the cause.

In para 2 none of the print statements produce anything on the monitor. Serial.println produced something in para 1 so it's the correct statement to use.

It's not really correct to say the code has "failed". It's doing what it must do, just following the logic of the code. It can't do anything else, so it never actually fails, even tho we often uase that phrase.

The only explanation is that the logic never lands on those statements so they never get executed. You have to figure out why by following the logic. It's common practice to put in some print statements in places to give you clues. For example, you could put:
Serial.println("mark 1");
immediately before
if(gps.encode.....
and see what you get.

How do the TinyGPS functions perform when there is no satellite data to process? That needs to be understood.

Good luck.

Thank you, you’re amazing!
It's helpful and kind. I'll test the way you mentioned.

Look at the source code in TinyGPS.cpp. You'll see that it only updates position after receiving a GPRMC or GPGGA sentence. Neither of those appear in the output shown in "p1".

@srnet gave two great suggestions and it's not at all clear they are being followed:

  1. Take the GPS outside.
  2. Switch to TinyGPSplus.

What do you think about the ANTENNA message being continually repeated?

Is it an indication that the GPS is not settling into stable healthy operation?

Maybe it's not an issue, but I haven't seen that behaviour on a board that is pulling in sat data.

Nah, switch to u-center.

I think this forum is amazing. Everyone helps everyone.

I would add a bit of useless information here, until about maybe 4 years ago TinyGPSplus also did not support GNGGA and GNRMC, but it was added;

#define _GPRMCterm "GPRMC"
#define _GPGGAterm "GPGGA"
#define _GNRMCterm "GNRMC"
#define _GNGGAterm "GNGGA"

In the early days of doing GPS trackers I had to add code to flip the Ublox GPSs across from the default of GNxxx to the more supported GPxxx.

Any idea why it didn't support RMC?

U-blox say it is the minimum requirement.

Whats 'it' ?

shanren,
Was this board configured to produce these particular sentences? They are not the usual default sentences.

They are the default sentences for a lot of the 'geniune' Ublox GPSs.

Do you think the OP needs to reconfigure the unit to make it produce a different set of sentences?5

Much easier to use a modern version of TinyGPSplus, see post #28