Issue with SD card file date

Hello,

I am trying to setup an automatic voice recorder, which records to a SD card with the correct file date. I can get the recording to work, and I can get the file date to work. However, with both in use it will create a file, but the file will not have any audio data.

Board- ProMini
RTC- DS3232
SD- SanDisk A1 (64GB)
Microphone- MAX9814
SD holder- Generic one.

#include <TMRpcm.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <DS3232RTC.h> 



const uint8_t CS = 10; // SD chip select

void dateTime(uint16_t* date, uint16_t* time)
{
   setSyncProvider(RTC.get);
  *date = FAT_DATE(year(), month(), day());
  *time = FAT_TIME(hour(), minute(), second());
}



TMRpcm audio;
int file_number = 0;
char filePrefixname[50] = "Test";
char exten[10] = ".wav";
const int recordLed = 7;
const int mic_pin = 14;
const int sample_rate = 16000;
#define SD_CSPin 10
// delay function for with serial log.
void wait_sec(int secs) {
  int count = 0;
 // int secs = 1;
  while (1) {
    Serial.print('.');
    delay(1000);
    count++;
    if (count == secs) {
      count = 0;
      break;
    }
  }
  Serial.println();
  return ;
}




void setup() {
  
  // put your setup code here, to run once:
  //initialises the serial connection between the arduino and any connected serial device(e.g. computer, phone, raspberry pi...)
  Serial.begin(9600);
  SdFile::dateTimeCallback(dateTime);
  //Sets up the pins
  pinMode(mic_pin, INPUT);
  pinMode(recordLed, OUTPUT);
  Serial.println("loading... SD card");
  if (!SD.begin(SD_CSPin)) {
    Serial.println("An Error has occurred while mounting SD");
  }
  while (!SD.begin(SD_CSPin)) {
    Serial.print(".");
    delay(500);
  }
  audio.CSPin = SD_CSPin;
}
void loop() {
  Serial.println("####################################################################################");
  char fileSlNum[20] = "";
  itoa(file_number, fileSlNum, 10);
  char file_name[50] = "";
  strcat(file_name, filePrefixname);
  strcat(file_name, fileSlNum);
  strcat(file_name, exten);
  Serial.print("New File Name: ");
  Serial.println(file_name);
  digitalWrite(recordLed, HIGH);
  audio.startRecording(file_name, sample_rate, mic_pin);
  Serial.println("startRecording ");
  // record audio for 2mins. means , in this loop process record 2mins of audio.
  // if you need more time duration recording audio then
  // pass higher value into the wait_min(int mins) function.
  wait_sec(10);
  digitalWrite(recordLed, LOW);
  audio.stopRecording(file_name);
  Serial.println("stopRecording");
  digitalWrite(7, LOW);
  file_number++;
  Serial.println("####################################################################################");
}

My question is is there something with the SD file dating that is causing the audio to not be recorded?

(P.S. There are no error codes)

I've not checked in details but dateTimeCallback() is not documented as a feature of the standard SD library... so may be it's bogus.

have you tried using the latest version of SDFat? (see this example)

See this thread about the dateTimeCallback with Sd.h. It is indeed supported.

https://forum.arduino.cc/index.php?topic=348562.msg3298426;topicseen#msg3298426

I don't think that setSynchProvider() belongs in the callback, but I don't think it's the cause of your issue.

Ok good to Know it’s fully working even if it’s not listed in the API (I had seen it in the .h).

Not sure why then but noticed the following in the documentation for recording audio:

Notes: SdFat library is recommended for recording.
Class 4 SD card minimum recommended
May need to increase buffSize

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.