not recording

Status
Not open for further replies.

garthpaine

Active member
HI everyone - the code used to record and I have changed something and now it is not recording to the SD card even though it is printing out that it is doing so - can anyone see why this is the case?? thanks in advance - here is my code. I wonder if the file name is too long? but I am thinking it is something re the 512 buffer which I read was the most efficient way too do this? Happy to have feedback and another set of eyes - I just can not find where this is Brocken. thanks heaps



[ CODE]
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=202,157
AudioRecordQueue queue1; //xy=481,150
AudioConnection patchCord1(i2s1, 0, queue1, 0);
AudioControlSGTL5000 sgtl5000_1; //xy=279,278
// GUItool: end automatically generated code


// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14

const int myInput = AUDIO_INPUT_MIC;
String recordingName = "Rec01";
int recordingCount = 0;
File frec;

void setup() {
Serial.begin(9600);

// setTime params: hr, min, sec, day, month, year
setTime(18, 05, 0, 5, 5, 18);

// Alarm each 10 minutes. startRec() will record
Alarm.timerRepeat(600, startRec);

AudioMemory(60);

sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(0.5);

// Initialize the SD card
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
while (!(SD.begin(SDCARD_CS_PIN))) {
Serial.println("Unable to access the SD card - retry in 10 seconds");
delay(10000);
}

delay(2000);
startRec();

}

void loop() {
//digitalClockDisplay();
Alarm.delay(1000);
}

// Record ten seconds of audio
// While this is recording the clock display will stop
void startRec() {
byte buffer[512];
Serial.println("Start Rec");
recordingCount++;

String rec = recordingName + "_" + recordingCount + "-" + hour() + ":" + minute() + ":" + second() + "_" + day() + "-" + month() + "-" + year() + ".RAW";
Serial.println("RecName: " + rec);

frec = SD.open(rec.c_str(), FILE_WRITE);

queue1.begin();


// 31007 is the number of buffers to make 44100 samples/sec for 3 min at 256 buffer size
// calculate ((Min*60) * (SampleRate 44100))/bufferSize 256

for (int i = 0; i < 51680; i++) {
memcpy(buffer, queue1.readBuffer(), 256);
queue1.freeBuffer();
memcpy(buffer+256, queue1.readBuffer(), 256);
queue1.freeBuffer();
// write all 512 bytes to the SD card

frec.write(buffer, 512);


}

stopRec();
}



void stopRec()
{

Serial.println("Stop Rec");
queue1.end();
frec.close();

}


void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" -- ");

// Serial.print(day());
// printDigits(month());
// printDigits(year());
// Serial.println();
}



void printDigits(int digits) {
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}
[/ CODE]
 
Last edited:
HI everyone - the code used to record and I have changed something and now it is not recording to the SD card even though it is printing out that it is doing so - can anyone see why this is the case?? thanks in advance - here is my code. I wonder if the file name is too long? but I am thinking it is something re the 512 buffer which I read was the most efficient way too do this? Happy to have feedback and another set of eyes - I just can not find where this is Brocken. thanks heaps

you should only read from queue if there is a buffer available (or did I miss the line?)
 
There is a byte buffer[512]; just at the top of startRec() I did wander if this needs to be refreshed in the loop during recording or not?
 
Status
Not open for further replies.
Back
Top