Loading...
Pages: [1]   Go Down
Author Topic: GPS Project UNO Rev3, Ethernet Shield, Parallax PMB-648 G- coordinates and speed  (Read 485 times)
0 Members and 1 Guest are viewing this topic.
Florida
Offline Offline
Newbie
*
Karma: 0
Posts: 20
All of our code is Y3K compliant!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
I've been working on a GPS project and got it working this morning. Took a couple of days to get the data on the SD correct, but it's working pretty well now. I am only using the Longitude, Latitude and Speed. Will probably continue to mess with the colors of the indicators that show up on the mapping site.

Here is the GPS (bought from Radio Shack)
[url=http://www.parallax.com/Store/Sensors/CompassGPS/tabid/173/ProductID/644/List/0/Default.aspx?SortField=ProductName,ProductName]http://www.parallax.com/Store/Sensors/CompassGPS/tabid/173/ProductID/644/List/0/Default.aspx?SortField=ProductName,ProductName[/url]

Here is the web site for mapping the output file.
[url=http://www.gpsvisualizer.com/]http://www.gpsvisualizer.com/[/url]

YouTube video of the end result.
[url=http://youtu.be/uMXIvraLj6o]http://youtu.be/uMXIvraLj6o[/url]

[code#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <SD.h>

#define LED 8           // status LED for SD operations

/* This sample code demonstrates the normal use of a TinyGPS object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 2(rx) and 3(tx)...but 3 is not used.
*/
int name = 0;
TinyGPS gps;
SoftwareSerial ss(2, 3);

void setup()
{
  Serial.begin(9600);
  ss.begin(4800);
 
    Serial.println("Name  Speed     Latitude  Longitude");
    Serial.println("----- --------  --------  ----------");
//  Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version());
//  Serial.println("by Mikal Hart");
//  Serial.println();
//  Modified by rfbase December 28, 2012

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 status LED if SD detection fails
     return;
   }
   else   digitalWrite(LED, HIGH); // turn on LED if SD detection is OK
  }

void loop()
{

  bool newData = false;
  unsigned long chars;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
  while (ss.available())
    {
      char c = ss.read();
      // Serial.write(c); // uncomment this line if you want to see the GPS data flowing
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }
  }

  if (newData)
  {
    name = name + 1;
//    Serial.println("Speed     Latitude  Longitude");
    float flat, flon;
    unsigned long age;
    unsigned long speed;
    gps.f_get_position(&flat, &flon, &age);
    // returns speed in 100ths of a knot
    speed = gps.speed()*.01; // multiply the 100th down to proper value
    Serial.print("Waypoint");
    Serial.print(name);
    Serial.print(" - ");
    Serial.print(speed == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : speed, 0);
    Serial.print("(mph),");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(",");
    Serial.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
  File dataFile = SD.open("GPS2.csv", FILE_WRITE);
  if (dataFile) {
    dataFile.print("Waypoint");
    dataFile.print(name);
    dataFile.print(" - ");
    dataFile.print(speed == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : speed, 0);
    dataFile.print("(mph),");
    dataFile.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    dataFile.print(",");
    dataFile.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    dataFile.close();
  } 
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening GPS2.csv");
  }
 }
}

Sample output to the SD Card

name,latitude,longitude
Waypoint13 - 5.00(mph),26.355909,-80.246040
Waypoint14 - 7.00(mph),26.355930,-80.246063
Waypoint15 - 9.00(mph),26.356019,-80.246109
Waypoint16 - 15.00(mph),26.356079,-80.246139
Waypoint17 - 17.00(mph),26.356149,-80.246177
Waypoint18 - 19.00(mph),26.356330,-80.246246
Waypoint19 - 21.00(mph),26.356430,-80.246276
Waypoint20 - 21.00(mph),26.356529,-80.246299
Waypoint21 - 20.00(mph),26.356729,-80.246322
Waypoint22 - 17.00(mph),26.356809,-80.246330
Waypoint23 - 14.00(mph),26.356889,-80.246330
Waypoint24 - 10.00(mph),26.356990,-80.246330
« Last Edit: December 28, 2012, 04:39:13 pm by rfbase » Logged

Pages: [1]   Go Up
Print
 
Jump to: