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.