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

Thread: Teensy 3.2 + Audio Board + MEMS Mic - Lots of noise but only when recording

Threaded View

  1. #1
    Junior Member
    Join Date
    Apr 2017

    Teensy 3.2 + Audio Board + MEMS Mic - Lots of noise but only when recording

    Hi all,

    I'm using a Teensy 3.2 with Teensy 3 Audio Shield coupled with a SparkFun ADMP401 breakout board MEMS microphone ( I don't require playback from the SD card on the Teensy, but I do desire to record data to the SD card for processing later on PC, as well as have the ability to listen to sounds being detected by the microphone (both when recording and not recording) via the on-board 3.5mm headphone jack.

    I've started at the Examples->Audio->Recorder sketch and adapted it to work as desired. It is functionally working as desired, whenever I plug headphones into the 3.5mm jack, it allows me to hear what the microphone is measuring (both when recording or not (idle mode)). Saving to the SD card is also working, and I can import the .RAW file into MATLAB for processing. The audio quality is FANTASTIC through the headphone output when in idle mode, i.e. when not storing data to the SD card. However, as soon as I begin recording, a large amount of 'noise' is induced into the microphone input signal that can be heard through the 3.5mm output, as well as seen in the data stored to the SD card. I use quotations for noise because it's as if I can here the electric signals from storing to the SD card. When the processor is storing the data to a buffer I head a constant buzz, then, periodically, I hear a higher freqeuncy buzz (of duration approx 0.5 sec) in which (I think) the processor is pushing data to the SD card. Stop recording to SD card and the noise stops completely.

    The noise I'm getting only when receiving is highly undesirable, and I can't seem to figure out where it's coming from to stop it. I will mention that powering the microphone via a separate power supply and ground seems to help the issue somewhat, but does not stop it completely. I've attached my code, as well as an image showing my setup-configuration as well as the data recorded to the SD card showing the noise explicitly, no other sounds were being recorded. Any ideas?

    HTML Code:
    // Record sound as raw data to a SD card, and play it back.
    // Requires the audio shield:
    // Three pushbuttons need to be connected:
    //   Record Button: pin 0 to GND
    //   Stop Button:   pin 1 to GND
    // This example code is in the public domain.
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // Define input & output
    AudioInputI2S            i2s2;           //xy=105,63
    AudioOutputI2S           i2s1;           //xy=470,120
    // Audio recording to SD card
    AudioAnalyzePeak         peak1;          //xy=278,108
    AudioRecordQueue         queue1;         //xy=281,63
    AudioConnection          patchCord1(i2s2, 0, queue1, 0);
    AudioConnection          patchCord2(i2s2, 0, peak1, 0);
    // 3.5mm headphone output (feed-through)
    AudioConnection          patchCord3(i2s2, 0, i2s1, 0);
    AudioConnection          patchCord4(i2s2, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=265,212
    // Bounce objects to easily and reliably read the buttons
    Bounce buttonRecord = Bounce(0, 4); // 8 = 8 ms debounce time
    Bounce buttonStop =   Bounce(1, 4);
    // Decide which input on the audio shield to be used
    //const int myInput = AUDIO_INPUT_LINEIN;
    const int myInput = AUDIO_INPUT_MIC;
    // Use these with the Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    // Remember which mode we're doing
    int mode = 0;  // 0=stopped, 1=recording
    // The file where data is recorded
    File frec;
    void setup() {
      // Configure the pushbutton pins - pull-up resistor configuration
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      // Audio connections require memory, and the record queue
      // uses this memory to buffer incoming audio.
      // Enable the audio shield, select input, and enable output
      // Microphone gain selection
      // Turn off ADC high pass filter to reduce noise level
      // Initialize the SD card
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
    void loop() {
      // First, read the buttons
      // Respond to button presses
      if (buttonRecord.fallingEdge()) {
        if (mode == 0) startRecording();
      if (buttonStop.fallingEdge()) {
        if (mode == 1) stopRecording();
      // If we're recording, carry on...
      if (mode == 1) {
      // Volume control via pot on audio board
      float vol = analogRead(15);
      vol = vol / 1024;
    void startRecording() {
      if (SD.exists("RECORD.RAW")) {
        // The SD library writes new data to the end of the
        // file, so to start a new recording, the old file
        // must be deleted before new data is written.
      frec ="RECORD.RAW", FILE_WRITE);
      if (frec) {
        mode = 1;
    void continueRecording() {
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        memcpy(buffer+256, queue1.readBuffer(), 256);
        // write all 512 bytes to the SD card
        elapsedMicros usec = 0;
        frec.write(buffer, 512);
        // Uncomment these lines to see how long SD writes
        // are taking.  A pair of audio blocks arrives every
        // 5802 microseconds, so hopefully most of the writes
        // take well under 5802 us.  Some will take more, as
        // the SD library also must write to the FAT tables
        // and the SD card controller manages media erase and
        // wear leveling.  The queue1 object can buffer
        // approximately 301700 us of audio, to allow time
        // for occasional high SD card latency, as long as
        // the average write time is under 5802 us.
        //Serial.print("SD write, us=");
    void stopRecording() {
      if (mode == 1) {
        while (queue1.available() > 0) {
          frec.write((byte*)queue1.readBuffer(), 256);
      mode = 0;

    Last edited by vq35dett01; 04-28-2017 at 04:55 PM.

Posting Permissions

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