I have compiled and uploaded the following code and monitored the output from the GPS via the Serial Monitor. The GPS antenna is outside and has good sky access. I can see on teh Serial Monitor that the LAT and LONG contained in the GPS data is correct for my location but the system never gets to the point where newData is set TRUE:
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
Obviously your not getting in a valid sentence, does gps.encode(c) need the full string first then see if it is valid, or can it accept individual chars?
It looks like all your longer sentences are being truncated, possibly 1 second is not long enough to receive a full sentence?
I would take the GPS reading out of the 1-second limit loop:
void loop() //loop principal. Os comentários do autor ajudam a entender.
{
static bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
unsigned long currentTime = millis();
static unsigned long lastTimeOfLocation;
static unsigned long lastTimeOfStatistics;
if (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?
if (currentTime - lastTimeOfLocation >= 1000) { // Has it been a second
float flat, flon;
unsigned long age;
lastTimeOfLocation = currentTime;
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());
}
}
// Display statistics every second
if (currentTime - lastTimeOfStatistics >= 1000) {
lastTimeOfStatistics = currentTime
gps.stats(&chars, &sentences, &failed);
Serial.print(" CHARS=");
Serial.print(chars);
Serial.print(" SENTENCES=");
Serial.print(sentences);
Serial.print(" CSUM ERR=");
Serial.println(failed);
}
}
Thanks for the tip johnwasser. I tried your code but with pretty much exactly the same result. The new serial monitor
output is in the attached file again. I am beginning to wonder if the GPS shield is faulty in some way.
If you play around with the time ( change 1000 to 800) you will get a newline with each reading the GPS makes. However what I recommend it that you get rid of the for loop and check to see if the next character is a "$" if so create a new line.
) // make a new line every time a new "$" sign is shown.
Serial.write("\n");
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;
}
// }
I seem to remember when I first got my GPS (Neo6M) that I had trouble with reception. I believe solved it by increasing the Software Serial buffer size in SoftwareSerial.h. May not be the answer for you but worked here.
Hey guys, thanks to everyone who was so kind to post their advice. I have changed the buffer size in SoftwareSerial and the code now works as expected.
Next step is to try and get the whole thing woirking in a data acquisition system for a model boat!!
Propeller revs
Current draw
Battery Voltage
Boat speed
etc etc.
At least it will keep me off the streets for a while!
I used a 23LCV1024 SPI SRAM chip to store data from my GPS for later downloading and mapping my route on Google Maps. 128K bytes and can be make non-volatile with a watch battery.