• General
  • MEMS analog microphone extremely noisy on Bela mini

Hello,
I have a problem using this MEMS microphone on Bela mini: https://learn.sparkfun.com/tutorials/mems-microphone-hookup-guide?_gl=1*1s04isu*_ga*MTYzMzE3MjQ1Ni4xNzAyMzkwMTI3*_ga_T369JS7J9N*MTcwNDY2MzYzMS4zLjEuMTcwNDY2MzY1MC40MS4wLjA.&_ga=2.144550133.1520399485.1704657639-1633172456.1702390127

datasheet: https://www.cdiweb.com/datasheets/invensense/admp401.pdf

I connect it to Bela mini to the A0 input and i use the following code in supercollider:

s = Server.default;

s.options.numAnalogInChannels = 2; // can only be 2, 4 or 8
s.options.numAnalogOutChannels = 2;
s.options.numDigitalChannels = 0;
s.options.maxLogins = 4;  	   // set max number of clients
s.options.bindAddress = "0.0.0.0"; // allow anyone on the network connect to this server

s.options.blockSize = 16;
s.options.numInputBusChannels = 2;
s.options.numOutputBusChannels = 2;

// initialize scope
s.options.belaMaxScopeChannels = 8;

s.waitForBoot{
	"Server Booted".postln;

	(
	SynthDef(\analog_to_audio, {
		arg out=0;
		var soundin = AnalogIn.ar(1).range(-1,1) *0.5;
			//soundin = LeakDC.ar(soundin);
		Out.ar(0, soundin.dup * 0.5)

	}).send(s);
	);


	s.sync;
	Synth.new("analog_to_audio", target: s);
};

ServerQuit.add({ 0.exit }); // quit if the button is pressed

No matter what analog pin I use, no matter if i put 0.1 uF capacitor between power lines nor if i use multiple capacitors between analog out on the MEMS and bela mini analog in - I ALWAYS hear some sort of electrical noise, fairly high pitched, that variates slightly but remains pretty much constant. Is there anything I am doing wrong? soldering looks ok, i tried different analog pins on bela, different ground and 3.3V lines, but no luck. Any ideas on how to troubleshoot this? I've also tried 2 MEMS of this same model and the problem remains.. I really don't know what could be causing this. It is occurring either USB powered from a computer, or USB wall powered (with the code running on boot), or powered via LiPo battery.

Appreciate anyone who can shed a light on this!

