Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Higher datarate. Fix for CRC issues #33

Merged
merged 4 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Getting time and date using Ublox commands
By: davidallenmann
SparkFun Electronics
Date: April 16th, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example shows how to query a Ublox module for the current time and date. We also
turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic
dramatically.

Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!

Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106

Hardware Connections:
Plug a Qwiic cable into the GPS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/

#include <Wire.h> //Needed for I2C to GPS

#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
SFE_UBLOX_GPS myGPS;

long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.

void setup()
{
Serial.begin(500000); //Increase serial speed to maximize
while (!Serial)
; //Wait for user to open terminal
Serial.println("SparkFun Ublox Example");

Wire.begin();
Wire.setClock(400000);

if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1)
;
}

myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGPS.saveConfiguration(); //Save the current settings to flash and BBR

//myGPS.enableDebugging(); //Enable debug messages over Serial (default)

myGPS.setNavigationFrequency(10); //Set output to 10 times a second
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
Serial.print("Current update rate:");
Serial.println(rate);

}

void loop()
{
//Query module only every second. Doing it more often will just cause I2C traffic.
//The module only responds when a new position is available
if (millis() - lastTime > 10)
{
lastTime = millis(); //Update the timer

long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));

long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));

byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);

Serial.print(myGPS.getYear());
Serial.print("-");
Serial.print(myGPS.getMonth());
Serial.print("-");
Serial.print(myGPS.getDay());
Serial.print(" ");
Serial.print(myGPS.getHour());
Serial.print(":");
Serial.print(myGPS.getMinute());
Serial.print(":");
Serial.print(myGPS.getSecond());
Serial.print(".");
Serial.print(myGPS.getNanosecond());

Serial.println();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Getting time and date using Ublox commands
By: Nathan Seidle
SparkFun Electronics
Date: April 16th, 2019
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example shows how to use the Millisecond and Nanosecond output as well as increase the
I2C speed (100 to 400kHz), and serial output (115200 to 500kbps).

Leave NMEA parsing behind. Now you can simply ask the module for the datums you want!

Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
NEO-M8P RTK: https://www.sparkfun.com/products/15005
SAM-M8Q: https://www.sparkfun.com/products/15106

Hardware Connections:
Plug a Qwiic cable into the GPS and a BlackBoard
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
Open the serial monitor at 115200 baud to see the output
*/

#include <Wire.h> //Needed for I2C to GPS

#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
SFE_UBLOX_GPS myGPS;

long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.

void setup()
{
Serial.begin(500000); //Increase serial speed to maximize
while (!Serial)
; //Wait for user to open terminal
Serial.println("SparkFun Ublox Example");

Wire.begin();
Wire.setClock(400000);

if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
Serial.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1)
;
}

myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)

//myGPS.enableDebugging(); //Enable debug messages over Serial (default)

myGPS.setNavigationFrequency(10); //Set output to 10 times a second
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
Serial.print("Current update rate:");
Serial.println(rate);

myGPS.saveConfiguration(); //Save the current settings to flash and BBR

pinMode(2, OUTPUT); //For debug capture
digitalWrite(2, HIGH);
}

void loop()
{
//Query module very often to get max update rate
if (millis() - lastTime > 10)
{
lastTime = millis(); //Update the timer

long latitude = myGPS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

long longitude = myGPS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));

long altitude = myGPS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));

byte SIV = myGPS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);

Serial.print(" ");
Serial.print(myGPS.getYear());
Serial.print("-");
Serial.print(myGPS.getMonth());
Serial.print("-");
Serial.print(myGPS.getDay());
Serial.print(" ");
Serial.print(myGPS.getHour());
Serial.print(":");
Serial.print(myGPS.getMinute());
Serial.print(":");
Serial.print(myGPS.getSecond());
Serial.print(".");
//Pretty print leading zeros
int mseconds = myGPS.getMillisecond();
if(mseconds < 100) Serial.print("0");
if(mseconds < 10) Serial.print("0");
Serial.print(mseconds);

Serial.print(" nanoSeconds: ");
Serial.print(myGPS.getNanosecond());

Serial.println();
}
}
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ getDay KEYWORD2
getHour KEYWORD2
getMinute KEYWORD2
getSecond KEYWORD2
getMillisecond KEYWORD2
getNanosecond KEYWORD2

