arduino / arduino/ArduinoCore-samd
Incompatibility between MKRZERO RTC & I2S libraries
- Dominant language
- C
- Stars
- 502
- Forks
- 740
- PR merge metrics
- No merged PRs in 30d
Description
There appears to be an incompatibility between the ArduinoSound.h and RTCZero.h libraries.
When you 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.
```c++
#include // SD card access library
#include // I2S sound interface library
#include // 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() {
}
void alarmMatch() {
Serial.println("Alarm Match!");
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the provided MKRZERO sketch and reproduce the difference between calling AudioOutI2S.play(waveFile) before and after rtc.begin(), using ArduinoSound.h, RTCZero.h, and the Adafruit MAX98357A setup. Trace the initialization interaction, then verify that the WAV plays after rtc.begin() while RTC setup and alarms still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- audio-video-rtc, embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100