How much precision do you need? Looks like there is some limitations to the toFloat() function.
toFloat()
Converts a valid String to a float. The input string should start with a digit. If the string contains non-digit characters, the function will stop performing the conversion. For example, the strings “123.45”, “123”, and “123fish” are converted to 123.45, 123.00, and 123.00 respectively. Note that “123.456” is approximated with 123.46. Note too that floats have only 6-7 decimal digits of precision and that longer strings might be truncated.
This code is being compiled in the Arduino, right?
Any global variables should be placed above all functions and the setup() and loop() functions.
struct GeoLoc {
float lat;
float lon;
};
GeoLoc phoneLoc;
void setup() {
// put your setup code here, to run once:
phoneLoc.lat = -1.0;
}
void loop() {
// put your main code here, to run repeatedly:
}
I just wanted to thank you for your help! The follow me robot works very well!!! It follows the location of my phone with a bluetooth shield, compass, and gps. I wouldn’t have been able to do it without your help with the coordinates. (I’m 13, so I’m really happy I got this to work out!! )!
@JackD12 - Glad to be of help. The community deserves the thanks, really. I have been learning quite a lot and still not be doing things very efficiently. I like to get things working first, then look for improvements. If I can optimize on the way, great.
Do you have future plans for your project? Maybe share a bit more of this in the #project-share part of the forum?
If you need or want another task, we used a bunch of Strings that could potentially lead to heap fragmentation and ultimately lead to sporadic resets/panics. At your leisure, you can read some other posts about heap fragmentation and improve that section of code.
There is more than one way to pull lat and long out of the serial stream of data.
General re-design:
Use a fixed length character buffer to collect the data via Serial
Upon discovery of the line feed parse the buffer
Send that information on to where it needs for the robot to do its work
Empty the buffer for the next lat/lon
If you are happy with the way it is, that is just fine too. Programming is a puzzle that keeps on giving (and taking at times). If you do take on this task, make a backup of your current code since it is working This way, you can always go back to a known working version.
Sorry, I can’t find a way to upload a video to this. I have my asset tracker, Adafruit bluefruit shield, logic level shifter, motor driver, and Adafruit9DOF breakout board for the compass.
The chassis you see here is my prototype chassis. I’m doing a Hackster.io project on this if you’re interested.