Skip to content

v2.0.4 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 30, 2021
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
107 changes: 107 additions & 0 deletions examples/Callbacks/CallbackExample6_RAWX/CallbackExample6_RAWX.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Configuring the GNSS to automatically send RXM RZWX reports over I2C and display them using a callback
By: Paul Clark
SparkFun Electronics
Date: March 11th, 2021
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example shows how to configure the u-blox GNSS to send RXM RAWX reports automatically
and access the data via a callback. No more polling!

Feel like supporting open source hardware?
Buy a board from SparkFun!
ZED-F9P RTK2: https://www.sparkfun.com/products/15136

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_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;

// Callback: newRAWX will be called when new RXM RAWX data arrives
// See u-blox_structs.h for the full definition of UBX_RXMRAWX_data_t
// _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMRAWXcallback
// / _____ This _must_ be UBX_RXM_RAWX_data_t
// | / _____ You can use any name you like for the struct
// | | /
// | | |
void newRAWX(UBX_RXM_RAWX_data_t ubxDataStruct)
{
Serial.println();

Serial.print(F("New RAWX data received. It contains "));
Serial.print(ubxDataStruct.header.numMeas); // Print numMeas (Number of measurements / blocks)
Serial.println(F(" data blocks:"));

for (uint8_t block = 0; block < ubxDataStruct.header.numMeas; block++) // For each block
{
Serial.print(F("GNSS ID: "));
if (ubxDataStruct.blocks[block].gnssId < 100) Serial.print(F(" ")); // Align the gnssId
if (ubxDataStruct.blocks[block].gnssId < 10) Serial.print(F(" ")); // Align the gnssId
Serial.print(ubxDataStruct.blocks[block].gnssId);
Serial.print(F(" SV ID: "));
if (ubxDataStruct.blocks[block].svId < 100) Serial.print(F(" ")); // Align the svId
if (ubxDataStruct.blocks[block].svId < 10) Serial.print(F(" ")); // Align the svId
Serial.print(ubxDataStruct.blocks[block].svId);

if (sizeof(double) == 8) // Check if our processor supports 64-bit double
{
// Convert prMes from uint8_t[8] to 64-bit double
// prMes is little-endian
double pseudorange;
memcpy(&pseudorange, &ubxDataStruct.blocks[block].prMes, 8);
Serial.print(F(" PR: "));
Serial.print(pseudorange, 3);

// Convert cpMes from uint8_t[8] to 64-bit double
// cpMes is little-endian
double carrierPhase;
memcpy(&carrierPhase, &ubxDataStruct.blocks[block].cpMes, 8);
Serial.print(F(" m CP: "));
Serial.print(carrierPhase, 3);
Serial.print(F(" cycles"));
}
Serial.println();
}
}

void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");

Wire.begin();

//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

myGNSS.disableUBX7Fcheck(); // RAWX data can legitimately contain 0x7F, so we need to disable the "7F" check in checkUbloxI2C

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

myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR

myGNSS.setNavigationFrequency(1); //Produce one solution per second (RAWX produces a _lot_ of data!)

myGNSS.setAutoRXMRAWXcallback(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
}

