I have an Arduino MKR Zero set up with an sd card in it and a speaker hooked up to the ground and DAC0. I have a .wav file on it called "test.wav" and it is 8-bit mono 88200hz recording. I am using the AudioZero example to try to play this audio file off the speaker but it is not working. When I upload and run the code and open the Serial Monitor to check to see if it has any errors or successes reading the files and it just says "Initializing SD card... done." and then it just freezes and doesn't get any further. It uploads the code all fine, but the Serial Monitor doesn't say anything more and the speaker doesn't play anything. Did I set it up wrong somehow?
Here is the code that it is running:
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 <a.guadalupi@arduino.cc>
Angelo Scialabba <a.scialabba@arduino.cc>
Claudio Indellicati <c.indellicati@arduino.cc>
This example code is in the public domain
http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero
*/
#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>
void setup()
{
// debug output at 115200 baud
Serial.begin(115200);
while (!Serial);
// setup SD-card
Serial.print("Initializing SD card...");
if (!SD.begin(SDCARD_SS_PIN)) {
Serial.println(" failed!");
return;
}
Serial.println(" done.");
// hi-speed SPI transfers
SPI.setClockDivider(4);
// 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);
AudioZero.end();
Serial.println("End of file. Thank you for listening!");
while (true) ;
}
I have an Arduino MKR Zero set up with an sd card in it and a speaker hooked up to the ground and DAC0.
That might have fried DAC0. Speakers usually have an impedance of 8Ω. At 3.3V that produces a current of 0.4A, much to high for any pin of the MKR Zero.
Have you read the comment in your sketch?
* An audio amplifier to connect to the DAC0 and ground
If you have "powered" computer speakers you can try those. They have an input impedance around 10K with a built-in amplifier to drive the low impedance speaker(s).
The minimum load on a regular Arduino is 125 Ohms (40mA at 5). I don't know anything about the MKR Zero chip but I'm sure it can't drive an 8-Ohm load.
pylon:
If you know that it freezes you probably have a serial output that shows what happened. Why did you fail to provide that information to us?
What do you mean? If you re-read my post I say exactly what the serial output gives me. It says that the sd card initializes but it never starts playing audio or ever finishing the audio to say that it has finished. It just says initialized and then doesn't go any further. If it went furthur the audio would probably play now that I have the speaker set up correctly with the amp.
I just ran this code on the MKR hooked up to a speaker and it works just fine:
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
// no need to repeat the melody.
}
It's a tone melody and it plays just fine off the MKR which means the audio zero program is freezing at some point. Is there any way I can re-structure the code so that this may not happen?
It just says initialized and then doesn't go any further. If it went furthur the audio would probably play now that I have the speaker set up correctly with the amp.
A description of what you see is not the same as the actual exact output you got. If you want help post the information we ask for.
From your description I would conclude that your SD card does not work. Maybe you can change that conclusion if you deliver more exact output data.
pylon:
A description of what you see is not the same as the actual exact output you got. If you want help post the information we ask for.
From your description I would conclude that your SD card does not work. Maybe you can change that conclusion if you deliver more exact output data.
The actual serial monitor text was in my original post, but I'll say it again. The serial monitor gives me this exactly: "Initializing SD card... done." That's it, and then it freezes. It doesn't give me any sd errors or any other errors it just stops right there.
My SD works perfectly. There is nothing wrong with it because when I run getcardinfo I get all the specs of the card without any issues. I have run all the tests necessary to see that the board works perfectly and the sd is also working just fine, so I'm not sure why the program is not playing the audio files.
The actual serial monitor text was in my original post, but I'll say it again. The serial monitor gives me this exactly: "Initializing SD card... done." That's it, and then it freezes. It doesn't give me any sd errors or any other errors it just stops right there.
Comment out all lines using the AudioZero object. Does it still freeze at after the above line? Do you get other output?
If that runs without problems, uncomment the AudioZero lines again. Insert the following line at the top of the loop():
Serial.println("Running loop");
If you don't see that line, the initialization code of AudioZero fails. The only code I found with potential for an endless loop is the wait loop for the TC to get in sync. I'm not an expert for this but did you replace your Zero after the mistreatment with the direct speaker connection? That might have destroyed part of the processor which may result in such a malfunction. The ARM based Arduino are much less forgiving if you wire them wrongly.