Playing file from SD-card on MKRZERO - SOLVED


Trying to play a soundfile from SD-card as the title suggest. Using mainly the code from the “Simple audio player”-tutorial. I used the setup from the SD-card sketch as the initializing of the card-part failed in the original sketch. Here’s my full sketch:

  Simple Audio Player for Arduino Zero

 Demonstrates the use of the Audio library for the Arduino Zero

 Hardware required :
 * Arduino shield with a SD card on CS4
 * A sound file named "test.wav" in the root directory of the SD card
 * An audio amplifier to connect to the DAC0 and ground
 * A speaker to connect to the audio amplifier

 Arturo Guadalupi <>
 Angelo Scialabba <>
 Claudio Indellicati <>

 This example code is in the public domain


// 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;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 28;
int track;

void setup() {
  // Open serial communications and wait for port to open:
  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

void loop()
  int count = 0;

  // open wave file from sdcard
  File myFile ="test.wav");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);

  // until the file is not finished;

  Serial.println("End of file. Thank you for listening!");
  while (true) ;

Tried replicating everything in the original tutorial but receive the following in the serial monitor:

20:47:27.555 →
20:47:27.555 → Initializing SD card…Wiring is correct and a card is present.
20:47:27.555 → error opening test.wav

If i run the SD card test sketch this is what i get:

20:56:29.874 →
20:56:29.874 → Initializing SD card…Wiring is correct and a card is present.
20:56:29.874 →
20:56:29.874 → Card type: SDHC
20:56:29.874 → Clusters: 242304
20:56:29.874 → Blocks x Cluster: 64
20:56:29.874 → Total Blocks: 15507456
20:56:29.874 →
20:56:29.874 → Volume type is: FAT32
20:56:29.874 → Volume size (Kb): 7753728
20:56:29.874 → Volume size (Mb): 7572
20:56:29.874 → Volume size (Gb): 7.39
20:56:29.874 →
20:56:29.874 → Files found on the card (name, date and size in bytes):
20:56:29.874 → BOOM-B~1.WAV 2016-05-08 09:05:36 55680732
20:56:29.874 → SDFHJK.WAV 2016-05-08 08:13:20 1245224
20:56:29.874 → TEST.WAV 2020-03-01 19:48:54 1748127

Tried searching for details regarding the audiozero library to figure out what is what but can’t find much information. Would love some help.


Just a guess - This wouldn’t matter on a computer but try changing the file name in the code to capital letters (TEST.WAV) since that’s how it shows-up in the test sketch.

Thx for the suggestion, no change though unfortunately. Anyone else?

Got it to work after all. The reason i changed the original tutorial code was because i couldn’t get the SD card to initialize, which was beacuse i hadn’t read up enough and didn’t change the pinsetting in the SD.begin-command in the original code. Not sure why the code i posted didn’t do the trick but will have to settle (for now) for what works. Thanks for the help.