another working gps sketch tiny gps

Hi guys Ive tried the code above but as yet no luck.

however this works on my set up no logging as yet.
remember to wire tx rx to digital pins 3,2

[code]#include <NewSoftSerial.h>
#include <TinyGPS.h>
//#include <math.h>

/* This sample code demonstrates the normal use of a TinyGPS object.
It requires the use of NewSoftSerial, and assumes that you have a
9600-baud serial GPS device hooked up on pins 3(TX1) and 2(RX1).
*/

TinyGPS gps;
NewSoftSerial nss(2, 3);

void gpsdump(TinyGPS &gps);
bool feedgps();
void printFloat(double f, int digits = 2);
void SwapElements( long * nArray, long nFirst, long nSecond);
double DegtoRad(double deg); // This shall convert degree value to radians
void distance_calc(double lat1, double lon1, double lat2, double lon2, double *d);

int i = 0;
long arraylat[10]; // creates an array that can stores 10 elements
long arraylon[10];
long lat, lon, lat1, lon1, lat2, lon2;
unsigned long age;
const double EarthRadius = 6371; // Mean Earth radius is 6371km
#define GPS_Port Serial1

void setup()
{
Serial.begin(115200);
nss.begin(9600);

Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
Serial.println(“by Mikal Hart”);
Serial.println();
Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS));
Serial.println();
}

void loop()
{
bool newdata = false;
unsigned long start = millis();

// Every 2.5 seconds we print an update
while (millis() - start < 2500)
{
if (feedgps())

  newdata = true;

}

if (newdata)
{

Serial.println();
Serial.println("Acquired Data");
Serial.println("-------------");
gpsdump(gps);
Serial.println("-------------");
Serial.println();

/*right after printing out the gps data, call the function that fetches the gps position */
gps.get_position(&lat, &lon, &age);

/*store the latitude and longitude in their seperate temporary arrays */

arraylat[i] = lat;    
arraylon[i] = lon;

if( i > 0 ) // means there are atleast 2 points available in each array
{
    lat1 = arraylat[i];
    lon1 = arraylon[i];
    lat2 = arraylat[i-1];
    lon2 = arraylon[i-1];
  
    /*Calculate distance between two points*/
    double Distance;
    Serial.print(lat1); Serial.print("\t"); Serial.println(lon1);
    Serial.print(lat2); Serial.print("\t"); Serial.println(lon2);
    distance_calc(lat1, lon1, lat2, lon2, &Distance);
    Serial.print("Distance between two points is ");
    printFloat(Distance);
    Serial.println();
    
    /*Swap contents of array's first position and second position*/

    SwapElements(arraylat, (i-1), i);        
    SwapElements(arraylon, (i-1), i);        

    
}
else
{
    Serial.print("only one position available");
    i++;
}

}
}

void printFloat(double number, int digits)
{
// Handle negative numbers
if (number < 0.0)
{
Serial.print(’-’);
number = -number;
}

// Round correctly so that print(1.999, 2) prints as “2.00”
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;

number += rounding;

// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
Serial.print(int_part);

// Print the decimal point, but only if there are digits beyond
if (digits > 0)
Serial.print(".");

// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
Serial.print(toPrint);
remainder -= toPrint;
}
}

