Trying to use the example wav player sketch to get a sound file to play. Have followed all of the instructions as laid out here: https://www.arduino.cc/en/Guide/ArduinoMKRZero but cannot get the thing to play a wav file! It just tells me "unable to play wave file using I2S!". The wav file has been converted to the correct format using Audacity and it does work on other Arduino/SD card players so I know it's good.
For the sake of my sanity would someone please be able to help?
I'm quite possibly missing something obvious but after nearly two days of searching for a solution I'm close to crushing this board under my boot!
#include <SD.h>
#include <ArduinoSound.h>
// filename of wave file to play
const char filename[] = "start.wav";
// variable representing the Wave File
SDWaveFile waveFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
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...");
if (!SD.begin(SDCARD_SS_PIN)) {
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(5);
// 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
}
// start playback
Serial.println("starting playback");
AudioOutI2S.play(waveFile);
}
void loop() {
// check if playback is still going on
if (!AudioOutI2S.isPlaying()) {
// playback has stopped
Serial.println("playback stopped");
while (1); // do nothing
}
}