Components and supplies
Jumper wires (generic)
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
DeviceExample.ino
c_cpp
1#include <TinyGPS++.h> 2#include <SoftwareSerial.h> 3/* 4 * https://alaspuresujay.github.io/ 5 * follow me on instagram https://www.instagram.com/alaspuresujay 6 7 This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object. 8 It requires the use of SoftwareSerial, and assumes that you have a 9 4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx). 10*/ 11static const int RXPin = 4, TXPin = 3; 12static const uint32_t GPSBaud = 4800; 13 14// The TinyGPS++ object 15TinyGPSPlus gps; 16 17// The serial connection to the GPS device 18SoftwareSerial ss(RXPin, TXPin); 19 20void setup() 21{ 22 Serial.begin(115200); 23 ss.begin(GPSBaud); 24 25 Serial.println(F("DeviceExample.ino")); 26 Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module")); 27 Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion()); 28 Serial.println(F("by Sujay Alaspure")); 29 Serial.println(); 30} 31 32void loop() 33{ 34 // This sketch displays information every time a new sentence is correctly encoded. 35 while (ss.available() > 0) 36 if (gps.encode(ss.read())) 37 displayInfo(); 38 39 if (millis() > 5000 && gps.charsProcessed() < 10) 40 { 41 Serial.println(F("No GPS detected: check wiring.")); 42 while(true); 43 } 44} 45 46void displayInfo() 47{ 48 Serial.print(F("Location: ")); 49 if (gps.location.isValid()) 50 { 51 Serial.print(gps.location.lat(), 6); 52 Serial.print(F(",")); 53 Serial.print(gps.location.lng(), 6); 54 } 55 else 56 { 57 Serial.print(F("INVALID")); 58 } 59 60 Serial.print(F(" Date/Time: ")); 61 if (gps.date.isValid()) 62 { 63 Serial.print(gps.date.month()); 64 Serial.print(F("/")); 65 Serial.print(gps.date.day()); 66 Serial.print(F("/")); 67 Serial.print(gps.date.year()); 68 } 69 else 70 { 71 Serial.print(F("INVALID")); 72 } 73 74 Serial.print(F(" ")); 75 if (gps.time.isValid()) 76 { 77 if (gps.time.hour() < 10) Serial.print(F("0")); 78 Serial.print(gps.time.hour()); 79 Serial.print(F(":")); 80 if (gps.time.minute() < 10) Serial.print(F("0")); 81 Serial.print(gps.time.minute()); 82 Serial.print(F(":")); 83 if (gps.time.second() < 10) Serial.print(F("0")); 84 Serial.print(gps.time.second()); 85 Serial.print(F(".")); 86 if (gps.time.centisecond() < 10) Serial.print(F("0")); 87 Serial.print(gps.time.centisecond()); 88 } 89 else 90 { 91 Serial.print(F("INVALID")); 92 } 93 94 Serial.println(); 95} 96
DeviceExample.ino
c_cpp
1#include <TinyGPS++.h> 2#include <SoftwareSerial.h> 3/* 4 * https://alaspuresujay.github.io/ 5 6 * follow me on instagram https://www.instagram.com/alaspuresujay 7 8 This 9 sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object. 10 11 It requires the use of SoftwareSerial, and assumes that you have a 12 4800-baud 13 serial GPS device hooked up on pins 4(rx) and 3(tx). 14*/ 15static const int RXPin 16 = 4, TXPin = 3; 17static const uint32_t GPSBaud = 4800; 18 19// The TinyGPS++ 20 object 21TinyGPSPlus gps; 22 23// The serial connection to the GPS device 24SoftwareSerial 25 ss(RXPin, TXPin); 26 27void setup() 28{ 29 Serial.begin(115200); 30 ss.begin(GPSBaud); 31 32 33 Serial.println(F("DeviceExample.ino")); 34 Serial.println(F("A simple demonstration 35 of TinyGPS++ with an attached GPS module")); 36 Serial.print(F("Testing TinyGPS++ 37 library v. ")); Serial.println(TinyGPSPlus::libraryVersion()); 38 Serial.println(F("by 39 Sujay Alaspure")); 40 Serial.println(); 41} 42 43void loop() 44{ 45 // 46 This sketch displays information every time a new sentence is correctly encoded. 47 48 while (ss.available() > 0) 49 if (gps.encode(ss.read())) 50 displayInfo(); 51 52 53 if (millis() > 5000 && gps.charsProcessed() < 10) 54 { 55 Serial.println(F("No 56 GPS detected: check wiring.")); 57 while(true); 58 } 59} 60 61void displayInfo() 62{ 63 64 Serial.print(F("Location: ")); 65 if (gps.location.isValid()) 66 { 67 68 Serial.print(gps.location.lat(), 6); 69 Serial.print(F(",")); 70 Serial.print(gps.location.lng(), 71 6); 72 } 73 else 74 { 75 Serial.print(F("INVALID")); 76 } 77 78 79 Serial.print(F(" Date/Time: ")); 80 if (gps.date.isValid()) 81 { 82 Serial.print(gps.date.month()); 83 84 Serial.print(F("/")); 85 Serial.print(gps.date.day()); 86 Serial.print(F("/")); 87 88 Serial.print(gps.date.year()); 89 } 90 else 91 { 92 Serial.print(F("INVALID")); 93 94 } 95 96 Serial.print(F(" ")); 97 if (gps.time.isValid()) 98 { 99 if 100 (gps.time.hour() < 10) Serial.print(F("0")); 101 Serial.print(gps.time.hour()); 102 103 Serial.print(F(":")); 104 if (gps.time.minute() < 10) Serial.print(F("0")); 105 106 Serial.print(gps.time.minute()); 107 Serial.print(F(":")); 108 if (gps.time.second() 109 < 10) Serial.print(F("0")); 110 Serial.print(gps.time.second()); 111 Serial.print(F(".")); 112 113 if (gps.time.centisecond() < 10) Serial.print(F("0")); 114 Serial.print(gps.time.centisecond()); 115 116 } 117 else 118 { 119 Serial.print(F("INVALID")); 120 } 121 122 Serial.println(); 123} 124
Github
https://github.com/mikalhart/TinyGPSPlus
Downloadable files
wiring VK16E GPS module
wiring VK16E GPS module
wiring VK16E GPS module
wiring VK16E GPS module
Comments
Only logged in users can leave comments