0
votes

I have seen many tutorials on this topic but I'm unable to determine an issue with the incomplete nature of most (>90%) of all messages I receive from my GT-U7, which is based on ublox NEO-7 (although confusingly the description of the item in the Amazon shop says NEO-6, however reviews and also the u-center state, it's a NEO-7):

Here is the code:

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

float lat = 0.0,lon = 0.0; // create variable for latitude and longitude object  
SoftwareSerial gpsSerial(10,11);   //rx,tx 
TinyGPS gps; // create gps object 

void setup(){ 
  Serial.begin(9600); // connect serial 
  gpsSerial.begin(9600); // connect gps sensor 
} 
void loop(){ 
  if (!gpsSerial.available()) Serial.println("GPS device not available");

  while(gpsSerial.available()){ // check for gps data 
    char d = gpsSerial.read();
    Serial.print(d);
    if(gps.encode(d))// encode gps data 
    {
      Serial.println("Encoding data successful");

      gps.f_get_position(&lat,&lon); // get latitude and longitude 

      // display position
      Serial.println("----------------------------------");
      Serial.println("Position: "); 
      Serial.print("\tlat : "); 
      Serial.println(lat,6); 
      Serial.print("\tlong : "); 
      Serial.println(lon,6);
    }
  }

  Serial.println();

  /*
  String latitude = String(lat,6); 
  String longitude = String(lon,6); 
  Serial.println(latitude+";"+longitude);
  */
  delay(1000); 
}

u-center works without any issues with the device, which I connect to my notebook via USB cable. However (of course USB cable detached!) when it comes to the serial communication things don't look so bright.

Initially I thought that the module is not working at all. However the blinking LED (once every second) indicated a fixed position. And the fact that u-center was able to extract all the data (satellites, speed, longitude and latitude, UTC time etc.) told me otherwise.

I in the code above I commented out the whole loop and added that if:

if (!gpsSerial.available()) Serial.println("GPS device not available");

For my surprise in the serial monitor I got this message only once at the beginning and after that I got the last commented out output (lon and lat both equal 0.0). Next step was to read the data without encoding it.

What I noticed was that most of the messages have something like ,,,, or incomplete ending. Some lines in the output were incomplete parts of a previous line. I pasted a couple of messages in an online decoder and got error telling me that the formatting is wrong (I'm new to this, so looking at it didn't tell me anything about its correctness).

Basically the

if(gps.encode(d))
{
    ...
}

is where the execution fails almost all the time. Every once in a while I would get a correct message here and there (for example $GPGLL) but overall right now it's more of a lucky hit than actual reliable data retrieval.

I've read that the baudrate is important but from what I've found so far 9600 should be used.

Any idea what's going on here? Should I try a different baudrate for Serial.begin(...)? I did try playing with that value and cranking it up produces garbage data that cannot be read at all. So at least I am sure that the baudrate affects the completeness and structural integrity of my data stream.

Note that this happens on both a "proper" Arduino Uno and an Arduino Nano that I've soldered the pin headers onto by myself.

2

2 Answers

0
votes

The value of baud must be set to the same value like setting of module NEO-7. As far as I can see, 9600 is the default value for it and you don't need to use any others. But you can check exactly what value is set for the module.

I'm not sure, but have you tried the following code? Or this example as is.

void loop() {
    String code = "";
    while (gpsSerial.available()) {
        code += (char)(gpsSerial.read());
    }

    Serial.println(code)
    if (gps.encode(code) && code.length() > 0){
        gps.f_get_position(&lat, &lon);

        Serial.println("----------");
        Serial.println("Position: ");
        Serial.print("\tlat : ");
        Serial.println(lat, 6);
        Serial.print("\tlong : ");
        Serial.println(lon, 6);
    }
}
0
votes

The incomplete nature of the data is actually normal. At least at the beginning or whenever the module looses the GPS location fix and attempts to acquire a new one.

Right now I use the code below:

#include <SoftwareSerial.h>
#include <Wire.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 4(rx) and 3(tx).
*/

TinyGPS gps;
SoftwareSerial ss(8, 9);

void setup()
{
  Wire.begin(0x11); // I2C address. Leave empty to join bus as master
  Serial.begin(9600); //115200
  ss.begin(9600); //4800

  Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  Serial.println("by Mikal Hart");
  Serial.println();
}

void loop()
{
  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read();
      // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }
  }

  if (newData)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
    Serial.print(" SPD=");
    float fspd = gps.f_speed_kmph();
    Serial.print("km/h");
    Serial.print(fspd == TinyGPS::GPS_INVALID_F_SPEED ? 0 : fspd);
    unsigned long date, _time;
    gps.get_datetime(&date, &_time, &age);
    Serial.print(" DATE=");
    Serial.print(date);
    Serial.print(" TIME=");
    Serial.print(_time);
  }

  gps.stats(&chars, &sentences, &failed);
  Serial.print(" CHARS=");
  Serial.print(chars);
  Serial.print(" SENTENCES=");
  Serial.print(sentences);
  Serial.print(" CSUM ERR=");
  Serial.println(failed);
  if (chars == 0)
    Serial.println("** No characters received from GPS: check wiring **");
}

This is one of the examples, shipped with the TinyGPS library.

I turned on the NMEA message log in u-center and noticed the exact same issue. This basically gave me a hint that the issue is not in the module itself but rather the poor signal reception I have here plus the fact I need to wait longer until I get a fix. The thing is I actually need to open my window and put my setup on the frame. Otherwise I get very little to no reception. This also includes phone services. :D