├── GPSLogger.ino ├── LICENSE └── README.md /GPSLogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | GPS Logger 3 | 4 | Simple project which logs data from GPS module (NEO 6M) into SD card. 5 | Locations are stored as file (yyyyMMdd.txt) and the file will contain one row per location (dd.MM.yyyy HH:mm:ss lat,lon). 6 | Location is stored for each interval given as configuration variable 'frequency'. 7 | 8 | Led modes: 9 | continuous -> error 10 | blinking -> looking for location 11 | off -> everything ok 12 | 13 | Connecting modules: 14 | Pin3 -> GPS-module-RX 15 | Pin4 -> GPS-module-TX 16 | Pin10 -> SD-module-SS 17 | Pin11/MOSI -> SD-module-MOSI 18 | Pin12/MISO -> SD-module-MISO 19 | Pin13/SCK -> SD-module-SCK 20 | 21 | Dependency(TinyGPS++ library): http://arduiniana.org/libraries/tinygpsplus/ 22 | 23 | created Apr 2017 24 | by CheapskateProjects 25 | 26 | --------------------------- 27 | The MIT License (MIT) 28 | 29 | Copyright (c) 2017 CheapskateProjects 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 32 | 33 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | // Pins used for communicating with GPS module 44 | static const int RXPin = 4, TXPin = 3; 45 | // Status led 46 | static const int GpsLedPin = 9; 47 | // Baud rate of your GPS module (usually 4800 or 9600) 48 | static const uint32_t GPSBaud = 9600; 49 | // How frequently should we save current location (milliseconds) 50 | static const unsigned long frequency = 5000; 51 | 52 | // gps object 53 | TinyGPSPlus gps; 54 | // true when we have found location since last restart and file has been opened 55 | boolean opened = false; 56 | // current data file 57 | File dataFile; 58 | // file name 59 | String fileName; 60 | // timestamp of previous location capture. Used to check if we should save this location or skip it 61 | unsigned long previous=0; 62 | // The serial connection to the GPS device 63 | SoftwareSerial ss(RXPin, TXPin); 64 | 65 | void setup() 66 | { 67 | ss.begin(GPSBaud); 68 | pinMode(GpsLedPin, OUTPUT); 69 | digitalWrite(GpsLedPin, LOW); 70 | 71 | if (!SD.begin(10)) 72 | { 73 | digitalWrite(GpsLedPin, HIGH); 74 | while(true); 75 | } 76 | } 77 | 78 | void loop() 79 | { 80 | // If we have data, decode and log the data 81 | while (ss.available() > 0) 82 | if (gps.encode(ss.read())) 83 | logInfo(); 84 | 85 | // Test that we have had something from GPS module within first 10 seconds 86 | if (millis() > 10000 && gps.charsProcessed() < 10) 87 | { 88 | // Set error led 89 | digitalWrite(GpsLedPin, HIGH); 90 | // Wiring error so stop trying 91 | while(true); 92 | } 93 | } 94 | 95 | // Help function to pad 0 prefix when valus < 10 96 | void printIntValue(int value) 97 | { 98 | if(value < 10) 99 | { 100 | dataFile.print(F("0")); 101 | } 102 | dataFile.print(value); 103 | } 104 | 105 | // Log current info if we have valid location 106 | void logInfo() 107 | { 108 | // Wait until we have location locked! 109 | if(!gps.location.isValid()) 110 | { 111 | digitalWrite(GpsLedPin, HIGH); 112 | delay(20); 113 | digitalWrite(GpsLedPin, LOW); 114 | return; 115 | } 116 | 117 | if(!opened) 118 | { 119 | // When we first get something to log we take file name from that time 120 | fileName = ""; 121 | fileName += gps.date.year(); 122 | if(gps.date.month() < 10) fileName += "0"; 123 | fileName += gps.date.month(); 124 | if(gps.date.day() < 10) fileName += "0"; 125 | fileName += gps.date.day(); 126 | fileName += ".txt"; 127 | opened = true; 128 | } 129 | 130 | // Show that everything is ok 131 | digitalWrite(GpsLedPin, LOW); 132 | 133 | if(millis() - previous > frequency) 134 | { 135 | previous = millis(); 136 | // Write data row (dd.MM.yyyy HH:mm:ss lat,lon) 137 | dataFile = SD.open(fileName, FILE_WRITE); 138 | printIntValue(gps.date.day()); 139 | dataFile.print(F(".")); 140 | printIntValue(gps.date.month()); 141 | dataFile.print(F(".")); 142 | dataFile.print(gps.date.year()); 143 | dataFile.print(F(" ")); 144 | printIntValue(gps.time.hour()); 145 | dataFile.print(F(":")); 146 | printIntValue(gps.time.minute()); 147 | dataFile.print(F(":")); 148 | printIntValue(gps.time.second()); 149 | dataFile.print(F(" ")); 150 | dataFile.print(gps.location.lat(), 6); 151 | dataFile.print(F(",")); 152 | dataFile.print(gps.location.lng(), 6); 153 | dataFile.println(); 154 | dataFile.close(); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 CheapskateProjects 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GPSLogger 2 | GPS Logger 3 | 4 | Simple project which logs data from GPS module (NEO 6M) into SD card. 5 | Locations are stored as file (yyyyMMdd.txt) and the file will contain one row per location (dd.MM.yyyy HH:mm:ss lat,lon). 6 | Location is stored for each interval given as configuration variable 'frequency'. 7 | 8 | Led modes: 9 | continuous - error 10 | blinking - looking for location 11 | off - everything ok 12 | 13 | Connecting modules: 14 | Pin3 - GPS-module-RX 15 | Pin4 - GPS-module-TX 16 | Pin10 - SD-module-SS 17 | Pin11/MOSI - SD-module-MOSI 18 | Pin12/MISO - SD-module-MISO 19 | Pin13/SCK - SD-module-SCK 20 | 21 | Dependency(TinyGPS++ library): 22 | 23 | 24 | --------------------------------------------------------------------------------