OK, now the longer answer…
If we were to attempt this dual-writing goal, how might I approach it? The trick is to prevent the audio writing from colliding with the text writing. We do this by ensuring that we only create one instance of the root SD-writing class and we use that one instance for both the audio writing and the text writing.
For the audio-writing, I might look at the Tympan example:
02-Intermediate\SDWriter_wApp. For the text logging, I might look at the Arduino/Teensy examples
SD\SdFat_Usage (or possibly
SD\Datalogger). These examples show how to use SD for audio or SD for text, but neither one of these shows both. We need to add this idea of creating a single SD instance that is shared between the two types of writing.
What I would do is:
- Create a single instance of the SD-controlling class
- Pass this one instance to the Tympan AudioSDWriter for writing audio to the SD
- Use this one instance for your code that writes text to the SD
Expanding these three steps into more words, it might look like:
- Create one instance of the SD-controlling class. Normally the SD-controlling class is created for you in the background by the Tympan AudioSDWriter. We now need to create the class explicitly. So, I grabbed the relevant line of code from deep down in the Tympan library. I’d insert it into the global space of your program. I’d probably add the line in the global space, right after you create the “myTympan”:
#include <SD.h> //enables us to manually control the SD card. Add somewhere near the top
//setup the Tympan using the default settings
Tympan myTympan(TympanRev::E, audio_settings);
SDClass sdx; // explicitly create SD card (will pass to AudioSDWriter)
- Pass this SD instance to the AudioSDWriter. Somewhere in your program, you create an instance of the AudioSDWriter_F32 class. We are going to modify that line to hand it the separately created SD class. Your modified line of code would look like:
AudioSDWriter_F32_UI audioSDWriter(&(sdx.sdfs), audio_settings);
- Use this SD instance to write text logs. At different points in your code, you need to open a file, write to the file, and close a file. If you are not going to write very often (like, maybe, no faster than 1 per second on average), you could do all three steps together. It’s inefficient to keep opening and closing, but it is very safe for your data. If you are recording user inputs, you could open-write-close with every user input. The three commands that you might want are:
FsFile myfile = sdx.sdfs.open("datalog.txt", O_WRITE | O_CREAT | O_APPEND);
myfile.println("User Changed Volume to : " + String(newVolume_dB)); //write the text
There are additional details that might need to be added, like maybe an sd.begin line like this one (to be put in your setup() function?):
But until it gets tested the first time, I’m not sure.
Sorry I don’t have a simple example that I can just point to!