Instructables

Geo Data Logger: Arduino+GPS+SD+Accelerometer to log, time-stamp, and geo-tag sensor data

Featured

Step 6: A PLAIN GPS LOGGER TO INTERFACE WITH GOOGLE EARTH

Picture of A PLAIN GPS LOGGER TO INTERFACE WITH GOOGLE EARTH
For those who want to use this prototype as a generic GPS logger, to track your path, just upload the Arduino code below. This program will generate raw NMEA RMC sentences to file GPS.LOG on the SD card without any sensor data.

We can then Import the GPS.LOG file into Google Earth and generate maps overlaid with your logged track points.  Please refer to my LS20031 GPS tutorial on how to import a raw GPS NMEA log files into Google Earth. 

You can also import this NMEA log file into Excel as a comma-delimited text file and reformat it for GPSvisualizer.com to draw maps with track points and more.  More on this in the next sections. 

// ================ START PROGRAM =====================

/*

PROJECT: A Plain GPS Logger

DEVELOPER:  Hazim Bitar (techbitar at gmail dot com)

DESCRIPTION:  This program logs GPS location information wherever you go and saves to the SD card as raw NMEA data to be imported into Google Earth. 

LICENSE:      I am placing this code in the public domain

DATE:         NOV 17, 2012

*/
#include <SD.h>
#define LED 8           // status LED for SD operations
#define BUFF_MAX 100    // size of GPS & SD buffers

File GPSlog;

void setup()
{
  Serial.begin(4800); // The LS20031 GPS receiver must be set to 4800 for program to work

  pinMode(10, OUTPUT);   // Per SD library notes, pin 10 must be set to output
  pinMode(LED, OUTPUT);

  if (!SD.begin(4)) {        // SD card detected?
    digitalWrite(LED,LOW);   // turn off staus LED if SD detection fails
    return;
  }
  else   digitalWrite(LED, HIGH); // turn on LED if SD detection is OK

  GPSlog = SD.open("GPS.log", O_CREAT | O_WRITE);  // open/append to a file GPS.log
  if (!GPSlog) {               // test if file can be opened
    digitalWrite(LED,LOW);     // turn off status LED if file open fails
    return;
  }
  else digitalWrite(LED, HIGH);  // turn on status LED if file open is OK
}

void loop()
{
  char inBuffer[BUFF_MAX];    // buffer used to read NMEA lines from GPS
  byte outBuffer[BUFF_MAX];   // buffer used to write NMEA lines to SD card
  int sizeBuffer = 0;        // counter of how many chars per line

  while (Serial.available()>0)  // if serial data available from GPS
  {        
    sizeBuffer = Serial.readBytesUntil('\n', inBuffer, BUFF_MAX);  // read one NMEA line from GPS until end of line
    for (int i = 0; i < BUFF_MAX; i++) outBuffer[i] = inBuffer[i];   // create CSV file on SD
    int j = 0;
    if (GPSlog) {
      GPSlog.write(outBuffer, sizeBuffer);  // write GPS NMEA output to SD
      GPSlog.print("\r\n");    
      GPSlog.flush();
      digitalWrite(LED, HIGH);  // Keep LED on so long as SD logging is working.
    }
    else {
      // if the file didn't open, turn LED off
      digitalWrite(LED, LOW);  // turn LED off if writing to file fails
    }
  }
}
// ================ END PROGRAM =====================
 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!