Hello,
Is there any way, using the Sparkfun ublox arduino library, to get the current time from the satellite? If so, which command would I use?
Thank you,
–Tim
Hello,
Is there any way, using the Sparkfun ublox arduino library, to get the current time from the satellite? If so, which command would I use?
Thank you,
–Tim
Hi Tim.
Curiously there isn’t a function in the library to get the time, but GPS time is included in the NEMA data coming from the GPS module. You’d need to route that NEMA data through a library like [TinyGPS++ to extract the time and date from the NEMA data and display it. Sadly, I don’t have any code examples for using TinyGPS++ with the UBlox library over I2C but you could probably modify the Example1_BasicNEMARead sketch to do this.
If you’re connecting to your GPS via serial, the TinyGPS++ examples will work as is.](GitHub - mikalhart/TinyGPSPlus: A new, customizable Arduino NMEA parsing library)
Thanks Chris,
Your post got me thinking. There is an example (example 2) which shows how to parse NMEA sentences included in the MicroNMEA library. I found that getMonth, getDay etc are all supported. I’m off to the races now. Thank you again!
Here’s the code:
#include <Wire.h> //Needed for I2C to GPS
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
SFE_UBLOX_GPS myGPS;
#include <MicroNMEA.h> //http://librarymanager/All#MicroNMEA
char nmeaBuffer[100];
MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer));
void setup()
{
Serial.begin(115200);
Serial.println("SparkFun Ublox Example");
Wire.begin();
if (myGPS.begin() == false)
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1);
}
}
void loop()
{
myGPS.checkUblox(); //See if new data is available. Process bytes as they come in.
if(nmea.isValid() == true)
{
long latitude_mdeg = nmea.getLatitude();
long longitude_mdeg = nmea.getLongitude();
int month = nmea.getMonth();
int day = nmea.getDay();
int year = nmea.getYear();
int hour = nmea.getHour();
int minute = nmea.getMinute();
int second = nmea.getSecond();
Serial.print("Latitude (deg): ");
Serial.println(latitude_mdeg / 1000000., 6);
Serial.print("Longitude (deg): ");
Serial.println(longitude_mdeg / 1000000., 6);
Serial.print("Date: ");
Serial.print(month);
Serial.print("/");
Serial.print(day);
Serial.print("/");
Serial.print(year);
Serial.println("");
Serial.print("Time: ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.print(second);
Serial.println("");
}
else
{
Serial.print("No Fix - ");
Serial.print("Num. satellites: ");
Serial.println(nmea.getNumSatellites());
}
delay(250); //Don't pound too hard on the I2C bus
}
//This function gets called from the SparkFun Ublox Arduino Library
//As each NMEA character comes in you can specify what to do with it
//Useful for passing to other libraries like tinyGPS, MicroNMEA, or even
//a buffer, radio, etc.
void SFE_UBLOX_GPS::processNMEA(char incoming)
{
//Take the incoming char from the Ublox I2C port and pass it on to the MicroNMEA lib
//for sentence cracking
nmea.process(incoming);
}
Ah! I didn’t even look at the microNEMA library to see if that had a function you could use.
Glad you found a solution.
Happy Hacking!