I2 Safmic
I2 Safmic
Guide Contents 2
Overview 3
Assembly 6
Prepare the header strip: 6
Add the breakout board: 6
And Solder! 7
Pinouts 9
Power Pins 9
I2S Data Pins 9
Arduino Wiring & Test 10
Wiring 10
I2S Library 10
VU Meter Demo 13
ArduinoSound Library 15
Raspberry Pi Wiring & Test 18
Wiring For Mono Mic 18
Wiring For Stereo Mic 18
Raspberry Pi i2s Configuration 19
Kernel Compiling 21
Prepare to Compile the i2s module 22
Pi Zero Only 23
Auto-load the module on startup 24
Test & Record! 25
Test Playback 26
Adding Volume control 26
Downloads 30
Files 30
Schematic & Fab Print 30
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.
Instead of an analog output, there are three digital pins: Clock, Data and Word-Select. When connected to your
microcontroller/computer, the 'I2S Master' will drive the clock and word-select pins at a high frequency and read out
the data from the microphone. No analog conversion required!
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.3V device only, so not for use with 5V logic (its really unlikely you'd have a 5V-
logic device with I2S anyways). Many beginner microcontroller boards don't have I2S, so make sure its a supported
interface before you try to wire it up! This microphone is best used with Cortex M-series chips like the Arduino Zero,
Feather M0, or single-board computers like the Raspberry Pi.
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.
Make sure the side with the components is face down, as shown in the photos in this guide!
Power Pins
3V - this is the power in pin. Technically it can be powered from as low as 1.6V to 3.6V but you'll need to make
sure your logic level matches!
GND - power and data ground
Wiring
For Feather M0, Ardruino Zero and friends, use the following wiring:
https://adafru.it/uya
https://adafru.it/uya
I2S Library
Luckily, there's a nice little I2S library already written for Arduinos based on the SAMD processor. Make sure you have
the most recent Arduino IDE and SAMD core. Then select the board you're using (e.g. Adafruit Feather M0) and you'll
see the I2S library examples show up in the pulldown menu
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)
#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
}
void loop() {
// read a sample
int sample = I2S.read();
Upload to your Arduino Zero/Feather wired up as above, and open up the Serial Plotter
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. 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
* ICS43432:
* 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)
#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
}
#define SAMPLES 128 // make it a power of two for best DMA performance
void loop() {
// read a bunch of samples:
int samples[SAMPLES];
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!
Various examples come with the library, check them out in the File->Examples->ArduinoSound sub menu
You can also do FFT spectral diagramming using SpectrumSerialPlotter. We made a small change to the example so
that all 128 bins are plotted:
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)
https://adafru.it/vkb
https://adafru.it/vkb
Uncomment #dtparam=i2s=on
Add snd-bcm2835 on its own line, to the modules file as shown below
Kernel Compiling
Ok now its time for the fun part! You'll manually compile in i2s support.
Then reboot!
On a Pi 3 this will take many many minutes, so don't worry if its taking 15 minutes. On a Pi Zero it can take an hour or
longer!
This may already be done - mount: debugs is already mounted - in which case keep going
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",
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.i2s mapping ok
And reboot!
sudo reboot
arecord -l
Or, if you have two i2s mics installed, record in stereo with this command:
If all is working correctly, you should see the VU meter react at the bottom of the terminal window
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:
#This is the software volume control, it links to the hardware above and after
# saving the .asoundrc file you can type alsamixer, press F6 to select
# your I2S mic then F4 to set the recording volume and arrow up and down
# to adjust the volume
# After adjusting the volume - go for 50 percent at first, you can do
# something like
# arecord -D dmic_sv -c2 -r 48000 -f S32_LE -t wav -V mono -v myfile.wav
pcm.dmic_sv {
type softvol
slave.pcm dmic_hw
control {
name "Boost Capture Volume"
card sndrpisimplecar
}
min_dB -3.0
max_dB 30.0
}
Now before you can change the volume you need to use the device once (this is an alsa thing)
Run
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).
Then you can record with the i2c mic device using
aplay recording.wav