Logging serial data to an SD chip

Status
Not open for further replies.

tomdouglas

New member
I've been searching for a way to capture my serial port data to an SD chip on Teensy 3.5. I need all the information that is sent to the serial port to also be sent to a file on the SD, without doubling all of the print statements.

I have explored several possibilities. The GeoTee library was one of those. GeoTee(?) (from GitHub) seems to output to the serial port just fine but not to the SD. I quickly gave that up. Perhaps I missed something there? I can write to the SD independently.

I also looked at setting up a Print library but couldn't find how to reference the serial port. I dropped that too.

Lately I started using Serial1 for directing my program data to, loop through its TX to RX pins, then relay the Serial1's RX to the SD as well as the serial port. With this technique, I'm having to add a ring buffer to Serial1's RX. I'm looking at a buffer size of 512 or 1024 bytes. My code is below.

Is there a better approach for tee'ing outputs, such as to an SD as well as the serial port?

Thanks, guys!

TomD

Code:
// Main program and subroutines with print statements
loop () {
  Serial1.print ( ... );
  Serial1.print ( ... );
  Serial1.print ( ... );
  distribPrint ();  // Distribute print output
}

// Serial event to catch print statement output
Serial1Event () {
  if (Serial1.available) {
    char c = (char) Serial.read ();
    // Store to ring buffer
  }
}

// Distribute the output info to the serial port and SD chip
distribPrint () {
  while (charAvail > 0) (
    char c = // Retrieve from ring buffer
    Serial.print (c);
    // Send c to SD write
  }
}
 
Status
Not open for further replies.
Back
Top