Merge pull request #180 from ladyada-eagleclaw/main

Use Adafruit SdFat for shield logging
This commit is contained in:
Limor "Ladyada" Fried authored and GitHub committed 2026-09-15 13:33:12 -04:00
commit c413dd495e
4 files changed
+32 -14

No files matched your search

+5
View File
@@ -19,6 +19,11 @@ jobs:
- name: pre-install
run: bash ci/actions_install.sh
- name: install SdFat logger example dependency
run: |
arduino-cli lib update-index
arduino-cli lib install "SdFat - Adafruit Fork"
- name: test platforms
run: python3 ci/build_platform.py main_platforms
+7 -5
View File
@@ -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**, including its offered dependencies. The SD logger
example needs the **SD** library from Arduino.
**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
+20 -8
View File
@@ -1,7 +1,7 @@
#include <SPI.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
#include <SD.h>
#include <SdFat_Adafruit_Fork.h>
#include <avr/sleep.h>
// 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!
-1
View File
@@ -7,4 +7,3 @@ paragraph=An interrupt-based GPS library for no-parsing-required use
category=Sensors
url=https://github.com/adafruit/Adafruit_GPS
architectures=*
depends=SD