0

PAM8302 connected to MKRZERO makes buzzing Noise
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PAM8302 connected to MKRZERO makes buzzing Noise

by egbrugel on Mon Aug 02, 2021 8:14 am

I have a PAM8302 connected to a MKRZERO thru the DAC0 pin.
When I run the "SimpleAudioPlayerZero" Example everything starts off fine.
But when the file ends the output is a loud buzzing sound?
I've tried several suggestions I found on the arduino forum
- 10K resistor between DAC0 and ground
- analogWrite(A0, 125);
Still buzzing
I'm using the MPU6050 to trigger the WAV files. At first I thought it was interference from the MPU6050, but after taking it out of the circuit the noise continues.
THank you
Ed
Attachments
MKRZERO-PAM8302-MPU6050.jpg
MKRZERO-PAM8302-MPU6050.jpg (54.79 KiB) Viewed 147 times

egbrugel
 
Posts: 17
Joined: Wed Jul 07, 2021 1:02 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by egbrugel on Mon Aug 02, 2021 8:17 am

Sorry forgot the code

Code: Select all | TOGGLE FULL SIZE
#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

void setup()
{
  // debug output at 115200 baud
  Serial.begin(9600);

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(28)) {
    Serial.println(" failed!");
    while(true);
  }
  Serial.println(" done.");

  // 44100kHz stereo => 88200 sample rate
  AudioZero.begin(2*44100);
}

void loop()
{
  int count = 0;

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

  Serial.print("Playing");
 
  // until the file is not finished 
  AudioZero.play(myFile);

  Serial.println("End of file. Thank you for listening!");
  analogWrite(A0, 125);
  while (true) ;
}
Last edited by adafruit_support_carter on Tue Aug 03, 2021 5:21 pm, edited 1 time in total.
Reason: added [code] tags

egbrugel
 
Posts: 17
Joined: Wed Jul 07, 2021 1:02 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by egbrugel on Mon Aug 02, 2021 10:11 am

I hooked up a LM386 module amp and I get no sound playing, It does appear the amp is working?
Do I need an I2S amp??
Thanks
Ed

egbrugel
 
Posts: 17
Joined: Wed Jul 07, 2021 1:02 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by adafruit_support_carter on Tue Aug 03, 2021 5:24 pm

You can use the SD (shutdown) pin on the PAM8302 to shutdown the amp when not in use. That way it won't make noise when not playing back files.

LOW = off
HIGH = on

adafruit_support_carter
 
Posts: 21106
Joined: Tue Nov 29, 2016 2:45 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by egbrugel on Tue Aug 03, 2021 7:43 pm

Thank you.
I got the
analogWrite(1, LOW);
to work when the File finished
But, having trouble understanding where to put the
analogWrite(1, HIGH)
when the Loop continues to play
When I comment out While(true); it should play again, but the loop works, just no sound?
Thanks
Ed

I'm just using SimpleAudioPlayerZero
Code: Select all | TOGGLE FULL SIZE
#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

void setup()
{
  // debug output at 115200 baud
  Serial.begin(9600);

  // setup SD-card
  Serial.print("Initializing SD card...");
  if (!SD.begin(28)) {
    Serial.println(" failed!");
    while (true);
  }
  Serial.println(" done.");

  // 44100kHz stereo => 88200 sample rate
  AudioZero.begin(2 * 44100);
  //analogWrite(1, HIGH);
}

void loop()
{
  int count = 0;

  // open wave file from sdcard
  //analogWrite(1, HIGH);
  File myFile = SD.open("C5.wav");
  //
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }
  Serial.print("Playing");
  // until the file is not finished
  AudioZero.play(myFile);
  analogWrite(1, LOW);
  Serial.println("End of file. Thank you for listening!");
  delay(10000);
  analogWrite(1, HIGH);
  delay(10000);
  //while (true) ;
}
Last edited by adafruit_support_carter on Wed Aug 04, 2021 10:58 am, edited 1 time in total.
Reason: added [code] tags

egbrugel
 
Posts: 17
Joined: Wed Jul 07, 2021 1:02 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by adafruit_support_carter on Wed Aug 04, 2021 11:02 am

Not sure. You may need to close the file at the end of the loop before trying to reopen it again. May also need to add a call to AudioZero.end()?
https://www.arduino.cc/en/Reference/AudioZeroEnd

Use digitalWrite() instead of analogWrite() to control the shutdown pin on the PAM.

adafruit_support_carter
 
Posts: 21106
Joined: Tue Nov 29, 2016 2:45 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by egbrugel on Wed Aug 04, 2021 11:44 am

OK< thank you
I wasn't sure of analog or digital... still learning these boards

egbrugel
 
Posts: 17
Joined: Wed Jul 07, 2021 1:02 pm

Re: PAM8302 connected to MKRZERO makes buzzing Noise

by egbrugel on Wed Aug 04, 2021 5:28 pm

Well, turns out I had to use the entire AudioZero() library
AudioZero.begin()
AudioZero.end()
Audio.Zero.play()

while (i < 2) {
// open wave file from sdcard
AudioZero.begin(2 * 44100);
File myFile = SD.open("C5-882.wav");
//
if (!myFile) {
// if the file didn't open, print an error and stop
Serial.println("error opening test.wav");
while (true);
}
Serial.print("Playing");
// until the file is not finished
AudioZero.play(myFile);
AudioZero.end();
Serial.println("End of file. Thank you for listening!");
Serial.print(i);
delay(5000);
i++;
break;
}

Thanks for the Help
Ed

egbrugel
 
Posts: 17
Joined: Wed Jul 07, 2021 1:02 pm

Please be positive and constructive with your questions and comments.