Hello,
I have an odd issue with a MKRZERO. When I try to play an audio file after the internal RTC has been initialised, the WAV files won't play. See the rtc.begin() function call in the code below.
Configuration: MKRZERO and Adafruit MAX98357A I2S audio board.
#include <SD.h> // SD card access library
#include <ArduinoSound.h> // I2S sound interface library
#include <RTCZero.h> // Real Time Clock library
// SETUP Audio playback
// filename of wave file to play
const char filename[] = "MUSIC.WAV";
// variable representing the Wave File
SDWaveFile waveFile;
// SETUP Real Time Clock
/* Create a RTC object */
RTCZero rtc;
/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;
/* Change these values to set the current initial date */
const byte day = 15;
const byte month = 6;
const byte year = 15;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Start Arduino serial port at 9,600 baud
// SD.begin(); // Open the SD card
delay(500);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// setup the SD card, depending on your shield of breakout board
// you may need to pass a pin number in begin for SS
Serial.print("Initializing SD card..z.");
if (!SD.begin()) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// create a SDWaveFile
waveFile = SDWaveFile(filename);
// check if the WaveFile is valid
if (!waveFile) {
Serial.println("wave file is invalid!");
while (1); // do nothing
}
// print out some info. about the wave file
Serial.print("Bits per sample = ");
Serial.println(waveFile.bitsPerSample());
long channels = waveFile.channels();
Serial.print("Channels = ");
Serial.println(channels);
long sampleRate = waveFile.sampleRate();
Serial.print("Sample rate = ");
Serial.print(sampleRate);
Serial.println(" Hz");
long duration = waveFile.duration();
Serial.print("Duration = ");
Serial.print(duration);
Serial.println(" seconds");
// adjust the playback volume
AudioOutI2S.volume(100);
// check if the I2S output can play the wave file
if (!AudioOutI2S.canPlay(waveFile)) {
Serial.println("unable to play wave file using I2S!");
while (1); // do nothing
}
// IF START PLAYBACK LOCATED HERE IT WORKS
// start playback
Serial.println("starting playback");
AudioOutI2S.play(waveFile);
// Start the RTC
rtc.begin(); // Initialize RTC
// IF START PLAYBACK LOCATED HERE, after rtc.begin();, IT DOESN'T
// start playback
// Serial.println("starting playback");
// AudioOutI2S.play(waveFile);
// Set the time
rtc.setHours(hours);
rtc.setMinutes(minutes);
rtc.setSeconds(seconds);
// Set the date
rtc.setDay(day);
rtc.setMonth(month);
rtc.setYear(year);
rtc.setAlarmTime(16, 0, 20);
rtc.enableAlarm(rtc.MATCH_HHMMSS);
rtc.attachInterrupt(alarmMatch);
}
void loop() {
// put your main code here, to run repeatedly:
}
void alarmMatch()
{
Serial.println("Alarm Match!");
}
Many thanks for any thoughts / assistance.