0
\$\begingroup\$

I have a music player via an ESP32 and an SD card module

Structure:

SD card module (with the .wav files) -> ESP32

ESP32 pin 26 to Audio amplifier module LM386 IN (with 10µF capacitor between IN and GND) and ESP32 GND to Audio amplifier module LM386 GND and from Audio amplifier module LM386 GND and VCC to the external power supply constant 5V

From audio amplifier module GND and OUT to the loudspeaker (8 Ohm 100W)

Scematic

Problem:

When I want to play the .wav files from the SD card via the ESP32, I always get a loud noise when it plays and only the music of the .wav file in the background

Can anyone help me?

Code (is just the code snippet):

bool startAudioPlayback(const String& pfad) {
  // Vorhandene Instanzen löschen, um Speicherlecks zu vermeiden
  if (wav != nullptr) {
    wav->stop();
    delete wav;
    wav = nullptr;
  }
  if (file != nullptr) {
    delete file;
    file = nullptr;
  }
  if (out != nullptr) {
    delete out;
    out = nullptr;
  }

  // Neue Instanzen erstellen
  out = new AudioOutputI2S();
  out->SetPinout(27, 26, 26);  // Anpassen der Pins je nach ESP32 Setup
  out->SetGain(0.1);           // Setzt die Lautstärke auf 10%
  out->SetRate(480000);         // Common sample rates are 44100 or 48000 Hz
  out->SetBitsPerSample(16);   // Use 16 for CD quality audio
  out->SetChannels(2);         // Set to 2 for stereo

  file = new AudioFileSourceSD(pfad.c_str());  // Dateipfad als C-String übergeben
  if (!file->isOpen()) {
    Serial.println("Fehler: Datei konnte nicht geöffnet werden");
    delete file;
    file = nullptr;
    delete out;
    out = nullptr;
    return false;
  }

  wav = new AudioGeneratorWAV();
  bool success = wav->begin(file, out);

  if (success) {
    Serial.println("Spiele Audio ab...");
    while (wav->isRunning()) {
      if (!wav->loop()) {
        wav->stop();
      }
      delay(1);  // Kürzere Verzögerung, um die Schleife effizienter zu machen
    }
    Serial.println("Audiowiedergabe abgeschlossen.");
  } else {
    Serial.println("Fehler beim Starten der Audiowiedergabe");
  }

  // Instanzen löschen
  delete wav;
  delete file;
  delete out;

  // Instanzen auf NULL setzen, um wiederholte Zugriffe zu verhindern
  wav = nullptr;
  file = nullptr;
  out = nullptr;

  return success;
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ I2S is a digital format. You can't send I2S to an analog amplifier and expect sensible results. I'm amazed you hear any music at all from your speaker. \$\endgroup\$
    – brhans
    Commented Aug 19 at 11:40
  • \$\begingroup\$ There is a codec, that produces an analog output compatible signal, using the I2S hardware, named "AudioOutputI2SNoDAC". The sound quality is not optimal, but it will probably work with your amplifier. \$\endgroup\$
    – Jens
    Commented Aug 19 at 12:10

1 Answer 1

1
\$\begingroup\$

You can't put a 10uF capacitor from DAC output to GND. Or from any IO pin for that matter. It will prevent the audio from working and may even damage MCU output. Remove it.

Maybe you intended to connect the cap in series to remove DC. So connect it accordingly.

Also the component values are unknown. At least don't mount the bass boost components until you get it working. And make sure the Zobel network is present for providing high frequency load impedance so the amp does not oscillate.

There is also no supply bypass cap on the supply inpu pin or on the bypass filter pin.

If you draw the circuit and components as per the data sheet examples, it should work.

Edit: Also, your schematics are not correct because you say you use a LM386 module bought from Amazon. It also has realy

And you are outputing the WAV file as digital audio stream on I2S bus, you have no DAC to convert it to analog and you connected the digital output which is just series of bits into the analog amplifier.

Which is why it sounds the way it does - you can hear the audio being distorted but recognizable, because I2S data output is not analog audio, it's digital bits.

\$\endgroup\$
3
  • \$\begingroup\$ How do you mean that i´m not so good in this theme (Electric and Music) I untersdant that i remove the 10µF Capacitor but the rest not And what i forgot to say the external Power (5V) is from a handy charger \$\endgroup\$ Commented Aug 19 at 11:01
  • \$\begingroup\$ @FischerFritz by handy do you happen to mean German for mobile phone charger? These may be noisy. But do read the LM386 data sheet for examples. It explains the terminology as well. \$\endgroup\$
    – Justme
    Commented Aug 19 at 11:46
  • \$\begingroup\$ OK I now realized you are using some random Amazon bought module so what you draw in the schematics is not really what you have. And also you are outputing digital I2S audio to the pin, not analog, you have no DAC. \$\endgroup\$
    – Justme
    Commented Aug 19 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.