Need Help Sorting Asset Tracker coordinates From Serial on Arduino




So the lat & lon floats are local objects.
Would there be a way to make those global?

I have

GeoLoc phoneLoc; = lat;
  phoneLoc.lon =  lon;
    driveTo(phoneLoc, GPS_STREAM_TIMEOUT);

but that is in void loop and I’m getting an error that says lat & lon not declared…
Geoloc is a

struct GeoLoc {
  float lat;
  float lon;

Sorry for all the questions by the way. :wink:


How much precision do you need? Looks like there is some limitations to the toFloat() function.

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.

What was the error when you used atof()?



cannot convert 'String' to 'const char*' for argument '1' to 'double atof(const char*)'


No problem with all the questions :slight_smile:

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: = -1.0;


void loop() {
  // put your main code here, to run repeatedly:





 float phoneLat = 0;//b
    float phoneLon = 0;
    float roverLat = 0;
    float roverLon = 0; 

are global but I assign the lat and lon to them in geoBearing…

Ok now I did it like this and it compiles fine. The error for atof remains…

void loop() {
  // put your main code here, to run repeatedly:
String latt = Serial2.readStringUntil(',');
char comma =;
String lonn = Serial2.readStringUntil('\r');
char carrageReturn =;
char lineFeed =;
GeoLoc phoneLoc; = latt;
  phoneLoc.lon =  lonn;
    driveTo(phoneLoc, GPS_STREAM_TIMEOUT);




roverLat = atof(latt.c_str());
roverLon = atof(lonn.c_str());



Thanks a million it compiles!! :grinning:



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!!:grin: )!

Thanks again, Jack


@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 :slight_smile: 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 project on this if you’re interested.


To post a video, you can upload to any video service (e.g. YouTube) and post a link.


@ScruffR @cermak @kennethlimcp @bko

I don’t have a youtube channel but I did post it on my Instagram


Hello Jack.D. Can you help me. I rework robot follow me. But, It is not work. :(((((((((((
I edited auth of me, and I replace PAM 7Q by NEO 6M.
Can you help me.
my facebook:
Thank you !