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

Thread: AUDIO board internal Mic failure...?

  1. #1

    AUDIO board internal Mic failure...?

    Hi,

    Finally I got exactly the same type of microphone, which is shown on the pages of the Audio Shield at www.pjrc.com.

    I soldered the microphone onto the board and wanted to do a quick check, whether the microphone "is online" .

    For that, the "Recorder" example sketch was taken and freed from all unecessary stuff (since I have no reliable
    SDcard interaction still).
    I prints all bytes in the data buffer via the serial monitor.
    Or at least...it should...

    Unfortunately I can't find the bug...either the microphone is demaged (optical check of the soldering is ok) or...the sketch
    is buggy:

    Code:
    // Record sound as raw data to a SD card, and play it back.
    //
    // Requires the audio shield:
    //   http://www.pjrc.com/store/teensy3_audio.html
    //
    // Three pushbuttons need to be connected:
    //   Record Button: pin 0 to GND
    //   Stop Button:   pin 1 to GND
    //   Play Button:   pin 2 to GND
    //
    // This example code is in the public domain.
    
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s2;           //xy=105,63
    AudioAnalyzePeak         peak1;          //xy=278,108
    AudioRecordQueue         queue1;         //xy=281,63
    AudioPlaySdRaw           playRaw1;       //xy=302,157
    AudioOutputI2S           i2s1;           //xy=470,120
    AudioConnection          patchCord1(i2s2, 0, queue1, 0);
    AudioConnection          patchCord2(i2s2, 0, peak1, 0);
    AudioConnection          patchCord3(playRaw1, 0, i2s1, 0);
    AudioConnection          patchCord4(playRaw1, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=265,212
    // GUItool: end automatically generated code
    
    // For a stereo recording version, see this forum thread:
    // https://forum.pjrc.com/threads/46150?p=158388&viewfull=1#post158388
    
    // A much more advanced sound recording and data logging project:
    // https://github.com/WMXZ-EU/microSoundRecorder
    // https://github.com/WMXZ-EU/microSoundRecorder/wiki/Hardware-setup
    // https://forum.pjrc.com/threads/52175?p=185386&viewfull=1#post185386
    
    
    
    
    // which input on the audio shield will be used?
    //const int myInput = AUDIO_INPUT_LINEIN;
    const int myInput = AUDIO_INPUT_MIC;
    
    
    // Remember which mode we're doing
    int mode = 1;  // 0=stopped, 1=recording, 2=playing
    
    
    void setup() {
    
      // Audio connections require memory, and the record queue
      // uses this memory to buffer incoming audio.
      AudioMemory(60);
    
      // Enable the audio shield, select input, and enable output
      sgtl5000_1.enable();
      sgtl5000_1.inputSelect(myInput);
      sgtl5000_1.volume(0.5);
      startRecording();
    }
    
    
    void loop() {
    
      // If we're playing or recording, carry on...
      if (mode == 1) {
        continueRecording();
      }
    
      // when using a microphone, continuously adjust gain
      if (myInput == AUDIO_INPUT_MIC) adjustMicLevel();
    }
    
    
    void startRecording() {
      Serial.println("startRecording");
      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);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        int i;
        for( i=0 ; i< 512 ; i++ ) {
          Serial.print( buffer[i], HEX );
        }
       }
    }
    
    void stopRecording() {
      Serial.println("stopRecording");
       mode = 0;
    }
    
    
    void startPlaying() {
      Serial.println("startPlaying");
      mode = 2;
    }
    
    void continuePlaying() {
      if (!playRaw1.isPlaying()) {
        mode = 0;
      }
    }
    
    void stopPlaying() {
      Serial.println("stopPlaying");
      mode = 0;
    }
    
    void adjustMicLevel() {
      // TODO: read the peak1 object and adjust sgtl5000_1.micGain()
      // if anyone gets this working, please submit a github pull request :-)
    }
    Is there anything, which I should program differently so the microphone can be read?

    Thanks a lot for any help in advance!
    Cheers!
    Meino

  2. #2
    Hi,

    in the audio tutorial I found the "Mic Check" sketch, which works for me and proofs, that the mic is working!

    Cheers!
    Meino

Posting Permissions

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