getHPPOSLLH KEYWORD2
getTimeOfWeek KEYWORD2
Expand Down
78 changes: 70 additions & 8 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
while (bytesAvailable)
{
_i2cPort->beginTransmission(_gpsI2Caddress);
_i2cPort->write(0xFF); //0xFF is the register to read general NMEA data from
_i2cPort->write(0xFF); //0xFF is the register to read data from
if (_i2cPort->endTransmission(false) != 0) //Send a restart command. Do not release bus.
return (false); //Sensor did not ACK

Expand All @@ -253,12 +253,28 @@ boolean SFE_UBLOX_GPS::checkUbloxI2C()
if (bytesToRead > I2C_BUFFER_LENGTH)
bytesToRead = I2C_BUFFER_LENGTH;

TRY_AGAIN:

_i2cPort->requestFrom((uint8_t)_gpsI2Caddress, (uint8_t)bytesToRead);
if (_i2cPort->available())
{
for (uint16_t x = 0; x < bytesToRead; x++)
{
process(_i2cPort->read()); //Grab the actual character and process it
uint8_t incoming = _i2cPort->read(); //Grab the actual character

//Check to see if the first read is 0x7F. If it is, the module is not ready
//to respond. Stop, wait, and try again
if (x == 0)
{
if (incoming == 0x7F)
{
debugPrintln("Module not ready with data");
delay(5); //In logic analyzation, the module starting responding after 1.48ms
goto TRY_AGAIN;
}
}

process(incoming); //Process this valid character
}
}
else
Expand Down Expand Up @@ -479,15 +495,40 @@ void SFE_UBLOX_GPS::processUBX(uint8_t incoming, ubxPacket *incomingUBX)
{
if (_printDebug == true)
{
_debugSerial->print("Received: ");
_debugSerial->print("Size: ");
_debugSerial->print(incomingUBX->len);
_debugSerial->print(" Received: ");
printPacket(incomingUBX);
}
incomingUBX->valid = true;
processUBXpacket(incomingUBX); //We've got a valid packet, now do something with it
}
else
{
debugPrintln("Checksum failed. Response too big?");
if (_printDebug == true)
{
debugPrintln("Checksum failed. Response too big?");

digitalWrite(2, LOW);
delay(10);
digitalWrite(2, HIGH);

_debugSerial->print("Received: ");
printPacket(incomingUBX);

_debugSerial->print("Size: ");
_debugSerial->print(incomingUBX->len);
_debugSerial->print(" checksumA: ");
_debugSerial->print(incomingUBX->checksumA);
_debugSerial->print(" checksumB: ");
_debugSerial->print(incomingUBX->checksumB);

_debugSerial->print(" rollingChecksumA: ");
_debugSerial->print(rollingChecksumA);
_debugSerial->print(" rollingChecksumB: ");
_debugSerial->print(rollingChecksumB);
_debugSerial->println();
}
}
}
else //Load this byte into the payload array
Expand Down Expand Up @@ -529,12 +570,14 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
//Parse various byte fields into global vars
constexpr int startingSpot = 0; //fixed value used in processUBX

gpsMillisecond = extractLong(0) % 1000; //Get last three digits of iTOW
gpsYear = extractInt(4);
gpsMonth = extractByte(6);
gpsDay = extractByte(7);
gpsHour = extractByte(8);
gpsMinute = extractByte(9);
gpsSecond = extractByte(10);
gpsNanosecond = extractLong(16); //Includes milliseconds

fixType = extractByte(20 - startingSpot);
carrierSolution = extractByte(21 - startingSpot) >> 6; //Get 6th&7th bits of this byte
Expand All @@ -554,6 +597,7 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
moduleQueried.gpsHour = true;
moduleQueried.gpsMinute = true;
moduleQueried.gpsSecond = true;
moduleQueried.gpsNanosecond = true;

moduleQueried.all = true;
moduleQueried.longitude = true;
Expand Down Expand Up @@ -1307,7 +1351,7 @@ uint8_t SFE_UBLOX_GPS::getMonth(uint16_t maxWait)
return (gpsMonth);
}

//Get the current year
//Get the current day
uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
{
if (moduleQueried.gpsDay == false)
Expand All @@ -1316,7 +1360,7 @@ uint8_t SFE_UBLOX_GPS::getDay(uint16_t maxWait)
return (gpsDay);
}

//Get the current year
//Get the current hour
uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
{
if (moduleQueried.gpsHour == false)
Expand All @@ -1325,7 +1369,7 @@ uint8_t SFE_UBLOX_GPS::getHour(uint16_t maxWait)
return (gpsHour);
}

//Get the current year
//Get the current minute
uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
{
if (moduleQueried.gpsMinute == false)
Expand All @@ -1334,7 +1378,7 @@ uint8_t SFE_UBLOX_GPS::getMinute(uint16_t maxWait)
return (gpsMinute);
}

//Get the current year
//Get the current second
uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
{
if (moduleQueried.gpsSecond == false)
Expand All @@ -1343,6 +1387,24 @@ uint8_t SFE_UBLOX_GPS::getSecond(uint16_t maxWait)
return (gpsSecond);
}

//Get the current millisecond
uint16_t SFE_UBLOX_GPS::getMillisecond(uint16_t maxWait)
{
if (moduleQueried.gpsiTOW == false)
getPVT();
moduleQueried.gpsiTOW = false; //Since we are about to give this to user, mark this data as stale
return (gpsMillisecond);
}

//Get the current nanoseconds - includes milliseconds
int32_t SFE_UBLOX_GPS::getNanosecond(uint16_t maxWait)
{
if (moduleQueried.gpsNanosecond == false)
getPVT();
moduleQueried.gpsNanosecond = false; //Since we are about to give this to user, mark this data as stale
return (gpsNanosecond);
}

//Get the latest Position/Velocity/Time solution and fill all global variables
boolean SFE_UBLOX_GPS::getPVT(uint16_t maxWait)
{
Expand Down
Loading