This example shows my first very simple GPS navigation tool, that was written for my Wiring board. It connects to a GPS receiver via port Serial1
(4800bps) and shows some very basic navigation information on a character-based LCD. I tried it in my car, and it works perfectly, although it's quite useless.
The information shown is:
My code uses the Wiring board diagnostic LED on pin 48, which does not exist on Arduino's -- be aware. Also, I think that the call to LiquidCrystal()
in Arduino is different. Below the code are some photos of my hardware setup.
// This is my first very simple GPS navigation tool, that // was written for my Wiring board. It connects to a GPS // module via port Serial1 (4800bps) and shows some very // basic navigation information on a character-based LCD. // The information shown is: // - direction to destination, relative to own movement // - distance to destination in meters (it is really // easy to do kilometers, miles, etc.) // - my current speed in kilometers per hour // - GPS status identifier // // I tried it in my car, and it works perfectly, although // it's quite useless. The code below uses the Wiring // board diagnostic LED on pin 48, which does not exist // on Arduino's -- be aware. #include <nmea.h> #include <LiquidCrystal.h> // create connection to GPRMC sentences from my GPS NMEA myGPS(GPRMC); // create LCD object (I use a 2x16 character display) LiquidCrystal myLCD = LiquidCrystal(13,14,15,2); // my destination coordinates in signed degrees-decimal float dest_latitude = 52.090649; float dest_longitude = 5.121322; void setup() { Serial1.begin(4800); // my GPS is connected to port Serial1, at 4800bps pinMode(48, OUTPUT); // diagnostic led on Wiring-board myLCD.clear(); myLCD.home(); myLCD.print("GPS-NAV TEST 001"); delay(1000); } void loop() { // check if data from GPS available on Serial1 port if (Serial1.available() > 0 ) { // check if full sentence recieved from GPS if (myGPS.decode(Serial1.read())) { // if so, set status led on digitalWrite(48, HIGH); // calculate direction to destination, relative to my own direction of movement float dir = myGPS.gprmc_course_to(dest_latitude, dest_longitude) - myGPS.gprmc_course(); if (dir < 0) { dir += 360; } if (dir > 180) { dir -= 360; } // display relative direction to destination myLCD.clear(); myLCD.home(); if (dir < 0) { myLCD.print('<'); // destination is to your left } else { myLCD.print('>'); // destination is to your right } myLCD.print(abs(dir), DEC); myLCD.print(223, BYTE); // print °-character // display distance to destination in meters myLCD.setCursor(6, 0); myLCD.print("DIST:"); myLCD.print(round(myGPS.gprmc_distance_to(dest_latitude, dest_longitude, MTR)),DEC); myLCD.print("m"); // display my speed in kilometers per hour myLCD.setCursor(0, 1); myLCD.print("SPEED:"); myLCD.print(round(myGPS.gprmc_speed(KMPH)),DEC); myLCD.print("Km/h"); // display GPS positioning status ('A'=active, 'V'=void) myLCD.setCursor(15, 1); myLCD.print(myGPS.gprmc_status()); // set status led off digitalWrite(48, LOW); } } }
A first test on the dashboard of my car (the LCD text is still in Dutch). On the left is the LCD display and above it my Wiring board. On the right is my u-Blox GPS-PS1E receiver module, dangling off the dashboard. Above it you see a 9V battery from which it all runs.
The same setup running on my living room table. The GPS antenna wire runs out the window into my yard.