Hi im having a load of grief converting a string that i have parsed from the serial port into a float number that i can do math with.
The project is an FPV antenna tracker, im hooking a gps to a pro mini, then sending the gps infor over my radio control link's serial passthru port. (its there, why not use it). on the ground another arduino will take the serial data, toss out any errors, do math, and point the antenna in the correct position.
It's also a project to help teach me to code.
I'm now at a stumbling block, i thought there would be an easy way to convert the numbers in my string into a float (lat lon, so needs 6sig fig).
Ive eventually done a work around so i only need a large integer rather than a float.
heres my code, any ideas what im doing wrong (P.S this is just me testing the parsing before adding it to my main function)
// testing ways to parse serial input for the gps tracker
#include <stdlib.h>
#include <string>
int lat, lon, check;
float flat, flon;
int alt;
String latStream, lonStream, altStream, checkStream;
void setup(){
Serial.begin(9600);
delay(50);
Serial.println("Serial Parsing test");
}
//@lat?lon$alt%check#
String inputStream;
void loop(){
if (Serial.available()){
//@lat?lon$alt%check#
//@52126411?1247066$100%53373477# TEST values, input in serial monitor
char c;
while(c != '@'){
Serial.println(c);
c = Serial.read();
delay(500);
}
latStream = Serial.readStringUntil('?');
lonStream = Serial.readStringUntil('
);
altStream = Serial.readStringUntil('%');
checkStream = Serial.readStringUntil('#');
lat = latStream.toInt();
lon = lonStream.toInt();
alt = altStream.toInt();
check = checkStream.toInt();
flat = lat / 1000000;
flon = lon / 1000000;
Serial.println("strings");
Serial.println(latStream);
Serial.println(lonStream);
Serial.println(altStream);
Serial.println(checkStream);
Serial.println();
Serial.println("integers");
Serial.println(lat);
Serial.println(lon);
Serial.println(alt);
Serial.println(check);
Serial.println();
Serial.println("floats");
Serial.println(flat);
Serial.println(flon);
Serial.println(alt);
Serial.println(check);
Serial.println();
}
}