Hi,
I am trying to determine the direction and distance to a destination using this gps module :
I am getting values for distance and direction in the Serial monitor, but when I turn the gps shield/ antenna, the direction values do not change. I would like the direction/ distance values to change as you walk away/towards the destination. The code is below.
Thanks for your help
#include <SoftwareSerial.h>
#include "TinyGPS.h"
/* 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 3(rx) and 4(tx).
*/
TinyGPS gps;
SoftwareSerial ss(3, 4);
float dest_latitude = 42.24313;
float dest_longitude = -83.002853;
float distance;
float distanceangle;
void setup()
{
Serial.begin(115200);
Serial.print("Simple TinyGPS library v. ");
Serial.println(TinyGPS::library_version());
Serial.println("by Mikal Hart");
Serial.println();
}
void loop()
{
ss.begin(9600);
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)
{
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print("LAT=");
Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(" LON=");
Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(" SAT=");
Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
Serial.print(" PREC=");
Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
gps.stats(&chars, &sentences, &failed);
Serial.print(" CHARS=");
Serial.print(chars);
Serial.print(" SENTENCES=");
Serial.print(sentences);
Serial.print(" CSUM ERR=");
Serial.println(failed);
float course = (TinyGPS::course_to(flat, flon, dest_latitude, dest_longitude ));
float distance = (TinyGPS::distance_between(flat, flon, dest_latitude, dest_longitude ));
Serial.print ("course is ");
Serial.print (course);
Serial.print ( "distance is ");
Serial.print (distance);
}
}
As I turn the module/antenna, this is what I get in the Serial monitor
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=295151 SENTENCES=1843 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=295631 SENTENCES=1845 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=295907 SENTENCES=1847 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=296183 SENTENCES=1849 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=296459 SENTENCES=1851 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=296735 SENTENCES=1853 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=297215 SENTENCES=1855 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=297491 SENTENCES=1857 CSUM ERR=59
course is 74.56distance is 543.55LAT=42.241828 LON=-83.009216 SAT=8 PREC=100 CHARS=297767 SENTENCES=1859 CSUM ERR=59
As you can see, the values don't change