Yesterday I have tested U-BLOX NEO-6M GPS module with TinyGPS lastest library v12.
The following is my codes copy from Arduino Cookbook.
#include "TinyGPS.h"
#include "SoftwareSerial.h"
#define HEMISPHERE_PIN 13
#define GPS_RX_PIN 2
#define GPS_TX_PIN 3
TinyGPS gps; // create a TinyGPS object
SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN); // create soft serial object
void setup()
{
Serial.begin(9600); // for debugging
ss.begin(9600); // Use Soft Serial object to talk to GPS
pinMode(HEMISPHERE_PIN, OUTPUT);
digitalWrite(HEMISPHERE_PIN, LOW); // turn off LED to start
}
void loop()
{
while (ss.available())
{
int c = ss.read();
Serial.write(c); // display NMEA data for debug
// Send each byte to encode()
// Check for new position if encode() returns "True"
if (gps.encode(c))
{
long lat, lon;
unsigned long fix_age;
gps.get_position(&lat, &lon, &fix_age);
if (fix_age == TinyGPS::GPS_INVALID_AGE)
Serial.println("No fix ever detected!");
else if (fix_age > 2000)
Serial.println("Data is getting STALE!");
else
Serial.println("Latitude and longitude valid!");
Serial.print("Lat: ");
Serial.print(lat);
Serial.print(" Lon: ");
Serial.println(lon);
if (lat < 0) // Southern Hemisphere?
digitalWrite(HEMISPHERE_PIN, HIGH);
else
digitalWrite(HEMISPHERE_PIN, LOW);
}
}
}
UNO can read NMEA formatted codes successfully. Here is part of printing in Serial monitoring window.
$GPVTG,,T,,M,0.005,N,0.010,K,A27
$GPG.0306129,189762,,809,6.,.80
$GGV311,23627330,238490,528271,922,87
GGV,,,01,2,1,2135,0,1,6,0,201,4,7B
GPS,,,1,32,013,8,01927
$PL,20.62,,189762E,5670,AA6
$GPRMC,153658.00,A,3206.16229,N,11849.75641,E,0.016,,120612,,,A70
Latitude and longitude valid!
Lat: 3210270 Lon: 11882927
After input the position into GOOGLE Map in my iPhone, I found the error was so big, i.e. up to 200m, while the supplier says the error should be within 2m.
Can anyone tell me what is the reason? Thank you.