this little Programm should calculate the direction in degree based on GPS data.
The main part reading Serial and convert it to float works well.
In the function directiongrad() the distLat and distLong works correct too.
These contains the distance in meters for the Lat and Long in GPS.
But then in Line 53 the calculation is wrong.
But in the End, for every number I tried until yet, I get NotANumber as error.
Maybe someone see my mistake
Just post the code - don't make people download it.
void setup() {
 Serial.begin(9600);
}
void loop() {
 char inputCharserial = 0;
 String inputstrserial;
 while (Serial.available() > 0 && inputCharserial != '\n') {
  inputCharserial = Serial.read();
  inputstrserial = inputstrserial + inputCharserial;
 }
 if (inputstrserial != "")
 {
  String inputstrserial1 = inputstrserial;
  String inputstrserial2 = inputstrserial;
  String inputstrserial3 = inputstrserial;
  String inputstrserial4 = inputstrserial;
  inputstrserial1.remove(inputstrserial1.indexOf(" "));
  inputstrserial2.remove(0, inputstrserial2.indexOf(" ") + 1);
  inputstrserial2.remove(inputstrserial2.indexOf(" "));
  inputstrserial3.remove(0, inputstrserial3.indexOf(" ") + 1);
  inputstrserial3.remove(0, inputstrserial3.indexOf(" ") + 1);
  inputstrserial3.remove(inputstrserial3.indexOf(" "));
  inputstrserial4.remove(0, inputstrserial4.indexOf(" ") + 1);
  inputstrserial4.remove(0, inputstrserial4.indexOf(" ") + 1);
  inputstrserial4.remove(0, inputstrserial4.indexOf(" ") + 1);
  float lat1 = inputstrserial1.toFloat();
  float lat2 = inputstrserial2.toFloat();
  float long1 = inputstrserial3.toFloat();
  float long2 = inputstrserial4.toFloat();
  Serial.println(directiongrad( lat1, lat2, long1, long2 ));
 }
 delay(100);
}
float directiongrad (float disgpsLat0, float disgpsLat, float disgpsLong0, float disgpsLong)
{
 float distLat = abs(disgpsLat0 - disgpsLat) * 111194.9;
 float distLong = 111194.9 * abs(disgpsLong0 - disgpsLong) * cos(radians((disgpsLat0 + disgpsLat) / 2));
 float deg = acos( (distLat / distLong) ) * 57.29577951;
 return deg;
}
Maybe GIGO applies - what values are you inputting?
It would behoove you to derive your "magic numbers" in the code, along with some comments. You have two of them, 111194.9 and 57.29577951. Whatever you did on your pocket calculator, you can do in C++.