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

Thread: reading raw data from the microphone

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    3

    reading raw data from the microphone

    [QUOTE=PaulStoffregen;238070]
    Hi,

    Is there a way to print out the raw digital audio data from the SPH0645 microphone onto the serial console ?; like the data samples in its binary format. I found the code to do this in the Adafruit webpage documenting the microphone. But, its using an I2S library, that will work only with boards with SAMD cores. The code that I found is listed below :



    /*
    This example reads audio data from an I2S microphone
    breakout board, and prints out the samples to the Serial console. The
    Serial Plotter built into the Arduino IDE can be used to plot the audio
    data (Tools -> Serial Plotter)

    Circuit:
    * Arduino/Genuino Zero, MKRZero or MKR1000 board
    * GND connected GND
    * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKRZero)
    * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKRZero)
    * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKRZero)
    * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKRZero)

    created 17 November 2016
    by Sandeep Mistry
    */

    #include <I2S.h>

    void setup() {
    // Open serial communications and wait for port to open:
    // A baud rate of 115200 is used instead of 9600 for a faster data rate
    // on non-native USB ports
    Serial.begin(115200);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
    }

    // start I2S at 16 kHz with 32-bits per sample
    if (!I2S.begin(I2S_PHILIPS_MODE, 16000, 32)) {
    Serial.println("Failed to initialize I2S!");
    while (1); // do nothing
    }
    }

    void loop() {
    // read a sample
    int sample = I2S.read();

    if ((sample == 0) || (sample == -1) ) {
    return;
    }
    // convert to 18 bit signed
    sample >>= 14;

    // if it's non-zero print value to serial
    Serial.println(sample);
    }





    I am wondering whether there is an equivalent library that will work with teensy, to do the same. I have a teensy 4.0.
    Thanks in advance!!

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,272
    Don't know why you posted this in Announcements - I moved this thread to "Audio".

  3. #3
    Junior Member
    Join Date
    Apr 2021
    Posts
    3
    Quote Originally Posted by Frank B View Post
    Don't know why you posted this in Announcements - I moved this thread to "Audio".
    Sorry, I am new to this. I posted that as a reply actually.

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,272
    The Audio library provides raw data. Just use the AudioRecordQueue: https://www.pjrc.com/teensy/gui/?info=AudioRecordQueue to read the data - and then print it.
    What is printing useful for?

  5. #5
    Junior Member
    Join Date
    Apr 2021
    Posts
    3
    Thank you so much. We are required to read the raw data and store them as files in the cloud, for now; so that they can later be used for analysis.

Posting Permissions

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