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

Commit c1b2b70

Browse files
committed
Adding extra Data Logging examples
1 parent dec6ebe commit c1b2b70

File tree

6 files changed

+600
-97
lines changed

6 files changed

+600
-97
lines changed

examples/Callbacks/CallbackExample5_ESF/CallbackExample5_ESF.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ void printESFMEASdata(UBX_ESF_MEAS_data_t ubxDataStruct)
8080
Serial.print(F(" numMeas: "));
8181
Serial.println(ubxDataStruct.flags.bits.numMeas);
8282

83-
for (uint8_t num = 0; num < ubxDataStruct.flags.bits.numMeas; num++)
83+
for (uint8_t num = 0; num < ubxDataStruct.flags.bits.numMeas; num++) // For each sensor
8484
{
8585
Serial.print(F("Sensor "));
8686
Serial.print(num);
8787

8888
UBX_ESF_MEAS_sensorData_t sensorData;
89-
myGPS.getSensorFusionMeasurement(&sensorData, ubxDataStruct, num);
89+
myGPS.getSensorFusionMeasurement(&sensorData, ubxDataStruct, num); // Extract the data for one sensor
9090

9191
Serial.print(F(": Type: "));
9292
Serial.print(sensorData.data.bits.dataType);
@@ -106,13 +106,13 @@ void printESFSTATUSdata(UBX_ESF_STATUS_data_t ubxDataStruct)
106106
Serial.print(F(" numSens: "));
107107
Serial.println(ubxDataStruct.numSens);
108108

109-
for (uint8_t num = 0; num < ubxDataStruct.numSens; num++)
109+
for (uint8_t num = 0; num < ubxDataStruct.numSens; num++) // For each sensor
110110
{
111111
Serial.print(F("Sensor "));
112112
Serial.print(num);
113113

114114
UBX_ESF_STATUS_sensorStatus_t sensorStatus;
115-
myGPS.getSensorFusionStatus(&sensorStatus, ubxDataStruct, num);
115+
myGPS.getSensorFusionStatus(&sensorStatus, ubxDataStruct, num); // Extract the data for one sensor
116116

117117
Serial.print(F(": Type: "));
118118
Serial.print(sensorStatus.sensStatus1.bits.type);

examples/Data_Logging/DataLoggingExample1_NAVPVT/DataLoggingExample1_NAVPVT.ino renamed to examples/Data_Logging/DataLoggingExample1_NAV_PVT/DataLoggingExample1_NAV_PVT.ino

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
Buy a board from SparkFun!
3939
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
4040
NEO-M8P RTK: https://www.sparkfun.com/products/15005
41+
SAM-M8Q: https://www.sparkfun.com/products/15106
42+
4143
*/
4244

4345
#include <SPI.h>
@@ -54,39 +56,39 @@ File myFile; //File that all GNSS data is written to
5456
#define packetLength 100 // NAV PVT is 92 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes)
5557

5658
// Callback: printPVTdata will be called when new NAV PVT data arrives
57-
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t *packetUBXNAVPVTcopy
58-
void printPVTdata()
59+
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t
60+
void printPVTdata(UBX_NAV_PVT_data_t ubxDataStruct)
5961
{
6062
Serial.println();
6163

6264
Serial.print(F("Time: ")); // Print the time
63-
uint8_t hms = myGPS.packetUBXNAVPVTcopy->hour; // Print the hours
65+
uint8_t hms = ubxDataStruct.hour; // Print the hours
6466
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
6567
Serial.print(hms);
6668
Serial.print(F(":"));
67-
hms = myGPS.packetUBXNAVPVTcopy->min; // Print the minutes
69+
hms = ubxDataStruct.min; // Print the minutes
6870
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
6971
Serial.print(hms);
7072
Serial.print(F(":"));
71-
hms = myGPS.packetUBXNAVPVTcopy->sec; // Print the seconds
73+
hms = ubxDataStruct.sec; // Print the seconds
7274
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
7375
Serial.print(hms);
7476
Serial.print(F("."));
75-
unsigned long millisecs = myGPS.packetUBXNAVPVTcopy->iTOW % 1000; // Print the milliseconds
77+
unsigned long millisecs = ubxDataStruct.iTOW % 1000; // Print the milliseconds
7678
if (millisecs < 100) Serial.print(F("0")); // Print the trailing zeros correctly
7779
if (millisecs < 10) Serial.print(F("0"));
7880
Serial.print(millisecs);
7981

80-
long latitude = myGPS.packetUBXNAVPVTcopy->lat; // Print the latitude
82+
long latitude = ubxDataStruct.lat; // Print the latitude
8183
Serial.print(F(" Lat: "));
8284
Serial.print(latitude);
8385

84-
long longitude = myGPS.packetUBXNAVPVTcopy->lon; // Print the longitude
86+
long longitude = ubxDataStruct.lon; // Print the longitude
8587
Serial.print(F(" Long: "));
8688
Serial.print(longitude);
8789
Serial.print(F(" (degrees * 10^-7)"));
8890

89-
long altitude = myGPS.packetUBXNAVPVTcopy->hMSL; // Print the height above mean sea level
91+
long altitude = ubxDataStruct.hMSL; // Print the height above mean sea level
9092
Serial.print(F(" Height above MSL: "));
9193
Serial.print(altitude);
9294
Serial.println(F(" (mm)"));
@@ -145,8 +147,6 @@ void setup()
145147

146148
//myGPS.enableDebugging(); // Uncomment this line to enable helpful GNSS debug messages on Serial
147149

148-
//myGPS.disableUBX7Fcheck(); // Advanced users only: uncomment this line to disable the "7F" check in checkUbloxI2C
149-
150150
// NAV PVT messages are 100 bytes long.
151151
// In this example, the data will arrive no faster than one message per second.
152152
// So, setting the file buffer size to 301 bytes should be more than adequate.
@@ -159,12 +159,16 @@ void setup()
159159
while (1);
160160
}
161161

162+
// Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate
163+
// (This will also disable any "auto" messages that were enabled and saved by other examples and reduce the load on the I2C bus)
164+
//myGPS.factoryDefault(); delay(5000);
165+
162166
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
163167
myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
164168

165169
myGPS.setNavigationFrequency(1); //Produce one navigation solution per second
166170

167-
myGPS.setAutoPVTcallback(printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
171+
myGPS.setAutoPVTcallback(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
168172

169173
myGPS.logNAVPVT(); // Enable NAV PVT data logging
170174

@@ -180,29 +184,11 @@ void loop()
180184
{
181185
uint8_t myBuffer[packetLength]; // Create our own buffer to hold the data while we write it to SD card
182186

183-
uint16_t numBytesExtracted = myGPS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
187+
myGPS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
184188

185-
if (numBytesExtracted != packetLength) // Check that we did extract exactly packetLength bytes
186-
{
187-
Serial.println(F("numBytesExtracted does not match packetLength! Something really bad has happened! Freezing..."));
188-
myFile.close(); // Close the data file
189-
while (1); // Do nothing more
190-
}
189+
myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
191190

192-
uint16_t numBytesWritten = myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
193-
194-
//printBuffer(myBuffer); // Uncomment this line to print the data
195-
196-
if (numBytesWritten != packetLength) // Check that we did write exactly packetLength bytes
197-
{
198-
Serial.println(F("numBytesWritten does not match packetLength! Something really bad has happened! Freezing..."));
199-
myFile.close(); // Close the data file
200-
while (1);
201-
}
202-
203-
Serial.print(F("Wrote "));
204-
Serial.print(packetLength);
205-
Serial.println(F(" bytes of data to NAV_PVT.ubx"));
191+
//printBuffer(myBuffer); // Uncomment this line to print the data as Hexadecimal bytes
206192
}
207193

208194
if (Serial.available()) // Check if the user wants to stop logging
@@ -216,7 +202,7 @@ void loop()
216202
delay(50);
217203
}
218204

219-
// Print the buffer contents as Hexadecimal
205+
// Print the buffer contents as Hexadecimal bytes
220206
// You should see:
221207
// SYNC CHAR 1: 0xB5
222208
// SYNC CHAR 2: 0x62

examples/Data_Logging/DataLoggingExample2_TIMTM2/DataLoggingExample2_TIMTM2.ino renamed to examples/Data_Logging/DataLoggingExample2_TIM_TM2/DataLoggingExample2_TIM_TM2.ino

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
will cause a TIM TM2 message to be produced once per second. You can then study the timing of the
3535
pulse edges with nanosecond resolution!
3636
37+
Note: TIM TM2 can only capture the timing of one rising edge and one falling edge per
38+
navigation solution. So with setNavigationFrequency set to 1Hz, we can only see the timing
39+
of one rising and one falling edge per second. If the frequency of the signal on the INT pin
40+
is higher than 1Hz, we will only be able to see the timing of the most recent edges.
41+
However, the module can count the number of rising edges too, at rates faster than the navigation rate.
42+
43+
TIM TM2 messages are only produced when a rising or falling edge is detected on the INT pin.
44+
If you disconnect your PPS to INT jumper wire, the messages will stop.
45+
3746
Data is logged in u-blox UBX format. Please see the u-blox protocol specification for more details.
3847
You can replay and analyze the data using u-center:
3948
https://www.u-blox.com/en/product/u-center
@@ -42,6 +51,8 @@
4251
Buy a board from SparkFun!
4352
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
4453
NEO-M8P RTK: https://www.sparkfun.com/products/15005
54+
NEO-M9N: https://www.sparkfun.com/products/17285
55+
4556
*/
4657

4758
#include <SPI.h>
@@ -57,32 +68,36 @@ File myFile; //File that all GNSS data is written to
5768

5869
#define packetLength 36 // TIM TM2 is 28 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes)
5970

71+
int dotsPrinted = 0; // Print dots in rows of 50 while waiting for a TIM TM2 message
72+
6073
// Callback: printTIMTM2data will be called when new TIM TM2 data arrives
61-
// See u-blox_structs.h for the full definition of UBX_TIM_TM2_data_t *packetUBXTIMTM2copy
62-
void printTIMTM2data()
74+
// See u-blox_structs.h for the full definition of UBX_TIM_TM2_data_t
75+
void printTIMTM2data(UBX_TIM_TM2_data_t ubxDataStruct)
6376
{
6477
Serial.println();
6578

6679
Serial.print(F("newFallingEdge: ")); // 1 if a new falling edge was detected
67-
Serial.print(myGPS.packetUBXTIMTM2copy->flags.bits.newFallingEdge);
80+
Serial.print(ubxDataStruct.flags.bits.newFallingEdge);
6881

6982
Serial.print(F(" newRisingEdge: ")); // 1 if a new rising edge was detected
70-
Serial.print(myGPS.packetUBXTIMTM2copy->flags.bits.newRisingEdge);
83+
Serial.print(ubxDataStruct.flags.bits.newRisingEdge);
7184

7285
Serial.print(F(" Rising Edge Counter: ")); // Rising edge counter
73-
Serial.print(myGPS.packetUBXTIMTM2copy->count);
86+
Serial.print(ubxDataStruct.count);
7487

7588
Serial.print(F(" towMsR: ")); // Time Of Week of rising edge (ms)
76-
Serial.print(myGPS.packetUBXTIMTM2copy->towMsR);
89+
Serial.print(ubxDataStruct.towMsR);
7790

7891
Serial.print(F(" towSubMsR: ")); // Millisecond fraction of Time Of Week of rising edge in nanoseconds
79-
Serial.print(myGPS.packetUBXTIMTM2copy->towSubMsR);
92+
Serial.print(ubxDataStruct.towSubMsR);
8093

8194
Serial.print(F(" towMsF: ")); // Time Of Week of falling edge (ms)
82-
Serial.print(myGPS.packetUBXTIMTM2copy->towMsF);
95+
Serial.print(ubxDataStruct.towMsF);
8396

8497
Serial.print(F(" towSubMsF: ")); // Millisecond fraction of Time Of Week of falling edge in nanoseconds
85-
Serial.println(myGPS.packetUBXTIMTM2copy->towSubMsF);
98+
Serial.println(ubxDataStruct.towSubMsF);
99+
100+
dotsPrinted = 0; // Reset dotsPrinted
86101
}
87102

88103
void setup()
@@ -138,8 +153,6 @@ void setup()
138153

139154
//myGPS.enableDebugging(); // Uncomment this line to enable helpful GNSS debug messages on Serial
140155

141-
//myGPS.disableUBX7Fcheck(); // Advanced users only: uncomment this line to disable the "7F" check in checkUbloxI2C
142-
143156
// TIM TM2 messages are 36 bytes long.
144157
// In this example, the data will arrive no faster than one message per second.
145158
// So, setting the file buffer size to 109 bytes should be more than adequate.
@@ -152,12 +165,16 @@ void setup()
152165
while (1);
153166
}
154167

168+
// Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate
169+
// (This will also disable any "auto" messages that were enabled and saved by other examples and reduce the load on the I2C bus)
170+
//myGPS.factoryDefault(); delay(5000);
171+
155172
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
156173
myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
157174

158175
myGPS.setNavigationFrequency(1); //Produce one navigation solution per second
159176

160-
myGPS.setAutoTIMTM2callback(printTIMTM2data); // Enable automatic TIM TM2 messages with callback to printTIMTM2data
177+
myGPS.setAutoTIMTM2callback(&printTIMTM2data); // Enable automatic TIM TM2 messages with callback to printTIMTM2data
161178

162179
myGPS.logTIMTM2(); // Enable TIM TM2 data logging
163180

@@ -173,29 +190,11 @@ void loop()
173190
{
174191
uint8_t myBuffer[packetLength]; // Create our own buffer to hold the data while we write it to SD card
175192

176-
uint16_t numBytesExtracted = myGPS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
177-
178-
if (numBytesExtracted != packetLength) // Check that we did extract exactly packetLength bytes
179-
{
180-
Serial.println(F("numBytesExtracted does not match packetLength! Something really bad has happened! Freezing..."));
181-
myFile.close(); // Close the data file
182-
while (1); // Do nothing more
183-
}
193+
myGPS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
184194

185-
uint16_t numBytesWritten = myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
195+
myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
186196

187197
//printBuffer(myBuffer); // Uncomment this line to print the data
188-
189-
if (numBytesWritten != packetLength) // Check that we did write exactly packetLength bytes
190-
{
191-
Serial.println(F("numBytesWritten does not match packetLength! Something really bad has happened! Freezing..."));
192-
myFile.close(); // Close the data file
193-
while (1);
194-
}
195-
196-
Serial.print(F("Wrote "));
197-
Serial.print(packetLength);
198-
Serial.println(F(" bytes of data to TIM_TM2.ubx"));
199198
}
200199

201200
if (Serial.available()) // Check if the user wants to stop logging
@@ -205,8 +204,13 @@ void loop()
205204
while(1); // Do nothing more
206205
}
207206

208-
Serial.print(".");
207+
Serial.print("."); // Print dots in rows of 50
209208
delay(50);
209+
if (++dotsPrinted > 50)
210+
{
211+
Serial.println();
212+
dotsPrinted = 0;
213+
}
210214
}
211215

