TinyGPS and hardware serial?

SoftwareSerial was also a cause for consternation in my project as well as it Will drop or mangle a character once in a while. When I switched to a Mega most problems went away. Is it possible that you have RX connected to RX and TX connected to...? That will also give you the results you report. GPS_RX must connect to Mega_TX and GPS_TX must connect to Mega_RX. Where Mega_RX is serial1,2,3 same for TX.
There is a serial0 but that is also the data connection to the usb converter and as such restricted to talking to the serial monitor or programming via the bootloader.
If you need it I can modify the two or three places where serial is mentioned in the sketch I did and enclosed it. It's untested both my Mega's are busy but the changes are just to assign serial data to a specific hardware port instead of an object.
One last thing, Verify both GPS connections and speed. The Ucenter thing comes with instructions, You can get them from the U-Blox webpage.

Doc

Mega_test_with_gps_device.ino (5.22 KB)

PaulS:

I ran the attached sketch, modified to use Pins 10 & 11 (with Softserial) for about 40 minutes now and still don't get any GPS data on the Serial Monitor.

Post a picture of how the GPS IS connected.

Stop using SoftwareSerial when you have 4 hardware serial ports on the Mega.

I'm trying to simplify things to make sure the GPS is working and responding properly. Right now I have the GPS connected to a NANO, with the GPS's RX going to D3 and TX going to D2, using the following sketch:

#include <SoftwareSerial.h>

#include <TinyGPS.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
 It requires the use of SoftwareSerial, and assumes that you have a
 4800-baud serial GPS device hooked up on pins 3(rx) and 4(tx).
 */

TinyGPS gps;
SoftwareSerial nss(2, 3);

static void gpsdump(TinyGPS &gps);
static bool feedgps();
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);

void setup()
{
  Serial.begin(115200);
  nss.begin(4800);

  Serial.print("Testing TinyGPS library v. "); 
  Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
  Serial.print("Sizeof(gpsobject) = "); 
  Serial.println(sizeof(TinyGPS));
  Serial.println();
  Serial.println("Sats HDOP Latitude Longitude Fix  Date       Time       Date Alt     Course Speed Card  Distance Course Card  Chars Sentences Checksum");
  Serial.println("          (deg)    (deg)     Age                        Age  (m)     --- from GPS ----  ---- to London  ----  RX    RX        Fail");
  Serial.println("--------------------------------------------------------------------------------------------------------------------------------------");
}

void loop()
{
  bool newdata = false;
  unsigned long start = millis();

  // Every second we print an update
  while (millis() - start < 1000)
  {
    if (feedgps())
      newdata = true;
  }

  gpsdump(gps);
}

static void gpsdump(TinyGPS &gps)
{
  float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5);
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5);
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);

  print_date(gps);

  print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2);
  print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2);
  print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6);
  print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9);
  print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2);
  print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6);

  gps.stats(&chars, &sentences, &failed);
  print_int(chars, 0xFFFFFFFF, 6);
  print_int(sentences, 0xFFFFFFFF, 10);
  print_int(failed, 0xFFFFFFFF, 9);
  Serial.println();
}

static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    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);
  feedgps();
}

static void print_float(float val, float invalid, int len, int prec)
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, "*******");
    sz[len] = 0;
    if (len > 0) 
      sz[len-1] = ' ';
    for (int i=7; i<len; ++i)
      sz[i] = ' ';
    Serial.print(sz);
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1);
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(" ");
  }
  feedgps();
}

static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
  if (age == TinyGPS::GPS_INVALID_AGE)
    Serial.print("*******    *******    ");
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d   ",
    month, day, year, hour, minute, second);
    Serial.print(sz);
  }
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);
  feedgps();
}

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

static bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))
      return true;
  }
  return false;
}

The output is still the same:

**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4374 0 715
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4455 0 728
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4536 0 741
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4617 0 753
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4698 0 767
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4779 0 781
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4860 0 795
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 4941 0 810
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 5022 0 825

Swapping the RX & TX pins around doesn't help either.

I'm trying to simplify things to make sure the GPS is working and responding properly. Right now I have the GPS connected to a NANO, with the GPS's RX going to D3 and TX going to D2, using the following sketch:

Possibly a dumb question, but you also connected ground, right?

PaulS:

I'm trying to simplify things to make sure the GPS is working and responding properly. Right now I have the GPS connected to a NANO, with the GPS's RX going to D3 and TX going to D2, using the following sketch:

