I have interfaced my ESP32 with a ublox GPS tracker NEO-6M module. It is continuously printing NULL on the serial monitor and even after 10 to 15seconds it prints NULL. What could be the possible reason and how to rectify that? Here is the code:
#include <TinyGPSPlus.h>
// The TinyGPSPlus object
TinyGPSPlus gps;
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid()){
Serial.print("Lat: ");
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print("Lng: ");
Serial.print(gps.location.lng(), 6);
Serial.println();
}
else
{
Serial.print(F("INVALID"));
}
}
void updateSerial()
{
// delay(500);
while (Serial.available())
{
Serial2.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while (Serial2.available())
{
Serial.write(Serial2.read());//Forward what Software Serial received to Serial Port
}
}
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
delay(3000);
}
void loop() {
updateSerial();
while (Serial2.available() > 0)
if (gps.encode(Serial2.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while (true);
}
}
Thanks all for your support. I have found the answer. The GPS-NEO6M tracker works in open air environment not indoor or basement area. So I have used this code, gave it 5V power using Arduino UNO and still it was not connected to the satellite but as soon as I took it to the open air keeping the tracker position towards the sky, it started showing date and time and showed GPS coordinates in 3 to 4 minutes. The code that I used and is working finally is shown below: