Problems using Adafruit electret mic amp and Audio library

Status
Not open for further replies.

mattcamp

Member
Hi,

I've been trying to get the Audio library to work with the Adafruit Electret Mic Amp (MAX4466).

I'm using the MonoPeakMeterAnalog example sketch, and I can't seem to get any input... very briefly I once had SOME level of input but the volume levels were so low that I basically had to hold the microphone against a speaker to get anything to register...and I'm not sure why it worked that one time but since then I've basically had nothing at all, no matter how loud a noise I make near it.

I know the mic amp works fine as I have other sketches using AnalogRead() which work just fine, and levels are good... but when using the Teensy Audio library nothing seems to work.

I have the mic on A0/pin 14 on my Teensy3.1, using the following code:

Code:
/* Mono peak meter example using Analog objects. Assumes Teensy 3.1

At a minimum DC decouple audio signals to/from Teensy pins with capacitors in the signal paths both in and out, 10uF is often used.
Possibly worthwhile to set up virtual ground at 3v3/2 for both, or if changing DAC REF to 1.2V then 1.2V/2 for output side.

This example code is in the public domain
*/

#include <Audio.h>
#include <Wire.h>
#include <SD.h>

//const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputAnalog        audioInput(A0);         // A0 is pin 14, feel free to change.
AudioPeak               peak_M;
//AudioOutputAnalog       audioOutput;            // DAC pin.

AudioConnection c1(audioInput,peak_M);
//AudioConnection c2(audioInput,audioOutput);

void setup() {
  AudioMemory(4);
  Serial.begin(Serial.baud());
}

elapsedMillis fps;

void loop() {
  if(fps>24) { // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.
    Serial.println();
    fps=0;
    uint8_t monoPeak=peak_M.Dpp()/2184.5321;
    Serial.print("|");
    for(uint8_t cnt=0;cnt<monoPeak;cnt++) Serial.print(">");
    peak_M.begin();
  }
}
 
Hey Matt, did you ever try this without having the
Code:
AudioOutputAnalog    audioOutput; // DAC pin
line commented out? I've a sneaking suspicion the Audio Library may still have the mild (imho) flaw of doing crucial set up steps only in the output objects - you don't need to uncomment the associated 'AudioConnection c2(....);' line but do retry this with the AudioOutputAnalog line back in play and tell me if it happens to change the result you are getting.
 
Hey Matt, did you ever try this without having the
Code:
AudioOutputAnalog    audioOutput; // DAC pin
line commented out? I've a sneaking suspicion the Audio Library may still have the mild (imho) flaw of doing crucial set up steps only in the output objects - you don't need to uncomment the associated 'AudioConnection c2(....);' line but do retry this with the AudioOutputAnalog line back in play and tell me if it happens to change the result you are getting.

I've just tried it, running the MonoPeakMeterAnalog example sketch directly as it comes (so with the Output still there), and still no joy.

I got the same thing again where it would get SOME input the first upload but VERY low level... but every upload since gives just nothing at all.
 
OK, first off I think I should tell you that when you transfer your sketch to a Teensy the Teensy will retain that sketch when you unplug it and just start running it again when it is powered again - if using the 'monitor' from Arduino you need to close it before re-plugging in the Teensy and re-open after Teensy has been enumerated by the system (enumeration is pretty quick but easy enough test is if the port associated with that Teensy is available then it has finished enum and is ready to 'play')

I once found, while mucking around with the analog input/output objects in the Audio Library, that sometimes sketches involving AudioInputAnalog and AudioOutputAnalog could seem dodgy immediately after programming Teensy 3.1 with my sketch but if I disconnected Teensy and reconnected and re-opened the com port then my code would execute and perform as I expected - probably wrong about this but I suggest programming the Teensy and then power cycling it before bothering to check if there is apparent sign of 'action' related to the microphone.

Are you powering the adafruit electret mic (pre)amp from GND and 3.3V straight off Teensy? If not then please rewire to make it so.

There is a little SMT trimpot on the far side (from mic) of the adafruit PCB and I am pretty sure it is their gain control, turning it ccw should make the output smaller and turning it cw should make it louder if they have followed general convention for such a control there - while under any circumstance you have 'action' in the terminal/monitor which is clearly (enough) depicting noises made near the microphone you can try turning it up until either you are happier about the signal level per noise made or you max it out.

Once you have a repeatable result, wherein signal from the microphone clearly effects the output from MonoPeakMeterAnalog roughly the same for repeated noises made near the microphone, we can talk about possibly using AudioMixer4 to adjust the gain.


Does any of this help? Post back where this info gets you and hopefully more/better help will be forthcoming.
 
OK, first off I think I should tell you that when you transfer your sketch to a Teensy the Teensy will retain that sketch when you unplug it and just start running it again when it is powered again - if using the 'monitor' from Arduino you need to close it before re-plugging in the Teensy and re-open after Teensy has been enumerated by the system (enumeration is pretty quick but easy enough test is if the port associated with that Teensy is available then it has finished enum and is ready to 'play')

I've had a brief play this morning before work and can confirm that when I first powered up the teensy and uploaded the sketch I was indeed getting some input, albeit low-level.

I then re-uploaded the sketch and got nothing as expected. However even after stopping the serial monitor, unplugging the teensy, replugging it and re-opening serial monitor I couldn't get anything. I even tried leaving the teensy unplugged for a solid 60 seconds to no avail. The only thing I didn't try was a complete unplug combined with a total restart of the Arduino IDE... either way, something isn't happy there.

Are you powering the adafruit electret mic (pre)amp from GND and 3.3V straight off Teensy? If not then please rewire to make it so.

I am indeed. It's working great on other AnalogRead() sketches, just not when using the Audio library.

