Problem playing wav files

Hi. I’m really struggling with playing wav files.
I have …
Mega 2560 board
mkrvrs pam8302a amp
mkrvrs ce07926 SD module
mcp4725 dac
The code I am using says that the SD module is initialised and the wav file is found.
The Serial.println lines tell me that the wav is playing and that the wav has ended and then it repeats.
Connections …
SD module
5v connected
GND connected
CS = pin 53
MOSI = pin 51
CLK = pin 52
MISO = pin 50
Amp
GND connected
5v connected
GND connected
IN = MCP4725 OUT pin
MCP4725
GND connected
5v connected
SDA = pin 20 (SDA)
SCL = pin 21 (SCL)
GND connected
OUT = Amp IN pin

Amp SD pin is not used
SD Module CD is not used

But the sound I am getting is a constant noise, like a cat purring, or a small motor boat engine putt putting.
Any help would be really appreciated, thanks
Sketch …

#define SD_CS_PIN 53

#include <Wire.h>
#include <Adafruit_MCP4725.h>
#include <SPI.h>
#include <SdFat.h>

Adafruit_MCP4725 dac;
SdFat sd;
SdFile file;

void setup()
  {
    Serial.begin(9600);
    Serial.print("Initializing SD card: ");
    if(!sd.begin(SD_CS_PIN))
      {
        Serial.println("failed");
        sd.initErrorHalt();
      }
    Serial.println("done");
  
    // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
    // For MCP4725A0 the address is 0x60 or 0x61
    // For MCP4725A2 the address is 0x64 or 0x65
    dac.begin(0x62);
  }

void loop()
  {
    Serial.println("4.wav");
    // open wave file from sdcard
    if(!file.open("4.wav", O_READ))
      {
        sd.errorHalt("opening test.txt for read failed");
      }
    Serial.println("Playing 4.wav");
    while(file.available())
      {
        dac.setVoltage(file.read()*1, false);
      }
    file.close();
    Serial.println("Finished playing.");
  }

// END OF CODE

Hello, which particular board are you using? Usually, wav files need some optimizations before you store them in the SD card and play with an Arduino.

1 Like

Hey @Chris282006,

Interesting problem. Would you be able to confirm what specific components you are using?

So far I have:

It would be useful if you could let me know the specific modules you are using that I haven’t caught or correct me if I have anything wrong.

Hi Lia

Thanks very much for your reply.

My board is a “Duinotech MEGA 2560 r3 Main Board”
Features:
• Fully Arduino®and DuinoTECH Compatible
• ATMega2560 Microcontroller
• EEPROM: 256KB
• Speed: 16MHZ
• ATMega16u2 USB-Serial Chipset
• IO:
Digital IO: 54 pins (15 are configurable as Digital or PWM)
PWM Capable: 15 pins
Analogue Inputs: 16pins
Serial Ports: 4 (1 is connected to on-board usb-Serial port)• Input Voltage:
5VDC Regulated via USB port or 5V pin
7-14VDC via Vin pin
On-board regulator supplies 5V when unit is powered via Vin pin

My wavs are only short in length, e.g. 10 secs.
I created them in Audacity …
e.g.
Export Audio
“1.wav”
Format : WAV (Microsoft)
Channels : Mono
Sample rate : 16000hz
Encoding : Unsigned 8-bit PCM
(saved to root of SD card)

If you are able to help that would be much appreciated
Chris

Hi Samuel
Thanks so much for replying

My board is “Diunotech MEGA 2560 r3 Main Board”
Features :
• Fully Arduino®and DuinoTECH Compatible
• ATMega2560 Microcontroller
• EEPROM: 256KB
• Speed: 16MHZ
• ATMega16u2 USB-Serial Chipset
• IO:
Digital IO: 54 pins (15 are configurable as Digital or PWM)
PWM Capable: 15 pins
Analogue Inputs: 16pins
Serial Ports: 4 (1 is connected to on-board usb-Serial port)• Input Voltage:
5VDC Regulated via USB port or 5V pin
7-14VDC via Vin pin
On-board regulator supplies 5V when unit is powered via Vin pin

The DAC is : Sparkfun Breakout Board for MCP4725 I2C DAC (SKU: BOB-12918)

Any further help would be much appreciated, thanks
Chris

I don’t think that will work. A WAV file is not just an audio data stream - it is a structured file that uses a RIFF wrapper.

There is a description here of how to decode a WAV file in order to find the audio data. There is also a library example available.

Thanks Jeff
I’ll look into this
Chris