Buzzing sound play WAV file TMRpcm --> Help :'(

Hello everyone!

So let's start with: this is my first topic and Arduino project. I will try to explain as much as possible in this post my problem: please correct me if something is wrong!

I tried for hours and hours to play a wav music from my Elegoo Uno R3 (= arduino UNO) using the TMRpcm library, a 2W speaker (from a basic computer speaker), the TDA2822M chip and a micro SD card.

My issue is that the sound going out from the speaker contains a LOT of buzzing (cf. audio).

I first tested the SD reader and it appears it has no problem connecting to the card and reading the music (I guess). Moreover I can hear the music in the background of the buzzing.

I tried all the frequencies for the music (8000, 16000, 32000, 48000 Hz), I tried mono and stereo, I tried 8 and 16 bits. Well I tried to play many different WAV files and none of them actually worked.

I use the circuit from Figure 2 (Bridge) provided by the TDA2822M notice (https://www.st.com/resource/en/datasheet/cd00000134.pdf) and as the input on port 7 I connect to the port 9 of the Elegoo Uno R3. For +Vs I tried 5V and 3.3V but none of them gave a correct sound.

I am using the code written at the end of this post (for clearness). With the function "tmrpcm.setVolume(x)" I tested every value from 1 to 7: none of them gave a correct result. The only difference is that a bigger value gave a louder buzzing sound.

I tried to uncomment "#define DISABLE_SPEAKER2" in pcmConfig.h but nothing changed.

I tried to use the same speaker with tone and it correctly played the notes expected. I guess the problem does not come from the speaker.

Well I really need help otherwise I might shout loud from my balcony out of sadness.

Thank you for your help !!!


The code

#include "SD.h"
#define SD_ChipSelectPin 4
#include "TMRpcm.h"
#include "SPI.h"

TMRpcm tmrpcm;

void setup(){
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}

tmrpcm.setVolume(2);
tmrpcm.play("16000u.wav");
}

void loop(){ }

EDIT

I added the circuit made with Fritzing.

buzzing.aac.zip (92.6 KB)

Tiipiac:
I tried to use the same speaker with tone and it correctly played the notes expected. I guess the problem does not come from the speaker.

Doesn't follow, tone generates a square wave so won't show up distortion at all.

You need to provide the circuit diagram of how you've connected everything.

Firstly are you using an amp on the speaker? I would
Secondly I found in similar circuit I had to use low-pass filter (1K resistor + 1uF cap) < this helped me a lot.

rickyelqasem:
Firstly are you using an amp on the speaker? I would
Secondly I found in similar circuit I had to use low-pass filter (1K resistor + 1uF cap) < this helped me a lot.

The OP goes to the trouble of telling us there's a TDA2822M, I presume since its an audio amplifier
its being used as one!

There are several possible issues that we need to see the circuit to evaluate.

Everyone thank you for your replies!!! Sorry I lost my computer (RIP) so I could not answer faster.

Yes I use the TDA2822m as an amplifier. Well I try to.

I tried the low-pass filter (1K resistor + 1uF cap) as suggested but it did not work. You can hear the sound in the attached file and it is not pleasant.

Does anyone have some ideas ?

low_pass_filter.aac.zip (90.6 KB)

I'll repeat myself:

"You need to provide the circuit diagram of how you've connected everything."

Without that we have nothing at all to go on.

I am sorry I forget to say: I added the diagram on the original post.

I added the diagram on the original post

Not much of a diagram though is it. It is almost impossible to read. When you make an schematic with a chip like this you need to use the symbol like in the data sheet, like this:-

Also from the sound of the file it suggests you have some feedback problems. That would normally be due to poor layout or lack of decoupling. So we need to see a photograph of your construction as well as an understandable schematic.

Did you ever resolve this? I'm experiencing more or less the same thing, buzzing that sounds like hair clippers. Been working for hours on it and tried all the same things, (different sample rates, tmrpcm.setVolume(), pcmconfig settings, etc). Still haven't figured it out. :frowning: Let me know.

First you have to see if your sample is ok.
Download an application called Audacity and drop your file into it. You will see the waveform, make sure it is an 8 bit file format and the waveform doesn’t clip. That is spend time with a flat top or bottom.

If that is OK then look at increasing the resistor or capacitor on your filter, it could be that your hearing is good and you can here the sample rate noise.