Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0e2a02b

Browse files
committedOct 20, 2022
Update DataLoggingExample7_OpenLogESP32_SPI_SDIO.ino
1 parent 28cd70b commit 0e2a02b

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed
 

‎examples/Data_Logging/DataLoggingExample7_OpenLogESP32_SPI_SDIO/DataLoggingExample7_OpenLogESP32_SPI_SDIO.ino

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ File myFile;
4949
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
5050
SFE_UBLOX_GNSS myGNSS;
5151

52-
#define sdWriteSize 512 // Write data to the SD card in blocks of 512 bytes
53-
#define fileBufferSize 16384 // Allocate 16KBytes of RAM for UBX message storage
52+
#define sdWriteSize 2048 // Write data to the SD card in blocks of n*512 bytes
53+
#define fileBufferSize 65530 // Allocate just under 64KBytes of RAM for UBX message storage
54+
#define navRate 20 // Set the Nav Rate (Frequency) to 20Hz
55+
//#define ubxOnly // Uncomment this line to log UBX (RAWX and SFRBX) only
5456
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
5557

5658
unsigned long lastPrint; // Record when the last Serial print took place
@@ -104,6 +106,7 @@ void setup()
104106

105107
// Do a fake transaction to initialize the SPI pins
106108
spiPort.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
109+
spiPort.transfer(0);
107110
spiPort.endTransaction();
108111

109112
pinMode(EN_3V3_SW, OUTPUT); // Enable power for the microSD card and GNSS
@@ -140,7 +143,11 @@ void setup()
140143

141144
//myGNSS.factoryDefault(); delay(5000); // Uncomment this line to reset the module back to its factory defaults
142145

146+
#ifdef ubxOnly
147+
myGNSS.setSPIOutput(COM_TYPE_UBX); //Set the SPI port to output only UBX
148+
#else
143149
myGNSS.setSPIOutput(COM_TYPE_UBX | COM_TYPE_NMEA); //Set the SPI port to output both UBX and NMEA messages
150+
#endif
144151

145152
//myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Optional: save (only) the communications port settings to flash and BBR
146153

@@ -218,8 +225,6 @@ void setup()
218225
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
219226
// Enable RAWX and SFRBX
220227

221-
myGNSS.setNavigationFrequency(4); // Set navigation rate to 4Hz
222-
223228
myGNSS.setAutoRXMSFRBXcallbackPtr(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
224229

225230
myGNSS.logRXMSFRBX(); // Enable RXM SFRBX data logging
@@ -228,13 +233,18 @@ void setup()
228233

229234
myGNSS.logRXMRAWX(); // Enable RXM RAWX data logging
230235

231-
myGNSS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 1); // Ensure the GxGGA (Global positioning system fix data) message is enabled. Send every measurement.
232-
myGNSS.enableNMEAMessage(UBX_NMEA_GSA, COM_PORT_SPI, 1); // Ensure the GxGSA (GNSS DOP and Active satellites) message is enabled. Send every measurement.
233-
myGNSS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_SPI, 1); // Ensure the GxGSV (GNSS satellites in view) message is enabled. Send every measurement.
236+
myBuffer = new uint8_t[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
234237

235-
myGNSS.setNMEALoggingMask(SFE_UBLOX_FILTER_NMEA_ALL); // Enable logging of all enabled NMEA messages
238+
#ifndef ubxOnly
239+
myGNSS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, navRate); // Ensure the GxGGA (Global positioning system fix data) message is enabled. Send every second.
240+
myGNSS.enableNMEAMessage(UBX_NMEA_GSA, COM_PORT_SPI, navRate); // Ensure the GxGSA (GNSS DOP and Active satellites) message is enabled. Send every second.
241+
myGNSS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_SPI, navRate); // Ensure the GxGSV (GNSS satellites in view) message is enabled. Send every second.
242+
myGNSS.enableNMEAMessage(UBX_NMEA_GST, COM_PORT_SPI, navRate); // Ensure the GxGST (Position error statistics) message is enabled. Send every second.
243+
myGNSS.enableNMEAMessage(UBX_NMEA_RMC, COM_PORT_SPI, navRate); // Ensure the GxRMC (Recommended minimum: position, velocity and time) message is enabled. Send every second.
244+
myGNSS.setNMEALoggingMask(SFE_UBLOX_FILTER_NMEA_GGA | SFE_UBLOX_FILTER_NMEA_GSA | SFE_UBLOX_FILTER_NMEA_GSV | SFE_UBLOX_FILTER_NMEA_GST | SFE_UBLOX_FILTER_NMEA_RMC); // Log only these NMEA messages
245+
#endif
236246

237-
myBuffer = new uint8_t[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
247+
myGNSS.setNavigationFrequency(navRate); // Set navigation rate
238248

239249
Serial.println(F("Press any key to stop logging."));
240250

@@ -269,20 +279,21 @@ void loop()
269279

270280
if (millis() > (lastPrint + 1000)) // Print the message count once per second
271281
{
272-
Serial.print(F("Number of message groups received: SFRBX: ")); // Print how many message groups have been received (see note above)
273-
Serial.print(numSFRBX);
274-
Serial.print(F(" RAWX: "));
275-
Serial.println(numRAWX);
276-
277282
uint16_t maxBufferBytes = myGNSS.getMaxFileBufferAvail(); // Get how full the file buffer has been (not how full it is now)
283+
float bufferHigh = 100.0 * (float)maxBufferBytes / (float)fileBufferSize;
278284

279-
//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
280-
//Serial.println(maxBufferBytes);
281-
282-
if (maxBufferBytes > ((fileBufferSize / 5) * 4)) // Warn the user if fileBufferSize was more than 80% full
283-
{
284-
Serial.println(F("Warning: the file buffer has been over 80% full. Some data may have been lost."));
285-
}
285+
Serial.print(F("Message groups received: SFRBX: ")); // Print how many message groups have been received (see note above)
286+
Serial.print(numSFRBX);
287+
Serial.print(F(" RAWX: "));
288+
Serial.print(numRAWX);
289+
Serial.print(F(" \tBuffer high tide: "));
290+
Serial.print(bufferHigh, 1); // It is a fun thing to watch how full the buffer gets
291+
if (bufferHigh > 90.)
292+
Serial.println(F("%!!"));
293+
else if (bufferHigh > 80.)
294+
Serial.println(F("%!"));
295+
else
296+
Serial.println(F("%"));
286297

287298
lastPrint = millis(); // Update lastPrint
288299
}
@@ -319,6 +330,8 @@ void loop()
319330
myGNSS.disableMessage(UBX_CLASS_RXM, UBX_RXM_RAWX, COM_PORT_SPI);
320331
myGNSS.disableMessage(UBX_CLASS_RXM, UBX_RXM_SFRBX, COM_PORT_SPI);
321332

333+
myGNSS.setSPIOutput(COM_TYPE_UBX | COM_TYPE_NMEA); // Re-enable NMEA
334+
322335
Serial.println(F("Logging stopped. Freezing..."));
323336
while(1); // Do nothing more
324337
}

0 commit comments

Comments
 (0)
Please sign in to comment.