88 lines
2.9 KiB
Arduino
88 lines
2.9 KiB
Arduino
/*
|
|
Read NMEA sentences over I2C using u-blox module SAM-M8Q, NEO-M8P, etc
|
|
By: Nathan Seidle
|
|
SparkFun Electronics
|
|
Date: August 22nd, 2018
|
|
License: MIT. See license file for more information but you can
|
|
basically do whatever you want with this code.
|
|
|
|
This example reads the NMEA characters over I2C and pipes them to MicroNMEA
|
|
This example will output your current long/lat and satellites in view
|
|
|
|
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
|
|
|
|
For more MicroNMEA info see https://github.com/stevemarple/MicroNMEA
|
|
|
|
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
|
|
Go outside! Wait ~25 seconds and you should see your lat/long
|
|
*/
|
|
|
|
#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;
|
|
|
|
#include <MicroNMEA.h> //http://librarymanager/All#MicroNMEA
|
|
char nmeaBuffer[100];
|
|
MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer));
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
Serial.println("SparkFun u-blox Example");
|
|
|
|
Wire.begin();
|
|
|
|
if (myGNSS.begin() == false)
|
|
{
|
|
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
|
|
while (1);
|
|
}
|
|
|
|
myGNSS.setProcessNMEAMask(SFE_UBLOX_FILTER_NMEA_ALL); // Make sure the library is passing all NMEA messages to processNMEA
|
|
|
|
myGNSS.setProcessNMEAMask(SFE_UBLOX_FILTER_NMEA_GGA); // Or, we can be kind to MicroNMEA and _only_ pass the GGA messages to it
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
myGNSS.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();
|
|
|
|
Serial.print("Latitude (deg): ");
|
|
Serial.println(latitude_mdeg / 1000000., 6);
|
|
Serial.print("Longitude (deg): ");
|
|
Serial.println(longitude_mdeg / 1000000., 6);
|
|
|
|
nmea.clear(); // Clear the MicroNMEA storage to make sure we are getting fresh data
|
|
}
|
|
else
|
|
{
|
|
Serial.println("Waiting for fresh data");
|
|
}
|
|
|
|
delay(250); //Don't pound too hard on the I2C bus
|
|
}
|
|
|
|
//This function gets called from the SparkFun u-blox 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_GNSS::processNMEA(char incoming)
|
|
{
|
|
//Take the incoming char from the u-blox I2C port and pass it on to the MicroNMEA lib
|
|
//for sentence cracking
|
|
nmea.process(incoming);
|
|
}
|