Using LM386 audio amp with audio shield line out

Status
Not open for further replies.

hm311

New member
Hi everyone,

I am making an interactive wearable project and I decided to use the Teensy 3.2 because of how compact it is. It's my first time using the Teensy. I needed to add sound to my project so I connected the audio adaptor board to be able to output sounds stored on an SD card through a 0.5W 8ohm speaker. In a previous project using Arduino I used an LM386 to amplify the sound going into a speaker following this circuit I found in a tutorial (see attached circuit diagram) so I thought I could do the same with the Teensy.

Screenshot 2019-04-01 at 12.55.25.jpg

With the audio board, I connected the Left line out to a 1K resistor connected to pin 3 of the LM386 and the Ground pin next to the left line out to pin 2 of the chip. All the capacitors shown in the diagram are connected the same as well. However when I tried the WavFilePlayer Sketch Example, I got good sound from the headphones but only a constant clicking sound comes out of the speaker with some noise. Is it possible that no sound is coming out of the speaker because the minimum supply voltage required for the LM386 is 4V and the Teensy only supplies 3.3V? Or could the problem be with the speaker? Here is the code from the WavFilePlayer example:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdWav           playWav1;
AudioOutputI2S           audioOutput;
AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14



void setup() {
  Serial.begin(9600);

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);

  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.3);

  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void playFile(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.println(filename);

  // Start playing the file.  This sketch continues to
  // run while the file plays.
  playWav1.play(filename);

  // A brief delay for the library read WAV info
  delay(5);

  // Simply wait for the file to finish playing.
  while (playWav1.isPlaying()) {
   
  }
}


void loop() {
  playFile("SDTEST1.WAV");  // filenames are always uppercase 8.3 format
  delay(500);
  playFile("SDTEST2.WAV");
  delay(500);
}

Any advice would be appreciated. Thank you!!
 
I see at least 2 problems with your schematic.

1: You've got a 100nF capacitor directly from pin 5 to GND. Not good! If you look at recommended schematics for the LM386, you'll see a resistor is supposed to be in series with that cap. Either add a 10 ohm or higher resistor, or just remove the capacitor if you have short wires between the chip and speaker. Using the capacitor without a resistor is bad.

2: LM386 gain is a minimum of 20. Teensy's output signals are approx 1 Vp-p. You need to reduce the signals, because they're too much for the LM386. Recommend changing those 1K resistors to 10K. Then add a 10K pot, so you can adjust the signal level, like shown on page 8 of the LM386 datasheet.

lm386.png
 
Thank you so much Paul for the quick reply! I will try again with your recommended changes and see how it goes. Thanks again!
 
Status
Not open for further replies.
Back
Top