Trying to test GPS

Hi there,

Now I have Blynk up and running finally (thanks to Pete [https://community.blynk.cc/u/peteknight/] for that!) I’m trying out a few things here and then and have become a little stumped on something so was wondering if someone could possibly help at all?

I have a very simple Blynk App on my iPhone which is using the GPS Stream widget to send GPS data across to my Arduino. This all works fine and I can use some simple code to retrieve that data :

BLYNK_WRITE(V2)
{
  GpsParam gps(param);
  // Print 6 decimal places for Lat
  Serial.println(gps.getLat(), 7);
  Serial.println(gps.getLon(), 7);
  Serial.println(gps.getAltitude(), 2);
  Serial.println(gps.getSpeed(), 2);
}

Apologies that I’ve just shown part of the code instead of the whole Arduino sketch but everything else is working fine and just need help with this little bit.

I then added the Map widget to the iPhone App (map is set to V10) and tried to do this :

BLYNK_WRITE(V2)
{
  GpsParam gps(param);
  // Print 6 decimal places for Lat
  Serial.println(gps.getLat(), 7);
  Serial.println(gps.getLon(), 7);
  Serial.println(gps.getAltitude(), 2);
  Serial.println(gps.getSpeed(), 2);

  /* Send GPS Co-ordinates to Blynk to show on map in iPhone App */
  int index = 0;
  float lat = (gps.getLat(), 7);
  float lon = (gps.getLon(), 7);
  Serial.println("LATITUDE = ");
  Serial.println(lat);
  Serial.println("LONGITUDE = ");
  Serial.println(lon);
  Blynk.virtualWrite(V10, index, lat, lon, "value");
}

When I check the serial monitor (after uploading the sketch to my board) I get this shown :


LATITUDE = 
7
LONGITUDE = 
7

instead of the same lat and lon values that showed up in the code that just prints them to the monitor. Not too sure where the 7 is coming from as I thought it would set them to the same as what the GPS widget is spitting out?

I know this is a bit of a silly example as I’m literally sending the GPS data from my phone via the Blynk app to the Arduino and then (trying) to send the GPS values back again to the iPhone to display them on the map but once I get it all working I’d like to then obviously add a GPS module to the Arduino so that it can get GPS co-ordinates itself and send those off. This is just to see how it all works but I don’t seem to be able to get the data which is being sent from the App into a format that I can then send it back again.

Many thanks for any help with this.

Best wishes,

Mark

When you use the Serial.print command you can add an option comma followed by the number of decimal places that you want to be displayed. That’s what the ,7 bit of the command does.

You can’t use the same command when you assign a value to a variable, so this:

float lat = (gps.getLat(), 7);

is saying “create a float variable called lat and make it equal to 7”

Instead you should do this:

float lat = gps.getLat();
Serial.println(lat,7);

Also, if you ever wanted to use the value of lat outside of this function then you’d get an error message, because by declaring it within this function you’ve limited its scope to just that function.
If you declare it at the top of your code, then just use lat = gps.getLat() (without the preceding float part) then it’s value is available anywhere within your code.
This will be important to you when the values are coming from a GPS module and not from pin V2.

BTW, the GPS stream will very quickly munch through the battery on your iPhone :frowning:

Pete.

Hi Pete,

Thank you so much for the exceptionally fast reply again!

All working now using


Blynk.virtualWrite(V10, index, gps.getLat(), gps.getLon(), "value");

Thank you so much for the pointer there.

Best wishes,

Mark

1 Like