212216
// Print the buffer contents as Hexadecimal

examples/Data_Logging/DataLoggingExample3_RXM_SFRBX_and_RAWX/DataLoggingExample3_RXM_SFRBX_and_RAWX.ino

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ int numSFRBX = 0; // Keep count of how many SFRBX message groups have been recei
7272
int numRAWX = 0; // Keep count of how many RAWX message groups have been received (see note above)
7373

7474
// Callback: newSFRBX will be called when new RXM SFRBX data arrives
75-
// See u-blox_structs.h for the full definition of UBX_RXMSFRBX_data_t *packetUBXRXMSFRBXcopy
76-
void newSFRBX()
75+
// See u-blox_structs.h for the full definition of UBX_RXMSFRBX_data_t
76+
void newSFRBX(UBX_RXM_SFRBX_data_t ubxDataStruct)
7777
{
7878
numSFRBX++; // Increment the count
7979
}
8080

8181
// Callback: newRAWX will be called when new RXM RAWX data arrives
82-
// See u-blox_structs.h for the full definition of UBX_RXMRAWX_data_t *packetUBXRXMRAWXcopy
83-
void newRAWX()
82+
// See u-blox_structs.h for the full definition of UBX_RXMRAWX_data_t
83+
void newRAWX(UBX_RXM_RAWX_data_t ubxDataStruct)
8484
{
8585
numRAWX++; // Increment the count
8686
}
@@ -157,18 +157,19 @@ void setup()
157157
}
158158

