Hi all,
I am having trouble with getting the correct distance between my coordinates.
I am using the 1Sheeld to get the coordinates from my phone and an adafruit breakout (gps module) to get the coordinates of the device.
When I upload the code and turn everything on the serial monitor gives me an output of around 5,000 which is the same value as if one of the coordinates is (0,0). Despite me testing the code and knowing that individually the 1Sheeld and gps module give the correct coordinates, when I put it together the 1Sheeld produces an output of (0,0).
Summarising, the bulk of the code works, but I am unable to get the 1Sheeld to output the correct coordinates when combined with the code. If anyone has any idea how to fix this it would be greatly appreciated
#include <OneSheeld.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
Adafruit_GPS GPSM(&mySerial);
#define GPSECHO false
#define CUSTOM_SETTINGS
#define INCLUDE_GPS_SHIELD
boolean usingInterrupt = false;
void useInterrupt(boolean);
float lat_gps,long_gps,lat_gpsm,long_gpsm;
float lonR1,lonR2,latR1,latR2;
char charlat [10];
char charlon [10];
char readings [80];
float dlat,dlon,a,e,d;
float R = 6371.00;
float toDegrees = 57.295779;
char sb[10];
void setup()
{
{ OneSheeld.begin();
}
Serial.begin(115200);
GPSM.begin(9600);
GPSM.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPSM.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(F(PMTK_Q_RELEASE));
}
SIGNAL(TIMER0_COMPA_vect) {
char c = GPSM.read();
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v) {
if (v) {
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
uint32_t timer = millis();
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if (! usingInterrupt) {
char c = GPSM.read();
if (GPSECHO)
if (c) Serial.print(c);
}
if (GPSM.newNMEAreceived()) {
if (!GPSM.parse(GPSM.lastNMEA()))
return;
}
lat_gpsm = GPSM.latitudeDegrees;
long_gpsm = GPSM.longitudeDegrees;
{
lat_gps = GPS.getLatitude();
long_gps = GPS.getLongitude();
}
{ void calcDist();
lonR1 = long_gps*(PI/180);
lonR2 = long_gpsm*(PI/180);
latR1 = lat_gps*(PI/180);
latR2 = lat_gpsm*(PI/180);
dlon = lonR2 - lonR1;
dlat = latR2 - latR1;}
a = (sq(sin(dlat/2))) + cos(latR1) * cos(latR2) * (sq(sin(dlon/2)));
e = 2 * atan2(sqrt(a), sqrt(1-a)) ;
d = R * e;
Serial.print ( d );
}