Input Serial Plotter

This example shows you how to read and visualize on the serial plotter I2S audio data coming from an I2S microphone.

Hardware Required

Circuit

To run this example you simply have to connect the board and the I2S microphone using the I2S bus as shown in the image. The image is for MKRZero; you find the proper pins for Zero and MKR1000 at the beginning of the sketch, in the comments.

I2SMIC

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Code


/*

 This example reads audio data from an Invensense's ICS43432 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 Zero, MKR family and Nano 33 IoT

 * ICS43432:

   * GND connected GND

   * 3.3V connected to 3.3V (Zero, Nano) or VCC (MKR)

   * WS connected to pin 0 (Zero) or 3 (MKR) or A2 (Nano)

   * CLK connected to pin 1 (Zero) or 2 (MKR) or A3 (Nano)

   * SD connected to pin 9 (Zero) or A6 (MKR) or 4 (Nano)

 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 8 kHz with 32-bits per sample

  if (!I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) {

    Serial.println("Failed to initialize I2S!");

    while (1); // do nothing

  }
}

void loop() {

  // read a sample

  int sample = I2S.read();

  if (sample) {

    // if it's non-zero print value to serial

    Serial.println(sample);

  }
}

See Also:

  • I2S library - Your reference for the I2S Library.

  • MKRZero - Product details for the MKRZero board.

  • SimpleTone - Generate a simple tone over I2S.

Last revision 2016/12/02 by AG