Arduino Uno and Neo-6m GPS help

Hello everyone,

Quick question for the more code savvy individuals on this site. I have a Neo -6m GPS module connected to an Arduino UNO. The problem I have is my Uno cannot "handle" both position data and time data at the same time. For example, I can serial print both latitude and longitude and the serial monitor will output the correct values. I can serial print both hour and minute and the serial monitor will output the correct values. But i cannot serial print latitude, longitude, hour, and minute at the same time. My serial monitor will output zeroes for each value. Here is the code I am using.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
SoftwareSerial gpsSerial(3, 4); //rx,tx
TinyGPSPlus gps;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  gpsSerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

  while (gpsSerial.available() > 0) {

    gps.encode(gpsSerial.read());
    Serial.print(gps.location.lat());
    Serial.print("  ");
    Serial.println(gps.location.lng());
    Serial.print("  ");
    Serial.print(gps.time.hour());
    Serial.print("  ");
    Serial.println(gps.time.minute());
  }
  Serial.println("NO DATA");
}

I think the input buffer is overflowing because you are spending far too much time printing.
Start with a faster output rate:
Serial.begin(115200);

Then only print when a full message has been processed:

  while (gpsSerial.available() > 0)
    if (gps.encode(gpsSerial.read()) {

The function gps.encode() returns 'true' if the character processed completes a message. If it doesn't, there is no chance that any values have changed.

Yep, that corrected the problem. Thank you very much for the swift response!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.