Adafruit I2S MEMS Microphone Breakout Created by lady ada Last updated on 2018-09-12 03:55:53 AM UTC
Guide Contents Guide Contents Overview Assembly 2 3 6 Prepare the header strip: Add the breakout board: And Solder! 6 6 7 Pinouts Power Pins I2S Data Pins Arduino Wiring & Test Wiring I2S Library VU Meter Demo ArduinoSound Library Raspberry Pi Wiring & Test Wiring For Mono Mic Wiring For Stereo Mic Raspberry Pi i2s Configuration Kernel Compiling Prepare to Compile the i2s module Pi Zero Only 23 Auto-load the module on startup Test & Record! Test Playback 24 25 26 Adding Volume control Downloads File
Overview For many microcontrollers, adding audio input is easy with one of our analog microphone breakouts (http://adafru.it/1063). But as you get to bigger and better microcontrollers and microcomputers, you'll find that you don't always have an analog input, or maybe you want to avoid the noise that can seep in with an analog mic system. Once you get past 8-bit micros, you will often find an I2S peripheral, that can take digital audio data in! That's where this I2S Microphone Breakout comes in.
The microphone is a single mono element. You can select whether you want it to be on the Left or Right channel by connecting the Select pin to power or ground. If you have two microphones, you can set them up to be stereo by sharing the Clock, WS and Data lines but having one with Select to ground, and one with Select to high voltage. This I2S MEMS microphone is bottom ported, so make sure you have the hole in the bottom facing out towards the sounds you want to read. It's a 1.6-3.
© Adafruit Industries https://learn.adafruit.
Assembly Assembly is really easy, you can use straight or 'right-angle' style headers to attach to the PCB. We'll be using the plain straight headers included The board comes with all surface-mount components pre-soldered. The included header strip can be soldered on for convenient use on a breadboard or with 0.1" connectors. You can also skip this step and solder on wires. Prepare the header strip: Cut the strip to length if necessary.
And Solder! Be sure to solder all 5 pins for reliable electrical contact. (For tips on soldering, be sure to check out our Guide to Excellent Soldering (https://adafru.it/aTk)). © Adafruit Industries https://learn.adafruit.
You're done! Check your solder joints visually and continue onto the next steps © Adafruit Industries https://learn.adafruit.
Pinouts Unlike most of our breakouts, this sensor has the detection element on the bottom of the PCB, so we expect you to solder it 'upside down' with the sensor package on the bottom and the port on top! Power Pins 3V - this is the power in pin. Technically it can be powered from as low as 1.6V to 3.
Arduino Wiring & Test Remember, the I2S microphone requires an I2S peripheral and won't work with chips that don't support it in hardware! For this example we'll use a Feather M0, but you can also use an Arduino Zero. Wiring For Feather M0, Ardruino Zero and friends, use the following wiring: GND connected GND 3.3V connected 3.
You could try the InputPlotter demo but this code is higher resolution: © Adafruit Industries https://learn.adafruit.
/* 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.
Try blowing or whistling at the sensor to see response in real time VU Meter Demo Often times you don't want the actual audio data but the overall "sound pressure level". This example will take a bunch of samples, normalize the data to be around 0, then give you the maximum difference between the waveforms for a 'volume graph' /* This example reads audio data from an Invensense's ICS43432 I2S microphone breakout board, and prints out the samples to the Serial console.
by Sandeep Mistry */ #include 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.
Serial.println(maxsample - minsample); } Open up the serial plotter to see how making noises will create peaks! ArduinoSound Library For most uses, its better to have a higher-level library for managing sound. The ArduinoSound library works with I2S mics and can do filtering, amplitude detection, etc! Install it using the Arduino library manager Various examples come with the library, check them out in the File->Examples->ArduinoSound sub menu © Adafruit Industries https://learn.adafruit.
For example, amplitude Serial plotter will do basic amplitude plotting: You can also do FFT spectral diagramming using SpectrumSerialPlotter. We made a small change to the example so that all 128 bins are plotted: © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Raspberry Pi Wiring & Test You can add mono or stereo I2S microphones to your Raspberry Pi, too! This will work with Raspberry Pi B+, 2, 3, Zero and any other 2x20-connector-Pi This guide is largely based on this great git repo https://github.com/nejohnson2/rpi-i2s (https://adafru.it/vka) Wiring For Mono Mic Mic 3V - Pi 3.3v Mic Gnd - Pi Gnd Mic LRCL - Pi Gnd (this is used for channel selection. Connect to 3.
https://adafru.it/vkc https://adafru.it/vkc Raspberry Pi i2s Configuration Start by logging into your Raspberry Pi via a terminal, we recommend ssh so you can copy + paste the many commands. Turn on i2s support by editing /boot/config.txt with: sudo nano /boot/config.txt Uncomment #dtparam=i2s=on © Adafruit Industries https://learn.adafruit.
Next, we'll make sure sound support is enabled in the kernel with: sudo nano /etc/modules Add snd-bcm2835 on its own line, to the modules file as shown below Now reboot your pi with: © Adafruit Industries https://learn.adafruit.
sudo reboot Once rebooted, re-log in. Enter the following to confirm the modules are loaded lsmod | grep snd Kernel Compiling Ok now its time for the fun part! You'll manually compile in i2s support. Start by updating your Pi: sudo apt-get update sudo apt-get install rpi-update sudo rpi-update Then reboot! Install the compilation dependencies: sudo apt-get install git bc libncurses5-dev Download kernel source & compile: © Adafruit Industries https://learn.adafruit.
sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source sudo chmod +x /usr/bin/rpi-source /usr/bin/rpi-source -q --tag-update rpi-source --skip-gcc On a Pi 3 this will take many many minutes, so don't worry if its taking 15 minutes.
Download the module, written by Paul Creaser (https://adafru.it/vkd) git clone https://github.com/PaulCreaser/rpi-i2s-audio cd rpi-i2s-audio Pi Zero Only If you are using a Raspberry Pi Zero, edit my_loader.c with nano my_loader.c and change the two lines .platform = "3f203000.i2s", and .name = "3f203000.i2s", with .platform = "20203000.i2s", and .name = "20203000.i2s", © Adafruit Industries https://learn.adafruit.
If you aren't using a Pi Zero, continue on! Compile the module with make -C /lib/modules/$(uname -r )/build M=$(pwd) modules sudo insmod my_loader.ko Verify that the module was loaded: lsmod | grep my_loader dmesg | tail Note that on the Pi 2/3 you'll see asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 3F203000.i2s mapping ok on the last line and on Pi Zero you'll see asoc-simple-card asoc-simple-card.0: snd-soc-dummy-dai <-> 20203000.
sudo echo sudo sudo cp my_loader.ko /lib/modules/$(uname -r) 'my_loader' | sudo tee --append /etc/modules > /dev/null depmod -a modprobe my_loader And reboot! sudo reboot Test & Record! OK that was a lot of effort but now you are ready to rock! Use the following command to list the available input devices: arecord -l you should see a snd_rpi_simple_card You can record a wav file in mono with this command: arecord -D plughw:1 -c1 -r 48000 -f S32_LE -t wav -V mono -v file.
Test Playback If you have speakers hooked up to the Pi, you can play the file back directly on the device: aplay file.wav Or, you can copy it over to your computer for playback :), just insert your Pi's IP address below: scp pi@:/home/pi/file.wav ~/Desktop/file.wav Adding Volume control You can add volume control to your mine via alsamixer and alsa config. (Hat tip to RickTracer (https://adafru.it/doW)) Run sudo nano ~/.asoundrc and put the following in: © Adafruit Industries https://learn.
#This section makes a reference to your I2S hardware, adjust the card name # to what is shown in arecord -l after card x: before the name in [] #You may have to adjust channel count also but stick with default first pcm.dmic_hw { type hw card sndrpisimplecar channels 2 format S32_LE } #This is the software volume control, it links to the hardware above and after # saving the .
arecord -D dmic_sv -c2 -r 44100 -f S32_LE -t wav -V mono -v file.wav And cancel with ^C once it starts recording. Now you can run alsamixer - press F6 and select the I2S simple sound card It will complain there are no playback controls (because its for recording only). Press F5 to change the volume. Then you can record with the i2c mic device using arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v recording.wav © Adafruit Industries https://learn.adafruit.
and playback with aplay recording.wav © Adafruit Industries https://learn.adafruit.
Downloads Files EagleCAD PCB Files on GitHub (https://adafru.it/uyb) Fritzing object in the Adafruit Fritzing library (https://adafru.