159159
// Uncomment the next line if you want to reset your module back to the default settings with 1Hz navigation rate
160+
// (This will also disable any "auto" messages that were enabled and saved by other examples and reduce the load on the I2C bus)
160161
//myGPS.factoryDefault(); delay(5000);
161162

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

165166
myGPS.setNavigationFrequency(1); //Produce one navigation solution per second (that's plenty for Precise Point Positioning)
166167

167-
myGPS.setAutoRXMSFRBXcallback(newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
168+
myGPS.setAutoRXMSFRBXcallback(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
168169

169170
myGPS.logRXMSFRBX(); // Enable RXM SFRBX data logging
170171

171-
myGPS.setAutoRXMRAWXcallback(newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
172+
myGPS.setAutoRXMRAWXcallback(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
172173

173174
myGPS.logRXMRAWX(); // Enable RXM RAWX data logging
174175

@@ -192,23 +193,9 @@ void loop()
192193

193194
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
194195

195-
uint16_t numBytesExtracted = myGPS.extractFileBufferData((uint8_t *)&myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
196+
myGPS.extractFileBufferData((uint8_t *)&myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
196197

197-
if (numBytesExtracted != sdWriteSize) // Check that we did extract exactly sdWriteSize bytes
198-
{
199-
Serial.println(F("numBytesExtracted does not match sdWriteSize! Something really bad has happened! Freezing..."));
200-
myFile.close(); // Close the data file
201-
while (1); // Do nothing more
202-
}
203-
204-
uint16_t numBytesWritten = myFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card
205-
206-
if (numBytesWritten != sdWriteSize) // Check that we did write exactly sdWriteSize bytes
207-
{
208-
Serial.println(F("numBytesWritten does not match sdWriteSize! Something really bad has happened! Freezing..."));
209-
myFile.close(); // Close the data file
210-
while (1);
211-
}
198+
myFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card
212199

213200
// In case the SD writing is slow or there is a lot of data to write, keep checking for the arrival of new data
214201
myGPS.checkUblox(); // Check for the arrival of new data and process it.
@@ -226,13 +213,14 @@ void loop()
226213
Serial.print(F(" RAWX: "));
227214
Serial.println(numRAWX);
228215

229-
uint16_t maxBufferBytes = myGPS.getMaxFileBufferAvail(); // Print how full the file buffer has been (not how full it is now)
230-
Serial.print(F("The maximum number of bytes which the file buffer has contained is: "));
231-
Serial.println(maxBufferBytes);
216+
uint16_t maxBufferBytes = myGPS.getMaxFileBufferAvail(); // Get how full the file buffer has been (not how full it is now)
217+
218+
//Serial.print(F("The maximum number of bytes which the file buffer has contained is: ")); // It is a fun thing to watch how full the buffer gets
219+
//Serial.println(maxBufferBytes);
232220

233221
if (maxBufferBytes > ((fileBufferSize / 5) * 4)) // Warn the user if fileBufferSize was more than 80% full
234222
{
235-
Serial.println(F("Warning: the file buffer was almost full. Some data may have been lost."));
223+
Serial.println(F("Warning: the file buffer has been over 80% full. Some data may have been lost."));
236224
}
237225

238226
lastPrint = millis(); // Update lastPrint

0 commit comments

Comments
 (0)