I do a lot of GPS testing, and I'd like to just capture NMEA data (RMC messages) as it streams to the SD card on Teensy 3.6 Serial1. I have great success using the Sparkfun OpenLog SD card with T3.2s and T4.0s, but now I'm trying to get it working on the built-in T3.6 SD card. My routine below works fairly well at 1Hz on the T3.6, putting one RMC message per line. But when I bump the output to 10Hz, everything gets written to the a single line because the last couple of characters of each RMC message seem to not get captured.
Is there a library (or sketch) that just does what the OpenLog does, i.e. just simply captures the entire NMEA data cleanly as it streams to Serial?
Thanks for any advice!
Is there a library (or sketch) that just does what the OpenLog does, i.e. just simply captures the entire NMEA data cleanly as it streams to Serial?
Thanks for any advice!
Code:
// The Code...
#include <SPI.h>
#include <SD.h>
#define gpsPort Serial1
File GPS_File;
void setup() {
Serial.begin(115200);
gpsPort.begin(115200);
delay(500);
Serial.println("Am Here");
if (!SD.begin(BUILTIN_SDCARD)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("Card initialized.");
// Remove old file
SD.remove("datalog.txt");
// Create new file
GPS_File = SD.open("datalog.txt", FILE_WRITE);
GPS_File.close();
//GPS_File.write("START\n");
// Enable LED pin
pinMode(ledPin, OUTPUT);
}
void loop() {
if (gpsPort.available())
{
String Buffer = "";
while (gpsPort.available())
{
char GPSRX = gpsPort.read();
Buffer += GPSRX;
}
// Open the file
GPS_File = SD.open("datalog.txt", FILE_WRITE);
// If the file is available, write to it:
if (GPS_File) {
GPS_File.print(Buffer);
GPS_File.close();
// print to the serial port too:
//Serial.print(Buffer);
}
// If the file isn't open, pop up an error
else {
Serial.println("Error opening datalog.txt");
}
}
}
Last edited by a moderator: