I have an Arduino MKR Zero set up with an SD card in it and headphones connected to ground and DAC0 for a test (I'm making the amplifier circuit for an 8ohm speaker as a permanent solution).
I also have a "test.wav" file in the root of the SD card, which is an 8-bit mono 82000hz recording; the file is under 1mb. When I upload the code and open the Serial Monitor, the card initializes correctly, but I get "error opening test.wav" every time.
I have tried exporting the file from Audacity many times, renaming it, playing with the size. The current file has been created in Audacity and exported with the attached settings through File - Export - Other Audio.
I'm also perplexed on why the sample suggests AudioZero.begin(2*44100) instead of AudioZero.begin(88200), but it doesn't work in any combination I've tried.
I would really appreciate any suggestions on what to try as the next step, as I've run out of ideas on how to troubleshoot this further.
Here is my code:
// include the SD library:
#include <SPI.h>
#include <SD.h>
#include <AudioZero.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// MKRZero SD: SDCARD_SS_PIN or 28
const int chipSelect = 28;
int track;
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
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}
// 44100kHz stereo => 88200 sample rate
AudioZero.begin(2*44100);
}
void loop()
{
int count = 0;
// open wave file from sdcard
File myFile = SD.open("test.wav");
if (!myFile) {
// if the file didn't open, print an error and stop
Serial.println("error opening test.wav");
while (true);
}
Serial.print("Playing");
// until the file is not finished
AudioZero.play(myFile);
Serial.println("End of file. Thank you for listening!");
while (true) ;
}