Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

READING ULTIMATE GPS
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

READING ULTIMATE GPS

by JoonasH on Wed Aug 05, 2020 9:40 am

Hi all, I'm working on a project to log GPS data and sensor data with the GPS timestamp at 2 Hz. I'm using an ESP32 HUZZAH and the Ultimate GPS FeatherWing. I'm a little new to this and just found myself lost trying to read out the milliseconds from the GPS timestamp.

Here's code similar to what I'm trying to do, taken from ' GPS_HardwareSerial_Parsing' in the Adafruit GPS sketch examples. I've already increased the baud rate to 38400 and the refresh rate to 2 Hz beforehand. I'm getting complete NMEA sentences (without fix because I'm inside):

$GPGGA,133049.703,,,,,0,00,,,M,,M,,*70
$GPRMC,133049.703,V,,,,,0.00,0.00,050820,,,N*4A

$GPGGA,133050.203,,,,,0,00,,,M,,M,,*7D
$GPRMC,133050.203,V,,,,,0.00,0.00,050820,,,N*47




Code: Select all | TOGGLE FULL SIZE
// Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or FeatherWing)
//
// This code shows how to listen to the GPS module via polling. Best used with
// Feathers or Flora where you have hardware Serial and no interrupt


#include <Adafruit_GPS.h>

// what's the name of the hardware serial port?
#define GPSSerial Serial1

// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);

// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false

uint32_t timer = millis();

void setup()
{

  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- [ALREADY CHANGED TO 38400]
  GPS.begin(38400);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_2HZ); // 1 Hz update rate

  delay(1000);

}

void loop() // run over and over again
{
  // read data from the GPS in the 'main loop'
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) Serial.print(c);
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trying to print out data
    Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }

  // approximately every 0.5 seconds or so, print out the current stats
  if (millis() - timer > 500) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");
    if (GPS.hour < 10) { Serial.print('0'); }
    Serial.print(GPS.hour, DEC); Serial.print(':');
    if (GPS.minute < 10) { Serial.print('0'); }
    Serial.print(GPS.minute, DEC); Serial.print(':');
    if (GPS.seconds < 10) { Serial.print('0'); }
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    if (GPS.milliseconds < 10) {
      Serial.print("00");
    } else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
      Serial.print("0");
    }
    Serial.println(GPS.milliseconds);

  }
}


This is some of the output I'm getting:

Time: 13:30:48.10623
Time: 13:30:49.11123
Time: 13:30:49.11623
Time: 13:30:50.12123


The milliseconds don't seem to be incrementing correctly and I'm not exactly sure why this is happening. Can someone explain what's going on and how I could get the correct timestamp? I've read the tutorials and checked the forum but I still haven't figured it out.

Thanks!

JoonasH
 
Posts: 3
Joined: Wed Aug 05, 2020 9:22 am

Re: READING ULTIMATE GPS

by mikeysklar on Wed Aug 05, 2020 5:49 pm

Those milliseconds look like they are at 500ms intervals as the code specifies. What was your specific concern about how they look?

Code: Select all | TOGGLE FULL SIZE
Time: 13:30:48.10623
Time: 13:30:49.11123
Time: 13:30:49.11623
Time: 13:30:50.12123


Code: Select all | TOGGLE FULL SIZE
 // approximately every 0.5 seconds or so, print out the current stats
  if (millis() - timer > 500) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");

mikeysklar
 
Posts: 1655
Joined: Mon Aug 01, 2016 8:10 pm

Re: READING ULTIMATE GPS

by JoonasH on Wed Aug 05, 2020 6:49 pm

Hi Mikey,
So that means that the last 3 digits of the 5 are the actual milliseconds? Where do the first two come from?
I'd like to have the raw files formatted correctly since I want to directly import the files into a video overlay program. I guess I could remove the leading two digits, unless there's some significance to them?

JoonasH
 
Posts: 3
Joined: Wed Aug 05, 2020 9:22 am

Re: READING ULTIMATE GPS

by mikeysklar on Thu Aug 06, 2020 10:50 am

You got the right idea with just saving the last three digits are those the milliseconds. The GPS.milliseconds var is not being reset so it just keeps on climbing probably for ease of use with the millis() timer. I would just use sprintf to meet your three digit needs.

mikeysklar
 
Posts: 1655
Joined: Mon Aug 01, 2016 8:10 pm

Re: READING ULTIMATE GPS

by JoonasH on Thu Aug 06, 2020 4:27 pm

Thanks a lot! This was exactly the info I needed

JoonasH
 
Posts: 3
Joined: Wed Aug 05, 2020 9:22 am

Re: READING ULTIMATE GPS

by saraTU on Tue Aug 11, 2020 12:25 pm

Hi,
I use direct connection of my GPS ultimate to TX/RX of my stm32 L452RE nucleo board to bypass mcu and at 9600BR I got some random square. this means My module is malfunctioned?

saraTU
 
Posts: 4
Joined: Fri Jul 31, 2020 5:23 am

Re: READING ULTIMATE GPS

by mikeysklar on Tue Aug 11, 2020 1:52 pm

@saraTU,

Sounds like a baud rate setting if you are getting extended characters.

Please open a new thread for your issue.

mikeysklar
 
Posts: 1655
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.