This is a GPS module test sketch for Arduino based on a LCD1602 shield. You can either save it to local INO file and build width Arduino IDE (TinyGPS library is required). You can also compile it online into a HEX file and upload to Arduino with AVRDUDE or other uploading utilities.
#include <LCD4Bit_mod.h>
#include <TinyGPS.h>
LCD4Bit_mod lcd = LCD4Bit_mod(2);
TinyGPS gps;
void setup()
{
// change the baudrate to adapt with GPS module
Serial.begin(9600);
lcd.init();
}
void loop()
{
static bool ready = false;
if (!Serial.available()) return;
char c = Serial.read();
// push NMEA characters to TinyGPS
if (!gps.encode(c)) {
// parsed data not ready
if (!ready) lcd.print(c);
return;
}
char buf[16];
unsigned long fix_age;
long lat, lon;
gps.get_position(&lat, &lon, &fix_age);
sprintf(buf, "LAT:%d.%05ld",
(int)(lat / 100000), lat % 100000);
lcd.cursorTo(1, 0);
lcd.printIn(buf);
sprintf(buf, "LON:%d.%05ld",
(int)(lon / 100000), lon % 100000);
lcd.cursorTo(2, 0);
lcd.printIn(buf);
ready = true;
}
If you need a GPS receiver for Arduino, check this out:
- Low-power consumption SIRF 3 chip
- No breakout needed for use with Arduino
- 9600Hz TTL UART interface
- Working with Arduino and TinyGPS
- Built-in antenna and mounting magnet
- Size:52x48x10 mm
- Weight: 80g
- Price: US$ 35 (free shipping worldwide)
