diff --git a/.github/workflows/githubci.yml b/.github/workflows/githubci.yml index ca9b31b..25b79fa 100644 --- a/.github/workflows/githubci.yml +++ b/.github/workflows/githubci.yml @@ -19,10 +19,10 @@ jobs: - name: pre-install run: bash ci/actions_install.sh - - name: install SD logger example dependency + - name: install SdFat logger example dependency run: | arduino-cli lib update-index - arduino-cli lib install SD + arduino-cli lib install "SdFat - Adafruit Fork" - name: test platforms run: python3 ci/build_platform.py main_platforms diff --git a/README.md b/README.md index 04e5e78..b94203d 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ not universal across GPS manufacturers. ## Getting started 1. In the Arduino IDE Library Manager, search for **Adafruit GPS** and install - **Adafruit GPS Library**. For the `shield_sdlog` example, also install **SD** - by Arduino from Library Manager. + **Adafruit GPS Library**. For the `shield_sdlog` example, also install + **SdFat - Adafruit Fork** by Bill Greiman from Library Manager. 2. Follow the wiring guide for your module: [Ultimate GPS](https://learn.adafruit.com/adafruit-ultimate-gps) or [PA1010D](https://learn.adafruit.com/adafruit-mini-gps-pa1010d-module). @@ -74,9 +74,11 @@ a **parsing** sketch turns that text into individual readings. **SD logging** writes files to a separate SD card. The `shield_sdlog` example uses GPS pins D8/D7, the hardware SPI pins, and SD chip select D10. It writes raw -NMEA text into files such as `GPSLOG00.TXT`. With `LOG_FIXONLY` set to `false`, it -also saves sentences while the GPS has no position fix. Set it to `true` if you -only want records with a fix. +NMEA text into files named `GPSLOG0000.TXT` through `GPSLOG9999.TXT`, using +SdFat's long-filename support. Each start creates a new file; if all names are +used, the logger stops instead of reopening an old log. With `LOG_FIXONLY` set +to `false`, it also saves sentences while the GPS has no position fix. Set it +to `true` if you only want records with a fix. The Uno and Metro 328 have only 2 KB of RAM. SD logging leaves limited room for additional buffers and variables; keep constant print messages in `F()` when diff --git a/examples/shield_sdlog/shield_sdlog.ino b/examples/shield_sdlog/shield_sdlog.ino index 9ed8467..5f03a6c 100644 --- a/examples/shield_sdlog/shield_sdlog.ino +++ b/examples/shield_sdlog/shield_sdlog.ino @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include // Ladyada's logger modified by Bill Greiman to use the SdFat library @@ -36,6 +36,7 @@ bool usingInterrupt = false; #define chipSelect 10 #define ledPin 13 +SdFat SD; File logfile; // read a Hex value and return the decimal equivalent @@ -96,18 +97,19 @@ void setup() { error(2); } char filename[15]; - strcpy(filename, "GPSLOG00.TXT"); - for (uint8_t i = 0; i < 100; i++) { - filename[6] = '0' + i/10; - filename[7] = '0' + i%10; - // create if does not exist, do not open existing, write, sync after write + strcpy(filename, "GPSLOG0000.TXT"); + for (uint16_t i = 0; i < 10000; i++) { + filename[6] = '0' + i/1000; + filename[7] = '0' + (i/100)%10; + filename[8] = '0' + (i/10)%10; + filename[9] = '0' + i%10; + // Find an unused long filename, then create it without opening an old log. if (! SD.exists(filename)) { break; } } - logfile = SD.open(filename, FILE_WRITE); - if( ! logfile ) { + if (!logfile.open(filename, O_WRONLY | O_CREAT | O_EXCL)) { Serial.print(F("Couldnt create ")); Serial.println(filename); error(3); @@ -131,6 +133,16 @@ void setup() { GPS.sendCommand(F(PGCMD_NOANTENNA)); GPS.sendCommand(F(CDCMD_NOANTENNA)); + // Drain startup command replies before the first SD write. Their rapid + // arrival can otherwise reuse a GPS receive buffer while it is being saved. + uint32_t start = millis(); + while (millis() - start < 2000) { + GPS.read(); + if (GPS.newNMEAreceived()) { + GPS.lastNMEA(); + } + } + // the nice thing about this code is you can have a timer0 interrupt go off // every 1 millisecond, and read data from the GPS for you. that makes the // loop code a heck of a lot easier!