Possibly a dumb question, but you also connected ground, right?

Yes, it's grounded.

The NANO is in a breaboard and "share" the side power rails with the GPS. i.e. there's a black cable coming from GND on the GPS to the blue line in the breadboard, and a jumper to the nano's GND pin. A red wire is connected from the GPS's VIN pin to the red line in the breadboard, and a jumper to the NANO's 5V pin.
Then I have a black wire coming from the GPS's RX pin, into the NANO's D3 pin, and a green wire from the GPS's TX pin to the Nano's D2 pin

Another dumb question, you have verified that your sketches are using the correct baud rate for how your GPS module is configured?

Sembazuru:
Another dumb question, you have verified that your sketches are using the correct baud rate for how your GPS module is configured?

Thanx, this solved the puzzle!
I honestly didn't look into that, since most examples use 115200. This GPS's baud rate is 9600 (took some google searching to find it). And it's working fine now, thank you :slight_smile:

hai
I am using arduino mega.. I downloaded and paste the tinygps library in arduino library folder.but when programming the tinygps header file is not highlighted...is there any way...??

is there any way

The syntax color means nothing. It is what the compiler says that matters.

thanq for the reply

but it shows "tinygps. .there is no file or directory "like errors

but it shows "tinygps. .there is no file or directory "like errors

We don't deal with paraphrased error messages. They are text. Text can be copied and pasted, really easily.

It sounds, though, like you have not downloaded and properly installed the TinyGPS (or TinyGPS++) library.

thanq for ur reply..
After i reinstalled the library its shows an error that"no known conversion for arguments 1 from to char..

RudiAhlers:
Thanx, this solved the puzzle!
I honestly didn't look into that, since most examples use 115200. This GPS's baud rate is 9600 (took some google searching to find it). And it's working fine now, thank you :slight_smile:

Hi i have similar issue of what you encountered, so far there is no luck in resolving.

I'm using a GPS Module Sklab skg13bl + Arduino Uno board

skg13bl has a TTL pins i'm using those to get the TX and RX and connected to D2 & D3 of Arduino uno also the 3rd pin on GND is connected to Arudino GND.

i could see the gps receiver receiving signals, green lights starts blinking after the gps fix.

but i get the same data,

**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 74253 0 16
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 74645 0 16
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 74922 0 16
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 75147 0 16
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 75542 0 16
**** **** ******* ******* **** ******* ******* **** ******* ****** ***** *** 0 0.00 *** 75822 0 16

akku_123:
thanq for ur reply..
After i reinstalled the library its shows an error that"no known conversion for arguments 1 from to char..

It shows the line number in the code that you didn't post that generated the error, too.

Show ALL of your code and ALL of the error message(s).

but i get the same data,

And you, too, failed to post your code.

After i re-installing the library the error got disappeared..but after i execute the following code the serial monitor shows nothing..

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

long lat,lon; // create variable for latitude and longitude object

SoftwareSerial gpsSerial(2, 3); // create gps sensor connection
TinyGPS gps; // create gps object

void setup(){
Serial.begin(9600); // connect serial
gpsSerial.begin(4800); // connect gps sensor
}

void loop(){
while(gpsSerial.available()){ // check for gps data
if(gps.encode(gpsSerial.read())){ // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
// display position
Serial.print("Position: ");
Serial.print("lat: ");Serial.print(lat);Serial.print(" ");// print latitude
Serial.print("lon: ");Serial.println(lon); // print longitude
}
}
}

      while(gpsSerial.available()){ // check for gps data
       if(gps.encode(gpsSerial.read())){ // encode gps data

Assuming that there is data on the SoftwareSerial port, read it and, if it ends a sentence, do some stuff and show the results.

Now, there are two assumptions about that you do NOT know to be true.

You do NOT know that there is really data to read on the SoftwareSerial port.
And, even if there is, you don't know that the data is any good.

So, your loop() should look like:

  void loop()
  {
    while(gpsSerial.available())
    {
        char c = gpsSerial.read();
        Serial.print(c);
    }
  }

until you KNOW that you are reading good data.

after i use character datatype it returns garbage values and for integer it returns 0

akku_123:
after i use character datatype it returns garbage values and for integer it returns 0

You have some code? You have some output you want to show (screenshots of)?

hi there, sorry for my late reply....

my problem got solved.... i used tinyGPSplus library serial 2 of my arduino..thanq..