I'm still a bit new to arduino, so I may be missing something obvious here.
I'm using a knockoff uno from "sainsmart"
I installed the TMRpcm library, hooked up an 8ohm speaker to an audio amp circuit (using LM386 and capacitors) and converted an audio file to unsigned 8 bit PCM, but I can't get it to play. (I went into audacity, set the project rate to 32,000, resampled the track at 32,000, exported as "audio," saved as "other uncompressed files," set the header to WAVEX (microsoft) because WAV microsoft was not available, and encoding to unsigned 8-bit PCM. I also tried downloading a few WAVs from forums where other people were using TMRpcm) The speaker is working, because if use the tone() command, (although it's a bit finnicky) I can hear it clearly. If I run audio.isPlaying immediately after audio.play, it returns true, but if I trigger audio.isPlaying via the serial monitor, it returns false. For a short time, after switching out the audio file, audio.isPlaying would return true and the speaker would play static. After shuffling in and out some more audio files and reformatting the SD card to make sure it wasn't corrupted, I'm back where I started. If I plug the SD card into my computer and try to play the audio from there, it works fine. I was hearing a beep whenever I reset the board, so I tried commenting and uncommenting #define SD_FULLSPEED in pcmConfig, but to no avail. I'm running out of ideas...
Could it be a hardware issue? I figured the tone() test would have disproved that, but it's possible I'm missing something.
Is it possible my SD card is corrupted? I don't think it is given that I can play the audio off it using my computer and I've already reformatted it twice, but maybe there's some small flaw in it that the library doesn't like?
Is there a setting in pcmConfig I need to mess around with? I've uncommented #define DISABLE_SPEAKER2 because I'm using a shield to connect my SD card to the arduino, but it doesn't seem to have changed anything.
Strangely, the audio gets more static-y when I touch the knob on my potentiometer. I'm not sure if this is relevant but I just thought it was weird...
If anyone can help me figure out the problem, it would be much appreciated!
Edit: I ran the code here: https://www.arduino.cc/en/Tutorial/LibraryExamples/CardInfo to test if the SD card was working. I had to change the chip select pin to 4, like it is in my code, and then the check succeeded.
#include <SD.h>
#define SD_ChipSelectPin 4
#include <TMRpcm.h>
#include <SPI.h>
TMRpcm tmrpcm;
TMRpcm audio;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
tmrpcm.speakerPin = 9;
Serial.println("Running setup...");
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(6);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available() > 0) {
char menu = Serial.read();
if(menu == '1') {
setup();
}
else if(menu == '2') {
Serial.println("playing tone...");
tone(9, 1000, 1000);
}
else if(menu == '3') {
Serial.println(audio.isPlaying());
}
else if(menu == '4') {
Serial.println("playing music...");
audio.play("music1.wav");
}
else if(menu == '5') {
audio.stopPlayback();
Serial.println("stopping...");
}
}
}
I've added some pictures of the circuit below; sorry they're not very pretty.
*The reason I have four capacitors on the edge is because the schematics I found online varied between 220uF and 250uF. I decided to go with 220 but I didn't have one, so I have here two 100s and two 10s in parallel.

