You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<SparkFun_u-blox_GNSS_Arduino_Library.h>//Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
48
+
SFE_UBLOX_GNSS myGNSS;
49
+
50
+
File myFile; //File that all GNSS data is written to
51
+
52
+
#definesdChipSelect CS //Primary SPI Chip Select is CS for the MicroMod Artemis Processor. Adjust for your processor if necessary.
53
+
54
+
#definesdWriteSize512// Write data to the SD card in blocks of 512 bytes
55
+
#definefileBufferSize16384// Allocate 16KBytes of RAM for UBX message storage
56
+
57
+
unsignedlong lastPrint; // Record when the last Serial print took place
58
+
unsignedlong bytesWritten = 0; // Record how many bytes have been written to SD card
59
+
60
+
voidsetup()
61
+
{
62
+
Serial.begin(115200);
63
+
while (!Serial); //Wait for user to open terminal
64
+
Serial.println("SparkFun u-blox Example");
65
+
66
+
pinMode(LED_BUILTIN, OUTPUT); // Flash LED_BUILTIN each time we write to the SD card
67
+
digitalWrite(LED_BUILTIN, LOW);
68
+
69
+
Wire.begin(); // Start I2C communication
70
+
71
+
#if defined(AM_PART_APOLLO3)
72
+
Wire.setPullups(0); // On the Artemis, we can disable the internal I2C pull-ups too to help reduce bus errors
73
+
#endif
74
+
75
+
while (Serial.available()) // Make sure the Serial buffer is empty
76
+
{
77
+
Serial.read();
78
+
}
79
+
80
+
Serial.println(F("Press any key to start logging."));
81
+
82
+
while (!Serial.available()) // Wait for the user to press a key
83
+
{
84
+
; // Do nothing
85
+
}
86
+
87
+
delay(100); // Wait, just in case multiple characters were sent
88
+
89
+
while (Serial.available()) // Empty the Serial buffer
90
+
{
91
+
Serial.read();
92
+
}
93
+
94
+
Serial.println("Initializing SD card...");
95
+
96
+
// See if the card is present and can be initialized:
97
+
if (!SD.begin(sdChipSelect))
98
+
{
99
+
Serial.println("Card failed, or not present. Freezing...");
100
+
// don't do anything more:
101
+
while (1);
102
+
}
103
+
Serial.println("SD card initialized.");
104
+
105
+
// Create or open a file called "PVT_NMEA.ubx" on the SD card.
106
+
// If the file already exists, the new data is appended to the end of the file.
107
+
myFile = SD.open("PVT_NMEA.ubx", FILE_WRITE);
108
+
if(!myFile)
109
+
{
110
+
Serial.println(F("Failed to create UBX data file! Freezing..."));
111
+
while (1);
112
+
}
113
+
114
+
//myGNSS.enableDebugging(); // Uncomment this line to enable lots of helpful GNSS debug messages on Serial
115
+
//myGNSS.enableDebugging(Serial, true); // Or, uncomment this line to enable only the important GNSS debug messages on Serial
116
+
117
+
//myGNSS.disableUBX7Fcheck(); // RAWX data can legitimately contain 0x7F. Uncomment this line to disable the "7F" check in checkUbloxI2C
118
+
119
+
// SD cards can occasionally 'hiccup' and a write takes much longer than usual. The buffer needs to be big enough
120
+
// to hold the backlog of data if/when this happens.
121
+
// getMaxFileBufferAvail will tell us the maximum number of bytes which the file buffer has contained.
122
+
myGNSS.setFileBufferSize(fileBufferSize); // setFileBufferSize must be called _before_ .begin
123
+
124
+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
125
+
{
126
+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing..."));
127
+
while (1);
128
+
}
129
+
130
+
// Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate
131
+
// This will (re)enable the standard NMEA messages too
132
+
// This will also disable any "auto" UBX messages that were enabled and saved by other examples and reduce the load on the I2C bus
133
+
//myGNSS.factoryDefault(); delay(5000);
134
+
135
+
myGNSS.setI2COutput(COM_TYPE_UBX | COM_TYPE_NMEA); //Set the I2C port to output both UBX and NMEA messages
136
+
137
+
//myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Optional: save (only) the communications port settings to flash and BBR
138
+
139
+
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second
140
+
141
+
myGNSS.setAutoPVT(true, false); // Enable automatic NAV PVT messages: without callback; without implicit update
142
+
myGNSS.logNAVPVT(); // Enable NAV PVT data logging
143
+
144
+
myGNSS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C, 1); // Ensure the GxGGA (Global positioning system fix data) message is enabled. Send every measurement.
145
+
myGNSS.enableNMEAMessage(UBX_NMEA_GSA, COM_PORT_I2C, 1); // Ensure the GxGSA (GNSS DOP and Active satellites) message is enabled. Send every measurement.
146
+
myGNSS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_I2C, 1); // Ensure the GxGSV (GNSS satellites in view) message is enabled. Send every measurement.
147
+
148
+
myGNSS.setNMEALoggingMask(SFE_UBLOX_FILTER_NMEA_ALL); // Enable logging of all enabled NMEA messages
149
+
//myGNSS.setNMEALoggingMask(SFE_UBLOX_FILTER_NMEA_GGA | SFE_UBLOX_FILTER_NMEA_GSA); // Or we can, for example, log only GxGGA & GxGSA and ignore GxGSV
150
+
151
+
Serial.println(F("Press any key to stop logging."));
152
+
153
+
lastPrint = millis(); // Initialize lastPrint
154
+
}
155
+
156
+
voidloop()
157
+
{
158
+
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
159
+
160
+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
161
+
162
+
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
163
+
164
+
while (myGNSS.fileBufferAvailable() >= sdWriteSize) // Check to see if we have at least sdWriteSize waiting in the buffer
165
+
{
166
+
digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN each time we write to the SD card
167
+
168
+
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
169
+
170
+
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
171
+
172
+
myFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card
// The GNSS identifiers of leap second event info source - used by UBX-NAV-TIMELS
476
+
enum sfe_ublox_ls_src_e
477
+
{
478
+
SFE_UBLOX_LS_SRC_DEFAULT,
479
+
SFE_UBLOX_LS_SRC_GLONASS,
480
+
SFE_UBLOX_LS_SRC_GPS,
481
+
SFE_UBLOX_LS_SRC_SBAS,
482
+
SFE_UBLOX_LS_SRC_BEIDOU,
483
+
SFE_UBLOX_LS_SRC_GALILEO,
484
+
SFE_UBLOX_LS_SRC_AIDED,
485
+
SFE_UBLOX_LS_SRC_CONFIGURED,
486
+
SFE_UBLOX_LS_SRC_UNKNOWN = 255
487
+
};
488
+
410
489
#ifndef MAX_PAYLOAD_SIZE
411
490
// v2.0: keep this for backwards-compatibility, but this is largely superseded by setPacketCfgPayloadSize
412
491
#defineMAX_PAYLOAD_SIZE256//We need ~220 bytes for getProtocolVersion on most ublox modules
@@ -580,15 +659,15 @@ class SFE_UBLOX_GNSS
580
659
boolean setPortOutput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = defaultMaxWait); //Configure a given port to output UBX, NMEA, RTCM3 or a combination thereof
581
660
boolean setPortInput(uint8_t portID, uint8_t comSettings, uint16_t maxWait = defaultMaxWait); //Configure a given port to input UBX, NMEA, RTCM3 or a combination thereof
582
661
583
-
boolean setI2CAddress(uint8_t deviceAddress, uint16_t maxTime = defaultMaxWait); //Changes the I2C address of the u-blox module
662
+
boolean setI2CAddress(uint8_t deviceAddress, uint16_t maxTime = defaultMaxWait); //Changes the I2C address of the u-blox module
584
663
voidsetSerialRate(uint32_t baudrate, uint8_t uartPort = COM_PORT_UART1, uint16_t maxTime = defaultMaxWait); //Changes the serial baud rate of the u-blox module, uartPort should be COM_PORT_UART1/2
585
664
586
665
boolean setI2COutput(uint8_t comSettings, uint16_t maxWait = defaultMaxWait); //Configure I2C port to output UBX, NMEA, RTCM3 or a combination thereof
587
-
boolean setUART1Output(uint8_t comSettings, uint16_t maxWait = defaultMaxWait);//Configure UART1 port to output UBX, NMEA, RTCM3 or a combination thereof
588
-
boolean setUART2Output(uint8_t comSettings, uint16_t maxWait = defaultMaxWait);//Configure UART2 port to output UBX, NMEA, RTCM3 or a combination thereof
666
+
boolean setUART1Output(uint8_t comSettings, uint16_t maxWait = defaultMaxWait);//Configure UART1 port to output UBX, NMEA, RTCM3 or a combination thereof
667
+
boolean setUART2Output(uint8_t comSettings, uint16_t maxWait = defaultMaxWait);//Configure UART2 port to output UBX, NMEA, RTCM3 or a combination thereof
589
668
boolean setUSBOutput(uint8_t comSettings, uint16_t maxWait = defaultMaxWait); //Configure USB port to output UBX, NMEA, RTCM3 or a combination thereof
590
669
boolean setSPIOutput(uint8_t comSettings, uint16_t maxWait = defaultMaxWait); //Configure SPI port to output UBX, NMEA, RTCM3 or a combination thereof
591
-
voidsetNMEAOutputPort(Stream &nmeaOutputPort); //Sets the internal variable for the port to direct NMEA characters to
670
+
voidsetNMEAOutputPort(Stream &nmeaOutputPort); //Sets the internal variable for the port to direct NMEA characters to
592
671
593
672
//Reset to defaults
594
673
@@ -800,6 +879,9 @@ class SFE_UBLOX_GNSS
800
879
// Add "auto" support for NAV SVIN - to avoid needing 'global' storage
801
880
boolean getSurveyStatus(uint16_t maxWait); //Reads survey in status
802
881
882
+
// Add "auto" support for NAV TIMELS - to avoid needing 'global' storage
883
+
boolean getLeapSecondEvent(uint16_t maxWait); //Reads leap second event info
884
+
803
885
boolean getRELPOSNED(uint16_t maxWait = defaultMaxWait); //Get Relative Positioning Information of the NED frame
boolean setAutoRELPOSNED(boolean enabled, boolean implicitUpdate, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic RELPOSNED, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
@@ -928,6 +1010,14 @@ class SFE_UBLOX_GNSS
928
1010
voidflushHNRPVT(); //Mark all the data as read/stale
929
1011
voidlogHNRPVT(boolean enabled = true); // Log data to file buffer
930
1012
1013
+
// Helper functions for NMEA logging
1014
+
voidsetNMEALoggingMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Add selected NMEA messages to file buffer - if enabled. Default to adding ALL messages to the file buffer
1015
+
uint32_tgetNMEALoggingMask(); // Return which NMEA messages are selected for logging to the file buffer - if enabled
1016
+
1017
+
// Helper functions to control which NMEA messages are passed to processNMEA
1018
+
voidsetProcessNMEAMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Control which NMEA messages are passed to processNMEA. Default to passing ALL messages
1019
+
uint32_tgetProcessNMEAMask(); // Return which NMEA messages are passed to processNMEA
1020
+
931
1021
// Helper functions for CFG RATE
932
1022
933
1023
boolean setNavigationFrequency(uint8_t navFreq, uint16_t maxWait = defaultMaxWait); //Set the number of nav solutions sent per second
@@ -936,6 +1026,7 @@ class SFE_UBLOX_GNSS
936
1026
uint16_tgetMeasurementRate(uint16_t maxWait = defaultMaxWait); //Return the elapsed time between GNSS measurements in milliseconds
937
1027
boolean setNavigationRate(uint16_t rate, uint16_t maxWait = defaultMaxWait); //Set the ratio between the number of measurements and the number of navigation solutions. Unit is cycles. Max is 127
938
1028
uint16_tgetNavigationRate(uint16_t maxWait = defaultMaxWait); //Return the ratio between the number of measurements and the number of navigation solutions. Unit is cycles
1029
+
voidflushCFGRATE(); // Mark the measurement and navigation rate data as stale - used by the set rate functions
939
1030
940
1031
// Helper functions for DOP
941
1032
@@ -1028,6 +1119,11 @@ class SFE_UBLOX_GNSS
1028
1119
uint16_tgetSurveyInObservationTime(uint16_t maxWait = defaultMaxWait); // Truncated to 65535 seconds
1029
1120
floatgetSurveyInMeanAccuracy(uint16_t maxWait = defaultMaxWait); // Returned as m
0 commit comments