Go Down

Topic: Noise on Due DAC when reading from MicroSD through SPI (Read 1 time) previous topic - next topic


Hi all,
I know this has already been asked (http://forum.arduino.cc/index.php?topic=150378.0) but since noone is answering on that topic I'm hoping to have better luck here.
I'm an experienced programmer but I'm just beginning with electronics, so please bear with me if I write silly stuff.
I'm trying to run the SimpleAudioPlayer example on a Due (see the code at http://arduino.cc/en/Reference/AudioBegin), reading a mono WAV file from a microSD card and playing it through the DAC, which is connected to an amplifier breakout, which in turn is connected to a speaker. See the attached images for details.
Everything works fine, except that there's a ground noise mixed with the audio that seems to be related to the microSD card reading.
The microSD card socket is directly wired to the SPI interface of the DUE, since it already works at 3.3v which is the required level for microSD. More specifically, I've attached the pins as follows (see http://en.wikipedia.org/wiki/Secure_Digital#Transfer_modes for microSD pin numbering, and http://arduino.cc/en/Reference/SPI for Arduino SPI header pin numbering):

- microSD pin 2 (nCS) to Digital Pin 10
- microSD pin 3 (DI) to SPI MOSI (pin 4 of the SPI header)
- microSD pin 4 (VDD) to 3.3v Pin
- microSD pin 5 (CLK) to SPI SCK (pin 3 of the SPI header)
- microSD pin 6 (VSS) to GND Pin
- microSD pin 7 (DO) to SPI MISO (pin 1 of the SPI header)
- microSD pin 1 and 8 not wired to anithing

The WAV files reads fine, so I guess my wiring is correct (at least from at logic level).

I'm using Sparkfun's Mono Audio Amp Breakout with TPA2005D1 as an amplifier, see https://www.sparkfun.com/products/11044. The DAC0 and GND pins are connected to the amp's input + and - respectively. The amp's power + and - are connected to pins 5.5v and GND on the arduino (I've already tried using 3.3 but the noise is still there). The amp's output + and - are connected to a 1.5W speaker (http://it.rs-online.com/web/p/altoparlanti-miniatura/7564618/).
All grounds (amp input-, amp power- and microsd pin 6) are connected to the same rail on the breadboard, which is then connected to a single GND pin on the arduino.

Things I've tried so far:
- switching DAC0 with DAC1: STILL noise
- powering the amp with 3.3v instead of 5v: STILL noise
- disconnecting ONLY DAC0 from the amp's input+: STILL noise at a lower volume
- disconnecting the microSD card completely so that nothing is read but the amp is powered: NO noise
- removing sparkfun's amp and attaching an external amplifier with speakers to DAC0: NO noise
- disconnecting DAC0 and GND from the amp's input, and connecting an external audio source to the amp's input (while it's still powered from the arduino): NO noise

Please help me, I have to ship this project for next week and the noise isn''t really acceptable. If required I can provide an mp3 with an example of the noise I'm hearing, and/or a complete schematic of the circuit.
Thanks in advance to everyone!

Finally, the code I'm using (it's the same as the SimpleAudioPlayer example, just modified to loop the wav indefinitely and use pin 10 as CS for the SPI):

Code: [Select]

  Simple Audio Player

Demonstrates the use of the Audio library for the Arduino Due

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

Original by Massimo Banzi September 20, 2012
Modified by Scott Fitzgerald October 19, 2012

This example code is in the public domain



#include <SD.h>
#include <SPI.h>
#include <Audio.h>

void setup()
  // debug output at 9600 baud

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(10)) {
    Serial.println(" failed!");
  Serial.println(" done.");
  // hi-speed SPI transfers

  // 44100Khz mono
  // 100 mSec of prebuffering.
  Audio.begin(44100, 100);

void loop()
  int count=0;

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

  const int S=1024; // Number of samples to read in block
  short buffer[S];

  // until the file is not finished
  while(true) {
    if(!myFile.available()) myFile.seek(0);
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));

    // Prepare samples
    int volume = 1024;
    Audio.prepare(buffer, S, volume);
    // Feed samples to audio
    Audio.write(buffer, S);

    // Every 100 block print a '.'
    if (count == 100) {
      count = 0;

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


Sep 06, 2013, 06:30 am Last Edit: Sep 06, 2013, 06:32 am by Grumpy_Mike Reason: 1
Does that not suggest that it is Sparkfun's amplifier causing the problem?
It looks like you could try and improve that with extra supply decoupling.

It is also a class D amplifier that is probbly where the noise is being generated.


Thanks for your reply, unfortunately I'm sure that it's not the amp because if I use it without the arduino, or even if I power it with the arduino but feed it with an external audio source, it works fine without any noise at all. Moreover, I've tried 3 of them (I have to build 3 prototypes), and all three have the noise problem when I read from the sd card.


But you said
- removing sparkfun's amp and attaching an external amplifier with speakers to DAC0: NO noise

So that suggests very strongly to me that the amplifier is the source of the noise. Why does it not to you?

You can try as many as you like but it is the fundamental design that is screwing you.


Sorry I didn't explain myself very clearly.
If I leave the circuit exactly as it is but I don't read from the sd card, there's no noise at all.
If I connect the amp's input to an external audio source (leaving the amp powered from the arduino), there's no noise either.
If I just disconnect the amp's input+ from DAC0 (leaving input- connected to arduino's GND), I obviously don't hear the audio playing, but I hear the ground noise at a lower volume when I read from the sd card. For this reason I'm quite convinced that the problem is related to the microsd messing with the ground level (sorry for the phrasing, I hope it's understandable).
Do you still think it may be the amp's fault?

Go Up