void loop()
{
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.

Serial.print(".");
delay(50);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
Getting Unix Epoch Time and micros using u-blox commands
By: UT2UH
Date: March 30th, 2021
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 u-blox module for the current time and date as Unix Epoch uint32_t type to avoid time.h dependency.
We also turn off the NMEA output on the I2C port. This decreases the amount of I2C traffic dramatically.

Note: this example works best on modules like the ZED_F9P. Modules like the ZOE_M8Q do not support confirmedTime.

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 GNSS 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 GNSS

#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;


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

void setup()
{
Serial.begin(115200);
while (!Serial)
; //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");

Wire.begin();

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

// Uncomment the next line if you need to completely reset your module
//myGNSS.factoryDefault(); delay(5000); // Reset everything and wait while the module restarts

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

Serial.println("Compare Unix Epoch given with reference one from https://www.epochconverter.com/");

}

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 > 1000)
{
lastTime = millis(); //Update the timer

// getUnixEpoch marks the PVT data as stale so you will get Unix time and PVT time on alternate seconds

uint32_t us; //microseconds returned by getUnixEpoch()
uint32_t epoch = myGNSS.getUnixEpoch(us);
Serial.print("Unix Epoch: ");
Serial.print(epoch, DEC);
Serial.print(" micros: ");
Serial.println(us, DEC);

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

Serial.print(" Time is ");
if (myGNSS.getTimeValid() == false)
{
Serial.print("not ");
}
Serial.print("valid ");
if (myGNSS.getConfirmedTime() == false)
{
Serial.print("but not ");
} else {
Serial.print("and ");
}
Serial.print("confirmed");

byte SIV = myGNSS.getSIV();
Serial.print(F(" SIV: "));
Serial.println(SIV);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
Demonstrate get/setMeasurementRate and get/setNavigationRate
By: Paul Clark
SparkFun Electronics
Date: March 30th, 2021
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

This example shows how to slow down the measurement and navigation rates.
This should run on any GNSS module but has only been tested on the ZED_F9P and ZOE_M8Q.

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 GNSS 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 GNSS

#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;

unsigned long lastTime = 0; //Simple local timer. Used to calc the message interval.

void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for user to open terminal
Serial.println("SparkFun u-blox Example");

Wire.begin();

//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial

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

// Uncomment the next line if you need to completely reset your module
//myGNSS.factoryDefault(); delay(5000); // Reset everything and wait while the module restarts

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

// Begin by printing the current measurement rate and navigation rate

uint16_t rate = myGNSS.getMeasurementRate(); //Get the measurement rate of this module
Serial.print("Current measurement interval (ms): ");
Serial.println(rate);

rate = myGNSS.getNavigationRate(); //Get the navigation rate of this module
Serial.print("Current navigation ratio (cycles): ");
Serial.println(rate);

// The measurement rate is the elapsed time between GNSS measurements, which defines the rate
// e.g. 100 ms => 10 Hz, 1000 ms => 1 Hz, 10000 ms => 0.1 Hz.
// Let's set the measurement rate (interval) to 5 seconds = 5000 milliseconds
if (myGNSS.setMeasurementRate(5000) == false)
{
Serial.println(F("Could not set the measurement rate. Freezing."));
while (1);
}

// setMeasurementRate will set i2cPollingWait to a quarter of the interval
// Let's override that so we can poll the module more frequently and avoid timeouts
myGNSS.setI2CpollingWait(25); // Set i2cPollingWait to 25ms

// The navigation rate is the ratio between the number of measurements and the number of navigation solutions
// e.g. 5 means five measurements for every navigation solution. Maximum value is 127
// Let's set the navigation rate (ratio) to 12 to produce a solution every minute
if (myGNSS.setNavigationRate(12) == false)
{
Serial.println(F("Could not set the navigation rate. Freezing."));
while (1);
}

// Another trick we can use is to mark the CFG RATE data as stale so we can be sure we read fresh data
myGNSS.packetUBXCFGRATE->moduleQueried.moduleQueried.all = 0; // Mark all of the CFG RATE data as stale

// Read and print the updated measurement rate and navigation rate

rate = myGNSS.getMeasurementRate(); //Get the measurement rate of this module
Serial.print("New measurement interval (ms): ");
Serial.println(rate);

rate = myGNSS.getNavigationRate(); //Get the navigation rate of this module
Serial.print("New navigation ratio (cycles): ");
Serial.println(rate);

lastTime = millis();
}

void loop()
{
// i2cPollingWait will prevent us from thrashing the I2C bus

if (myGNSS.getPVT()) //Check for new Position, Velocity, Time data. getPVT returns true if new data is available.
{
long latitude = myGNSS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

long longitude = myGNSS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);

//Calculate the interval since the last message
Serial.print(F(" Interval: "));
Serial.print(((float)(millis() - lastTime)) / 1000.0, 2);
Serial.print(F("s"));

Serial.println();

lastTime = millis(); //Update lastTime
}
}
11 changes: 11 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ setFileBufferSize KEYWORD2
extractFileBufferData KEYWORD2
fileBufferAvailable KEYWORD2
getMaxFileBufferAvail KEYWORD2
clearFileBuffer KEYWORD2
clearMaxFileBufferAvail KEYWORD2

getPortSettings KEYWORD2
setPortOutput KEYWORD2
Expand Down Expand Up @@ -369,6 +371,10 @@ logHNRPVT KEYWORD2

setNavigationFrequency KEYWORD2
getNavigationFrequency KEYWORD2
setMeasurementRate KEYWORD2
getMeasurementRate KEYWORD2
setNavigationRate KEYWORD2
getNavigationRate KEYWORD2

getGeometricDOP KEYWORD2
getPositionDOP KEYWORD2
Expand All @@ -391,8 +397,11 @@ getMinute KEYWORD2
getSecond KEYWORD2
getMillisecond KEYWORD2
getNanosecond KEYWORD2
getUnixEpoch KEYWORD2
getDateValid KEYWORD2
getTimeValid KEYWORD2
getConfirmedDate KEYWORD2
getConfirmedTime KEYWORD2
getFixType KEYWORD2
getGnssFixOk KEYWORD2
getDiffSoln KEYWORD2
Expand Down Expand Up @@ -602,3 +611,5 @@ SFE_UBLOX_GNSS_ID_BEIDOU LITERAL1
SFE_UBLOX_GNSS_ID_IMES LITERAL1
SFE_UBLOX_GNSS_ID_QZSS LITERAL1
SFE_UBLOX_GNSS_ID_GLONASS LITERAL1

DAYS_SINCE_MONTH LITERAL1
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun u-blox GNSS Arduino Library
version=2.0.3
version=2.0.4
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for I2C and Serial Communication with u-blox GNSS modules<br/><br/>
Expand Down
Loading