GPS module GY-NEO6MV2 not working

Hello, i am working on a project where i use an arduino mega, a sim800l module and a GPS module. When i tested each part on its own, they worked but when i put then together in a code they dont work. I am basically trying to use gps module for location if i am outside and if i am in a building to use the sim800l module but the gps doesnt seem to work. Even if i am using it outside it send only the location from the SIM800l module, the location from the gps doesnt seem to work(i tested the gps with another code and it worked tho). The wiring its correct, i tested them but i dont know to make it work. Can you please help me? This is what i tried :

void loop()
{

  while (Serial2.available() > 0) 
  {
    gps.encode(Serial2.read());
    if (gps.location.isUpdated())
    {
      // Latitude in degrees (double)
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      lat_gps = gps.location.lat();
      sprintf(Latitude_GPS_char,"%.6f",lat_gps);
      
      Latitude_GPS = String(Latitude_GPS_char);

      // Longitude in degrees (double)
      Serial.print("Longitude= ");
      Serial.println(gps.location.lng(), 6);
      lon_gps = gps.location.lng();
      sprintf(Longitude_GPS_char,"%.6f",lon_gps);
      
      Longitude_GPS = String(Longitude_GPS_char);
    }
  

    responce = "";
    if ( (Latitude_GPS!="") && (Longitude_GPS!="") )
    {
      Serial.println("Latitude: " + String(Latitude_GPS) + "\tLongitude: " + String(Longitude_GPS));
      url = "script.google.com/macros/s/" + Script_ID + "/exec?value1=" + String(Latitude_GPS) + "&value2=" + String(Longitude_GPS);
    }
    else
    {
      Serial1.println("AT+CLBS=1,1"); delay(5000); //Request for location data 
      while (Serial1.available()) 
      {
        char letter = Serial1.read();
        responce = responce + String(letter); //Store the location information in string responce
        delay(1000); 
      }

      Serial.print("Result Obtained as:");   Serial.print(responce); Serial.println("*******");
      prepare_message(); delay(1000); //use prepare_message funtion to prepare the link with the obtained LAT and LONG co-ordinates 

      Serial.println("Latitude: " + Latitude + "\tLongitude: " + Longitude);
      url = "script.google.com/macros/s/" + Script_ID + "/exec?value1=" + Latitude + "&value2=" + Longitude;

    }`

Please state which Arduino you are using, and explain what "doesn't work" means.

What did you expect to happen, and what happened instead?

Note that the sprintf "%f" format specifier is not supported on many Arduinos.

I am using and arduino mega 2560, it only sends the location from the SIM800l module, the location from the GPS even tho it was supposed to work it doesnt register, the string is empty and it sends the location only from the sim800l.

By default the Mega 2560 does not support sprintf ("%f"). Use dtostrf() instead.

Avoid using String objects on Arduino, as they cause memory problems and program crashes.

1 Like

thank you

This is how i put them, do you know if Longitude_GPS = String(Longitude_GPS_char); works?

      // Latitude in degrees (double)
      Serial.print("Latitude= "); 
      Serial.print(gps.location.lat(), 6);
      lat_gps = gps.location.lat();

      dtostrf(lat_gps,9,6,Latitude_GPS_char);
      Latitude_GPS = String(Latitude_GPS_char);
      

      // Longitude in degrees (double)
      Serial.print("Longitude= ");
      Serial.println(gps.location.lng(), 6);
      lon_gps = gps.location.lng();
      
      dtostrf(lon_gps,9,6,Longitude_GPS_char);
      Longitude_GPS = String(Longitude_GPS_char);

shouldnt i have an error if the mega doesnt support sprintf()?

It supports sprintf out of the box, just not %f.

1 Like

You should not use String objects or functions on any ATmega. Strings are a waste of time, space and program reliability and are never necessary.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.