There is a little SMT trimpot on the far side (from mic) of the adafruit PCB and I am pretty sure it is their gain control, turning it ccw should make the output smaller and turning it cw should make it louder if they have followed general convention for such a control there - while under any circumstance you have 'action' in the terminal/monitor which is clearly (enough) depicting noises made near the microphone you can try turning it up until either you are happier about the signal level per noise made or you max it out.

As above, I've got other sketches where the microphone is working great through AnalogRead(). The gain is high enough that those other sketches can pick up background noise and someone talking on the other side of the room, whereas on the few times Audio does work it basically requires me to clap less than 10cm from the mic to get any reading at all.
 
This might be meaningless but the only way I have seen this done: AudioConnection c1(audioInput,peak_M); Is AudioConnection c1(audioInput,0,peak_M,0);
 
Some progress:

I've now got the teensy reliably booting and having some form of audio input every time... I'm not sure what it was about the original MonoPeakMeterAnalog example sketch but when I replaced the input and connection routines with those taken from the FFT example (but changed to be Analog) it's now reliable... Could be the slight changes as mentioned by cartere.

So now the follow code works, however the input level is still really low. I'm having to use a gain of 20 on the mixer to get meaningful levels... is this normal?

Code:
/* Mono peak meter example using Analog objects. Assumes Teensy 3.1

At a minimum DC decouple audio signals to/from Teensy pins with capacitors in the signal paths both in and out, 10uF is often used.
Possibly worthwhile to set up virtual ground at 3v3/2 for both, or if changing DAC REF to 1.2V then 1.2V/2 for output side.

This example code is in the public domain
*/

#include <Audio.h>
#include <Wire.h>
#include <SD.h>

const int myInput = AUDIO_INPUT_LINEIN;
// const int myInput = AUDIO_INPUT_MIC;

AudioInputAnalog        audioInput(A0);        // audio shield: mic or line-in
AudioPeak               peak_M;
AudioOutputI2S      audioOutput;        // audio shield: headphones & line-out
AudioMixer4        mix1;

AudioConnection c1(audioInput, 0, mix1, 0);
AudioConnection c2(mix1,0,peak_M,0);
AudioConnection c3(mix1, 1, audioOutput, 1);

void setup() {
  AudioMemory(4);
  Serial.begin(Serial.baud());
  mix1.gain(0, 20.0);
}

elapsedMillis fps;

void loop() {
  if(fps>24) { // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can.
    Serial.println();
    fps=0;
    uint8_t monoPeak=peak_M.Dpp()/2184.5321;
    Serial.print("|");
    for(uint8_t cnt=0;cnt<monoPeak;cnt++) Serial.print(">");
    peak_M.begin();
  }
}
 
I had a similar issue using the same mic, the problem is the Internal Voltage Reference is enabled in the library, meaning Teensy only looks for voltages from 0.0-1.2v, while the mic floats at 1/2 of 3.3v (1.65v).

//analogReference(INTERNAL); // range 0 to 1.2 volts


The only fix I am aware of is to edit the library file input_adc.cpp, I simply commented out that line, and it now works excellent.
I posted more about this here: http://forum.pjrc.com/threads/26798-(Awesome)-Audio-Library-FFT-amp-analogReference
 
I had originally intended to include an adc1.analogReference() function, like the DAC object has. Somehow, this never happened. It'll come in some future version. Pull requests are welcome.... (hint, hint)

However, changing the reference to 3.3V will reduce the signal amplitude by 3. For hardware where the signal is already very low, you might be better off using the recommended circuit. Those 2 extra capacitors and 4 resistors will buy your 3X the signal gain.
 
ADC Mic circuit

Please excuse my limited experience with circuit schematics but I'm really confused on the adc1 input circuit schematic.

I built it and I got no audio input with a Electret microphone, I deconstructed it and made the most basic version I could find of an electret microphone circuit: http://www.edutek.ltd.uk/CBricks_Pages/Electret_Microphone.html

The one on the left.

It sounded like utter garbage but I could hear myself at least in the background.

Looking at the circuit I built it again. Same problem. Now I'm trying to piece apart the function of the circuit and am confused.

Why is the capacitor positive on the side HEADING to the analogue pin from the microphone. This is different then from the other circuit and makes me think the voltage is going INTO the audio input node. I was originally assuming the "audio input" node is a microphone or some other input. Is this circuit in reality an input circuit FROM a2 TO the "Audio Input" node?

Either way can you suggest a good simple circuit to produce what I'm attempting without getting the Adafruit breakout for example? I'm thinking there should be a relatively clean and simple way to do this.

Thank you
 
-Er Paul, he doesn't want to buy one! >_< but maybe he should if he is concerned about quality. I think he is using the wrong circuit, that circuit appears similar to this one, designed for audio output to headphones. He would want a circuit which passes a floating DC signal right?

Theman, I also heard terrible, popping audio when I used the circuit linked above, but it was a great tool for diagnosing crosstalk from high amperage LEDs. I found a tantalum capacitor worked better, but still cracking.
Try a search for: Electret mic circuit arduino input ? Or buy something engineered for quality audio?
 
-Er Paul, he doesn't want to buy one! >_< but maybe he should if he is concerned about quality. I think he is using the wrong circuit

lol ... i think your right. For some reason through going from wanting to make a circuit for recording with an electet microphone - to the audio design tool I selected adc1 -> queue and saw the circuit. Then somewhere along the way I made some assumption about that circuit that were way wrong.

Thanks for showing me I'm pointing in the wrong direction.

That being said, just so I'm clear, that circuit is to clean audio output from adc1?
 
Status
Not open for further replies.
Back
Top