Robin

    The analog inputs have a high sampling rate but are not able to provide high-quality audio input. I suggest you do the following:

    mic
    Vcc----3v3 Bela
            |
        4k7 R1
            |
    mic  1uF|
    AUD--C2-+-----+-------Bela analog in
            |     |
            |     |
        10k R2   C1 1uF
            |     |
    mic-----+-----+
    GND           | 
                 GND Bela

    Try this circuit (values are not critical) initially without C2 and without the microphone and try to listen to the output: this is the baseline noise you are going to get. Once you've come to terms with that, connect C2 and the microphone and evaluate whether the noise increases.

    robinm I connect it to Bela mini to the A0 input and i use the following code in supercollider:

    I don't really understand Supercollider, but I see no gain here, so you are probably not amplifying the noise in any way. In Pd I would do :

    [adc~ 3] <<< analog input
    |
    [*~ 2]
    |
    [-~ 1]
    | \
    [dac~ 1 2]
      5 days later

      hi Giulio sorry for the late reply. Just to make sure I understand, what you're suggesting is to first try this

      and listen to the analog input sent to the audio output to get the baseline noise;
      but then adding C2 and the MEMS, as in this

      giuliomoro

             3v3
              |
          4k7 R1
              |
      mic  1uF|
      AUD--C2-+-----+-------Bela analog in
              |     |
              |     |
          10k R2   C1 1uF
              |     |
      mic-----+--+--+
      GND        | 
                GND

      I'm not entirely sure I grasped it correctly how to provide 3v3 to the MEMS VCC input. could you show me the missing bit in this picture? I don't know whether 3v3 gets to the MEMS after R1, or after C2

        robinm Just to make sure I understand, what you're suggesting is to first try this

        Nope, the yellow wire from analog in should go to the other leg of the capacitor, i.e.: the mid-point of the two resistors. In your drawing that is just shorted to ground.

        robinm I don't know whether 3v3 gets to the MEMS after R1, or after C2

        This was not shown in my diagram, I took it for granted: 3v3 gets to the MEMS Vcc pin directly from 3v3 from Bela.
        Once you get the first circuit right, the second circuit adds C2 and three wires:
        MEMS VCC -> Bela 3v3
        MEMS GND -> Bela GND
        MEMS AUD -> C2 -> midpoint of R1 R2

        Please do not use a polarized electrolytic for C2, use a ceramic capacitor instead. If you don't have 1u ceramic, get a smaller value (hundreds of nF are good).

          giuliomoro Nope, the yellow wire from analog in should go to the other leg of the capacitor, i.e.: the mid-point of the two resistors. In your drawing that is just shorted to ground.

          riiiight so it should look something like this:

          and this

          is this correct? hope i didn't forget anything.

          (minor correction in the code - of course AnalogIn.ar(1) is actually AnalogIn.ar(0) when connected to A0)

          It looks OK to me, the only unknown is about the pinout of the microphone breakout, but you'll be able to read it on the PCB itself.

            ok so - i really couldn't hear anything from the first circuit (no baseline?), but the second circuit (the one including the MEMS) actually DOES work like a charm. The microphone itself is still crunchy as crazy, but the baseline noise has been practically completely removed this way. Since it seems too much like magic to believe it, can you explain me what's happening?

              robinm ok so - i really couldn't hear anything from the first circuit (no baseline?), but the second circuit (the one including the MEMS) actually DOES work like a charm

              That's a good first step.

              robinm The microphone itself is still crunchy as crazy, but the baseline noise has been practically completely removed this way.

              Is this the case both when powering from USB or from LiPo?

              To assess and address the distortion you are hearing, can you show the microphone signal on the Bela scope? In Pd you 'd do:

              [adc~ 3] << mic input: analog in 0
              |\\
              | | \
              | |   \
              | [dac~ 1 2] << output to headphones. Does it distort when powered via USB?
              |
              [dac~ 27] << send to scope

              Then view it at http://bela.local/scope . Show screenshots both with the microphone connected and without it (without C2).

              It is harder/impossible to use the Scope when powered via LiPo. If the issue only presents itself only with the LiPo, consider using a program that can record the analog input as a wav file to disk and send that wav file over. In Pd it would be:

              Set this program to run on boot, power via LiPo, let it run for ten seconds, then power it off gracefully, power via USB, open up the IDE, download the wav file and look at it / post it here.

              Since it seems too much like magic to believe it, can you explain me what's happening?

              I don't know exactly how you were wiring the microphone before. This circuit provides a bias of about 2V at the analog input which works as the central point, which is what the two resistors do. C1 removes some of the high frequency noise. When you add the microphone, C2 ensure the signal is AC-coupled and no DC-voltage at the output of the microphone affects the 2V bias. If the mic breakout already has an output capacitor, this could be removed. The AC-coupled signal from the microphone will be added to the 2V DC bias and so it will oscillate around the 2V offset, thus remaining within the 0V : 4.096V range of the ADC.
              Now, I just looked at the circuit for your MEMS breakout: https://cdn.sparkfun.com/assets/c/3/7/5/e/SparkFun_Analog_MEMS_Microphone_Breakout_ICS40180_Schematic.pdf . If this is accurate, then the output of the breakout should already be centered at around 1.65V and so the diagram I suggested shouldn't be needed, at least for basic operation (although it may improve the dynamic range when Bela is powered from USB). So if you have something that works with my circuit that didn't work before, it may be one of these options:

              • you wired the previous circuit wrong (although it should be straightforward)
              • you wired my circuit wrong, something is hitting the rail (GND or 5V) when no microphone is connected, thus saturating the ADC input (dead silence!) and causing the subsequent distortion when the microphone is indeed connected. Looking at the scope and/or recorded wav file may shine some light on this
              • something else that requires further investigation

                Note that when both LiPo and USB are connected, the board would normally run off the USB power rail. I think you may be able to toggle the USB power on and off (thus forcing it to run from the LiPo) by running these commands in the console at the bottom of the IDE.

                This disables USB power and enables the LiPo:

                i2cset -y -f 0 36 1 47

                this enables USB power and disables the LiPo

                i2cset -y -f 0 36 1 63

                I haven't tested this, but it seems likely to work. If you do have any noise that only shows up with the LiPo, try toggling with these two commands and see if you can reproduce the "LiPo-only" noise even with the USB plugged in. To confirm this does anything at all, measure the voltage at the "REF" pin off the analog input header: It should be 4.096V when powered from USB and something closer to 3.7V when powered from LiPo only.

                giuliomoro Is this the case both when powering from USB or from LiPo?

                this was powered via USB.

                The scope is a good idea but I'll have to get back to you with it later / tomorrow.
                For the rest, quickly

                giuliomoro I don't know exactly how you were wiring the microphone before.

                I wasn't, or better I was just wiring VCC to 3v3, GNG to GNG, AUD to A0 or other analog pin.

                giuliomoro and so the diagram I suggested shouldn't be needed

                .. which is what I thought. the integrated circuit seemed to include some of this already (in my superficial understanding of it) so we went ahead and plugged it that way. To be honest, amongst us three people that have tried this setup on different units I am the only one that is experiencing this kind of noise via USB and LiPo (although the latter wasn't tested with your circuit yet); the other two people have only had noise while using the Lipo. We're in the process to test these various scenarios but I'll get back to you when I have checked scopes and maybe recorded files of it.

                giuliomoro you wired the previous circuit wrong (although it should be straightforward)

                never say never ahahah. I'll double check, it's always very likely

                giuliomoro you wired my circuit wrong, something is hitting the rail (GND or 5V) when no microphone is connected, thus saturating the ADC input (dead silence!) and causing the subsequent distortion when the microphone is indeed connected

                I'm not sure I understand this..

                  robinm

                  giuliomoro you wired my circuit wrong, something is hitting the rail (GND or 5V) when no microphone is connected, thus saturating the ADC input (dead silence!) and causing the subsequent distortion when the microphone is indeed connected

                  I'm not sure I understand this..

                  If you wired my circuit wrong, it may give the illusion that there is no background noise because the input is saturated when there's no microphone connected and when it's saturated there is no noise because it's just a constant value, either 0 or 1. But when the microphone signal is added on top of that, the resulting sound would be very distorted. This is compatible with your observation of "really couldn't hear anything from the first circuit (no baseline?)" and "crunchy as crazy"

                    giuliomoro
                    I see, well that picture i made in fritzing displays the actual wiring i used, but if you have another reference for your circuit (if you think it would help to see more clearly the diagram) I'd be happy to troubleshoot this!

                    Better start from the scope and/or file recording explained here as a starting point to troubleshoot further.

                    ok, since i don't have my hands on a Bela mini right now, do you think it would be equivalent to test this on Bela for the time being?

                    Give it a try and see if you get the same results, if you do, it's worth doing.

                    ok well, seems same (audio) results on a Bela. I think I wired the circuit correctly (but.. see below). the distorsion i experience might just be the output of the mic? I see no squarewave in the bela scope. here with the MEMS plugged in through your circuit, connected USB to the computer, in a condition of quietness:

                    here singing a single tone almost straight into it:

                    channel 1 (0) is the input directly from AnalogIn(0) in supercollider, channel 2 (1) is the same input scaled (-1,1) and sent to the Bela audio output.

                    The circuit (this time on a breadboard for clarity) looks like this:

                    If i test it removing only C2 and the MEMS I get nothing in the Bela scope, but it looks an awful lot like the scenario that you were picturing

                    In this case the circuit looks like this:

                    All of this was tested via USB to a pc. Can you spot any weird stuff in the circuit that I should fix? Or do you have other ideas on what to troubleshoot? at this point I'm not sure if what I'm hearing is in fact unusual for this mic... Should I send audio samples here on the forum?

                      robinm ok well, seems same (audio) results on a Bela. I think I wired the circuit correctly (but.. see below). the distorsion i experience might just be the output of the mic? I see no squarewave in the bela scope. here with the MEMS plugged in through your circuit, connected USB to the computer, in a condition of quietness:

                      here singing a single tone almost straight into it:

                      channel 1 (0) is the input directly from AnalogIn(0) in supercollider, channel 2 (1) is the same input scaled (-1,1) and sent to the Bela audio output.

                      These look OK: no obvious clipping or distortion can be seen. Try applying a DC-removal filter to the signal before sending it out of the output (e.g.: a high-pass filter with cutoff at 10Hz or some other Supercollider magic), just to ensure there's no unexpected clipping happening there (unlikely). In Pd that would be :

                      [adc~ 3] << mic input: analog in 0
                      |\
                      |  \
                      |   [hip~ 10]
                      |    | \
                      |    |   \
                      |    [dac~ 1 2] << output to headphones. Does it distort when powered via USB?
                      |
                      [dac~ 27] << send to scope
                      10 days later

                      Unfortunately that doesn't seem to make a difference. In Supercollider I routed the analog-to-audio signal both through HPF.ar (a hi-pass filter) and LeakDC.ar (an alleged DC noise remover) but no change whatsoever. I have to specify that some of us are only having this problem when plugged to a LiPo (+ booster) but in my case the noise although bearable is omnipresent (and powering-agnostic..). I hope to post lucky updates, although for now we're just scratching our heads