Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Using LM386 audio amp with audio shield line out

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    2

    Using LM386 audio amp with audio shield line out

    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.

    Click image for larger version. 

Name:	Screenshot 2019-04-01 at 12.55.25.jpg 
Views:	20 
Size:	43.5 KB 
ID:	16396

    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!!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,914
    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.

    Click image for larger version. 

Name:	lm386.png 
Views:	4 
Size:	11.3 KB 
ID:	16397

  3. #3
    Junior Member
    Join Date
    Apr 2019
    Posts
    2
    Thank you so much Paul for the quick reply! I will try again with your recommended changes and see how it goes. Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •