Search code examples
arduinogpsesp32arduino-c++

GPS module on ESP32 not giving valid logs


Environments

  • osx
  • esp32
  • vscode
  • platformio

I am working on an ESP32 module with this GPS module (very similar except the one I have has "ublox" logo on it - bought about 2 years ago).

#include <Arduino.h>
#include <HardwareSerial.h>
#include <TinyGPS++.h>

TinyGPSPlus gps;
HardwareSerial SerialGPS(2);

void setup() {
  Serial.begin(115200);          // RX  TX
  SerialGPS.begin(9600, SERIAL_8N1, 16, 17);
}

void loop() {

  Serial.println("------------");
  Serial.print("available(): ");
  Serial.println(SerialGPS.available());
  Serial.println("------------");
  while (SerialGPS.available() > 0) {
    char c = SerialGPS.read();
    Serial.print(c);
    gps.encode(c);
  }
  Serial.println();

  if (gps.location.isValid()) {
    Serial.print("LAT=");
    Serial.println(gps.location.lat(), 6);
    Serial.print("LONG=");
    Serial.println(gps.location.lng(), 6);
    Serial.print("ALT=");
    Serial.println(gps.altitude.meters());
  } else {
    Serial.println("not valid");
  }

  delay(1000);
}

I took it outside and ran it for over 15 mins, and I see the data are still invalid.

------------
available(): 195
------------
$GPRMC,023424.00,V,,,,,,,051120,,,N*79
$GPVTG,,,,,,,,,N*30
$GPGGA,023424.00,,,,,0,00,99.99,,,,,,*65
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,00*79
$GPGLL,,,,,023424.00,V,N*49

not valid
------------
available(): 195
------------
$GPRMC,023425.00,V,,,,,,,051120,,,N*78
$GPVTG,,,,,,,,,N*30
$GPGGA,023425.00,,,,,0,00,99.99,,,,,,*64
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
$GPGSV,1,1,00*79
$GPGLL,,,,,023425.00,V,N*48

not valid

Since I see letters coming in, I don't think TX and RX are mixed up. I am giving it 5V (although not exactly sure if it should be 3.3v or 5v).

How can I get valid GPS data coming in from this module?


Solution

  • To me it looks like the GPS module is sending data properly, but hasn't got any available. It could still be looking for satellites. You can try printing the number of available ones, and simply wait longer:

    Add the following lines to your program before your if statement:

    Serial.println(gps.time.value()); // Raw time in HHMMSSCC format (u32)
    Serial.println(gps.time.hour()); // Hour (0-23) (u8)  
    Serial.println(gps.time.minute()); // Minute (0-59) (u8)  
    Serial.println(gps.time.second()); // Second (0-59) (u8)   
    Serial.println(gps.satellites.value()); // Number of satellites in use (u32)
    

    The first step should be that your GPS module gets the correct time. This should happen after a few minutes, probably. Then the number of satellites in use should go up, and you should start getting valid results once a reasonable number of satellites are found. I tend to get a reading with probably about 9 satellites.

    If it is a cheaper module it might take a while, especially from a cold start.