Can't display latitude and longitude using neo-6m gps module

Can someone help me, latitude and longitude don't even display on serial monitor. I'm just begginer in this project. I hope there's someone who can give me an idea.

#define BLYNK_TEMPLATE_ID "TMPL6WA-fgP6m"
#define BLYNK_TEMPLATE_NAME "prototype"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h
//#define USE_ESP32_DEV_MODULE
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_TTGO_T_OI

#include "BlynkEdgent.h"
#include <TinyGPS++.h>
#include <HardwareSerial.h>
//#include <WiFi.h>
#include <Wire.h>               
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> 
//#include <BlynkSimpleEsp32.h>

float latitude , longitude;
String  latitude_string , longitiude_string;

#define SCREEN_WIDTH 128 
#define SCREEN_HEIGHT 64  
#define BLYNK_PRINT Serial
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


WidgetMap myMap(V4); 
WiFiClient client;
TinyGPSPlus gps;
HardwareSerial SerialGPS(2);

void setup()
{
  Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  

 /* while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");             
  }
  Serial.println("");
  Serial.println("WiFi connected!");*/

  SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
 
  Blynk.virtualWrite(V0, "clr"); 
  BlynkEdgent.begin();
}

void loop() {
  while (SerialGPS.available() > 0) {
    if (gps.encode(SerialGPS.read()))
    {
      if (gps.location.isValid())
      {
        latitude = gps.location.lat();
        latitude_string = String(latitude , 6);
        longitude = gps.location.lng();
        longitiude_string = String(longitude , 6);
        Serial.print("Latitude = ");
        Serial.print(gps.location.lat(), 6);
        Serial.print("Longitude = ");
        Serial.print(gps.location.lng() , 6);
        
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 20);
  display.println("Latitude: ");
  display.setCursor(45, 20);
  display.print(gps.location.lat(), 6);
  display.setCursor(0, 40);
  display.print("Longitude: ");
  display.setCursor(45, 40);
  display.print(gps.location.lng() , 6);
 
        Blynk.virtualWrite(V0, 1, latitude, longitude, "Location");
        display.display();
      }
     delay(1000);
     Serial.println();  
    }
  }  
  BlynkEdgent.run();
}


Test the display and your connections to it using an example sketch from the Adafruit_SSD1306 library.

Welcome to the forum

Why did you start your topic in the Covid19 category of the forum ?

It has been moved to a more relevant category

This project is related to Covid19. That's correct, isn't it, @mikemike06 ? You would not have posted it in that section otherwise! It's always a good idea to give the forum an idea of what the project is about, and by posting in that section, we now know it's related to Covid19.

I'm sorry. It's my first time posting in this forum

Please be more careful in future

Actually, this is not my final code . I just want to know how to get latitude and longitude. Is it posible to display latitude and longitude in serial monitor?

I already change it sir, thank you for your concern.

Sure it is.

Is the GPS outdoors with a good view of the sky ?

Is the GPS LED blinking ?

You should tell us that. Your code already appears to be doing that. Can you see anything in serial monitor or not?

Don't forget to set the correct serial baud rate in serial monitor!

yes , it is blinking but there's nothing in serial monitor .

Run this bit of code, it should copy the GPS characters to the serial monitor;


#include <HardwareSerial.h>
HardwareSerial SerialGPS(2);

void loop()
{
  while (SerialGPS.available())
  {
    Serial.write(SerialGPS.read());
  }
}

void setup()
{
  SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
  Serial.begin(115200);
  Serial.println();
  Serial.println("GPS_Echo_Hardware_Serial Starting");
}

So there is nothing at all showing in the Serial monitor ?

Whats on the display ?

this is the output

This is the only output that in serial monitor

You can use the TinyGPS++ library to achieve your desired outcome. Also if you are working with GPS modules for the first time, you can follow the Complete guide to interface and program the NEO-6M GPS module with Arduino.

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