void gpsdump(TinyGPS &gps)
{
long lat, lon;
double lat1, lon1;
float flat, flon;
unsigned long age, date, time, chars;
int year;
byte month, day, hour, minute, second, hundredths;
unsigned short sentences, failed;

gps.get_position(&lat, &lon, &age);
Serial.print(“Lat/Long(10^-5 deg): \t”); Serial.print(lat); Serial.print(", “); Serial.print(lon);
Serial.print(”\t Fix age: "); Serial.print(age); Serial.println(“ms.”);

feedgps(); // If we don’t feed the gps during this long routine, we may drop characters and get checksum errors

gps.f_get_position(&flat, &flon, &age);
Serial.print(“Lat/Long(float): \t”); printFloat(flat, 5); Serial.print(", “); printFloat(flon, 5);
Serial.print(”\t Fix age: "); Serial.print(age); Serial.println(“ms.”);

feedgps(); // The idea behind TinyGPS is that you feed it characters that (usually) come in from a serial port.
// Like all serial applications, if you don’t read the port sufficiently often, you’ll lose characters.

gps.get_datetime(&date, &time, &age);
Serial.print("Date(ddmmyy): “); Serial.print(date); Serial.print(”\t Time(hhmmsscc): “); Serial.print(time);
Serial.print(” Fix age: "); Serial.print(age); Serial.println(“ms.”);

feedgps();

gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
Serial.print(“Date: “); Serial.print(static_cast(month)); Serial.print(”/”); Serial.print(static_cast(day)); Serial.print("/"); Serial.print(year);
Serial.print("\t\t Time: “); Serial.print(static_cast(hour)); Serial.print(”:"); Serial.print(static_cast(minute)); Serial.print(":"); Serial.print(static_cast(second)); Serial.print("."); Serial.print(static_cast(hundredths));
Serial.print("\t Fix age: "); Serial.print(age); Serial.println(“ms.”);

feedgps();

Serial.print(“Alt(cm): “); Serial.print(gps.altitude()); Serial.print(”\t\t Course(10^-2 deg): “); Serial.println(gps.course());
Serial.print(“Alt(float): “); printFloat(gps.f_altitude()); Serial.print(”\t Course(float): “); printFloat(gps.f_course()); Serial.println();
Serial.print(“Speed(10^-2 knots): “); Serial.print(gps.speed());Serial.print(”\t Speed(knots):”); printFloat(gps.f_speed_knots()); Serial.println();
Serial.print(“Speed(mph):”); printFloat(gps.f_speed_mph());Serial.print(”\t\t (mps):”); printFloat(gps.f_speed_mps()); Serial.print(”\t\t (kmph):”);
printFloat(gps.f_speed_kmph()); Serial.println();

feedgps();

gps.stats(&chars, &sentences, &failed);
Serial.print("Characters: “); Serial.print(chars); Serial.print(”\t sentences: “); Serial.print(sentences); Serial.print(”\t\t failed checksum: "); Serial.println(failed);
}

bool feedgps()
{
while (nss.available())
{
if (gps.encode(nss.read()))
nss.flush();
return true;
}
return false;
}

void SwapElements( long *nArray, long nFirst, long nSecond)
{
long nTemp = nArray[nFirst];
nArray[nFirst] = nArray[nSecond];
nArray[nSecond] = nTemp;
}

/*
This function takes a value in degrees and converts it into radians
Arguments:
double deg : the degree input
Returned values:
double rad : returns the input value in radian
*/

double DegtoRad(double deg)
{
double rad;
rad = deg*PI/180;
return rad;
}

/*
This is the Haversine function.It calculates the distance between two points given their latitude and longitude of the two points
The mean radius of the Earth is used for the calculation. Since the Earth is slightly spherical, the Earth’s radius varies when measuring
from different points on the Earth’s surface to its core.
Arguments:
double lat1 : latitude of first point
double lon1 : longitude of first point
double lat2 : latitude of second point
double lon2 : longitude of second point
Returned values:
double d : distance between two points in kilometers
*/
void distance_calc(double lat1, double lon1, double lat2, double lon2, double *d)
{
double Lat = (lat2-lat1);
double Lon = (lon2-lon1);
double dLat = DegtoRad(Lat);
double dLon = DegtoRad(Lon);
double a = sin(dLat/2) * sin(dLat/2) + cos(DegtoRad(lat1)) * cos(DegtoRad(lat2)) * sin(dLon/2) * sin(dLon/2);
double c = 2 * (atan2(sqrt(a), sqrt(1-a)));
// The atan2() function computes the principal value of the arc tangent of __y / __x, using the signs of both arguments to determine the quadrant of the return value.
// The returned value is in the range [-pi, +pi] radians.
*d = EarthRadius * c;

}

[/code]

Dear customer,

There is a demo code at GPS WIKI for SD logger.
seeedstudio.com/wiki/index.p … ed_Antenna

So you could use FAT16 libraries and a mini SD card.
But anyway, software is not support yet. So hope your device is work correct.

Thanks for your feedback.

Best regards,

Yuri