1

I've synced my Uno with the Arduino IDE and I'm using the following code to get the GPS coordinates:

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

unsigned long fix_age;
SoftwareSerial GPS(4,3);
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;

void setup(){
  GPS.begin(9600);
  Serial.begin(9600);
}

void loop(){
  long lat, lon;
  unsigned long fix_age, time, date, speed, course;
  unsigned long chars;
  unsigned short sentences, failed_checksum;
  // retrieves +/- lat/long in 100000ths of a degree
  gps.get_position(&lat, &lon, &fix_age);
  // time in hh:mm:ss, date in dd/mm/yy

  getGPS();
  Serial.print("Latitude : ");
  Serial.print(lat/100000,7); //#UPDATED
  Serial.print(" :: Longitude : ");
  Serial.println(lon/100000,7); //#UPDATED
}

void getGPS(){
  bool newdata = false;
  unsigned long start = millis();
  // Every 1 seconds we print an update
  while (millis() - start < 1000)
  {
    if (feedgps ()){
      newdata = true;
    }
  }
  if (newdata)
  {
    gpsdump(gps);
  }
}

bool feedgps(){
  while (GPS.available())
  {
    if (gps.encode(GPS.read()))
      return true;
  }
  return 0;
}

void gpsdump(TinyGPS &gps)
{
  //byte month, day, hour, minute, second, hundredths;
  gps.get_position(&lat, &lon);
  Serial.print("Hello World : "); //#UPDATED (Test)
  LAT = lat;
  LON = lon;
  {
    feedgps(); // If we don't feed the gps during this long
  }
}

When I compile, it uploads successfully and when I check the serial streams, it displays:

Latitude : 41103 :: Longitude : 41103

But my lat/lon (in the risk of disclosing location) is (38.984898400, -76.957276900)

It doesn't seem to be the same.

12
  • is the GPS getting a good view of the sky? Should add some prints to see if you are getting into gpsdump() or just print your lat/lon rather then reassigning it to LAT/LON – Chad G Jun 27 '18 at 23:40
  • 1
    Can you update the code and provide the output – Chad G Jun 28 '18 at 4:02
  • 1
    @ChadG: I updated the code and results. – db18 Jun 28 '18 at 16:34
  • 1
    @ChadG: I did just now. No change in the lat/lon. Also if I change the baud rate from 9600 in the serial monitor, it again outputs garbage. – db18 Jun 28 '18 at 16:39
  • 1
    @ChadG: Surprisingly, no. I'm really clueless now. – db18 Jun 28 '18 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.