Skip to content

Update #5

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 10 commits into from
Apr 6, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void loop()
Serial.print(myGNSS.getMinute());
Serial.print(":");
Serial.print(myGNSS.getSecond());
Serial.print(".");
Serial.print(myGNSS.getNanosecond());
Serial.print(" nanoseconds: ");
Serial.print(myGNSS.getNanosecond()); // Nanoseconds can be negative

myGNSS.flushPVT();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void loop()
Serial.print("0");
Serial.print(mseconds);

Serial.print(" nanoSeconds: ");
Serial.print(" nanoseconds: ");
Serial.print(myGNSS.getNanosecond());

Serial.println();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Getting Unix Epoch Time and micros using u-blox commands
By: UT2UH
Date: March 30th, 2021
Date: March 31th, 2021
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

Expand Down Expand Up @@ -69,8 +69,11 @@ void loop()
// 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: ");
uint32_t epoch = myGNSS.getUnixEpoch();
Serial.print("Unix Epoch rounded: ");
Serial.print(epoch, DEC);
epoch = myGNSS.getUnixEpoch(us);
Serial.print(" Exact Unix Epoch: ");
Serial.print(epoch, DEC);
Serial.print(" micros: ");
Serial.println(us, DEC);
Expand Down Expand Up @@ -105,4 +108,4 @@ void loop()
Serial.print(F(" SIV: "));
Serial.println(SIV);
}
}
}
91 changes: 91 additions & 0 deletions examples/Example26_End/Example26_End.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Demonstrating how to use "end"
By: Paul Clark
SparkFun Electronics
Date: April 1st, 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 use the end function.
End will stop all automatic message processing and free (nearly) all used RAM.
The file buffer is deleted (if it exists).

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;

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);
}

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

myGNSS.end(); // Call end now just because we can - it won't do much as we haven't used any automatic messages
}

void loop()
{
// Allocate 128 bytes for file storage - this checks that issue #20 has been resolved
// Allocating only 128 bytes will let this code run on the ATmega328P
// If your processor has plenty of RAM, you can increase this to something useful like 16KB
myGNSS.setFileBufferSize(128);

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

Serial.print(F("The file buffer size is: "));
Serial.println(myGNSS.getFileBufferSize());

// Request Position, Velocity, Time
// RAM will be allocated for PVT message processing
// getPVT will return true is fresh PVT data was received and processed
if (myGNSS.getPVT())
{
long latitude = myGNSS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

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

long altitude = myGNSS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.println(F(" (mm)"));
}

// Calling end will free the RAM allocated for file storage and PVT processing
// Calling end is optional. You can comment the next line if you want to.
myGNSS.end();
}
106 changes: 106 additions & 0 deletions examples/Example27_MultipleRates/Example27_MultipleRates.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Configuring the GNSS to produce multiple messages at different rates
By: Paul Clark
SparkFun Electronics
Date: April 1st, 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 output multiple messages at different rates:
PVT is output every second;
POSECEF is output every five seconds;
VELNED is output every ten seconds.

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;

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);
}

myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGNSS.setMeasurementRate(1000); //Produce a measurement every 1000ms
myGNSS.setNavigationRate(1); //Produce a navigation solution every measurement

myGNSS.setAutoPVTrate(1); //Tell the GNSS to send the PVT solution every measurement
myGNSS.setAutoNAVPOSECEFrate(5); //Tell the GNSS to send each POSECEF solution every 5th measurement
myGNSS.setAutoNAVVELNEDrate(10); //Tell the GNSS to send each VELNED solution every 10th measurement
//myGNSS.saveConfiguration(); //Optional: Save the current settings to flash and BBR
}

void loop()
{
// Calling getPVT returns true if there actually is a fresh navigation solution available.
if (myGNSS.getPVT())
{
long latitude = myGNSS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);

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

long altitude = myGNSS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.println(F(" (mm)"));
}

// Calling getNAVPOSECEF returns true if there actually is a fresh position solution available.
if (myGNSS.getNAVPOSECEF())
{
Serial.print(F("ecefX: "));
Serial.print((float)myGNSS.packetUBXNAVPOSECEF->data.ecefX / 100.0, 2); // convert ecefX to m

Serial.print(F(" ecefY: "));
Serial.print((float)myGNSS.packetUBXNAVPOSECEF->data.ecefY / 100.0, 2); // convert ecefY to m

Serial.print(F(" ecefZ: "));
Serial.print((float)myGNSS.packetUBXNAVPOSECEF->data.ecefZ / 100.0, 2); // convert ecefY to m
Serial.println(F(" (m)"));

myGNSS.flushNAVPOSECEF(); //Mark all the data as read/stale so we get fresh data next time
}

// Calling getNAVVELNED returns true if there actually is fresh velocity data available.
if (myGNSS.getNAVVELNED())
{
Serial.print(F("velN: "));
Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velN / 100.0, 2); // convert velN to m/s

Serial.print(F(" velE: "));
Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velE / 100.0, 2); // convert velE to m/s

Serial.print(F(" velD: "));
Serial.print((float)myGNSS.packetUBXNAVVELNED->data.velD / 100.0, 2); // convert velD to m/s
Serial.println(F(" (m/s)"));

myGNSS.flushNAVVELNED(); //Mark all the data as read/stale so we get fresh data next time
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ void loop()
Serial.print("Lat (deg): ");
Serial.print(lat_int); // Print the integer part of the latitude
Serial.print(".");
Serial.print(lat_frac); // Print the fractional part of the latitude
printFractional(lat_frac, 9); // Print the fractional part of the latitude with leading zeros
Serial.print(", Lon (deg): ");
Serial.print(lon_int); // Print the integer part of the latitude
Serial.print(".");
Serial.println(lon_frac); // Print the fractional part of the latitude
printFractional(lon_frac, 9); // Print the fractional part of the latitude with leading zeros
Serial.println();

// Now define float storage for the heights and accuracy
float f_ellipsoid;
Expand Down Expand Up @@ -152,3 +153,20 @@ void loop()
Serial.println(f_accuracy, 4); // Print the accuracy with 4 decimal places
}
}

// Pretty-print the fractional part with leading zeros - without using printf
// (Only works with positive numbers)
void printFractional(int32_t fractional, uint8_t places)
{
if (places > 1)
{
for (uint8_t place = places - 1; place > 0; place--)
{
if (fractional < pow(10, place))
{
Serial.print("0");
}
}
}
Serial.print(fractional);
}
Loading