Amplitude Serial Plotter

Learn how to visualize amplitude using the Serial Plotter.

Introduction

This example reads audio data from an Invensense's ICS43432I2S microphone breakout board, and prints out the amplitude to the Serial console. The Serial Plotter built into the Arduino IDE can be used to plot the audio amplitude data.

Goals

  • How to use and read audio data.
  • How to use the Serial Plotter.

Hardware & Software Needed

Circuit

Amplitude serial plotter circuit.
Amplitude serial plotter circuit.

How to Use the Serial Plotter

The Arduino Serial Plotter is a tool available in the Arduino IDE that takes incoming serial data and can visualize the data in a plot in real-time.

Make sure that your Arduino is connected to your computer via USB, then open the serial plotter by navigating to Tools > Serial Plotter

Open the Serial Plotter.
Open the Serial Plotter.

Programming the Board

1. First, let's make sure we have correct the drivers installed. If we are using the Web Editor, we do not need to install anything. If we are using an offline editor, we need to install it manually. This can be done by navigating to Tools > Board > Board Manager.... Here we need to look for the Arduino SAMD boards (32-bits Arm® Cortex®-M0+) and install it.

2. Now, we need to install the libraries needed. Simply go to Tools > Manage libraries... and search for ArduinoSound and install it.

The sketch can be found in the snippet below. Upload the sketch to the board.

Code

1/*
2
3 This example reads audio data from an Invensense's ICS43432 I2S microphone
4
5 breakout board, and prints out the amplitude to the Serial console. The
6
7 Serial Plotter built into the Arduino IDE can be used to plot the audio
8
9 amplitude data (Tools -> Serial Plotter)
10
11 Circuit:
12
13 * Arduino Zero, MKRZero or MKR1000 board
14
15 * ICS43432:
16
17 * GND connected GND
18
19 * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKRZero)
20
21 * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKRZero)
22
23 * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKRZero)
24
25 * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKRZero)
26
27 created 23 November 2016
28
29 by Sandeep Mistry
30
31 */
32
33#include <ArduinoSound.h>
34
35// create an amplitude analyzer to be used with the I2S input
36
37AmplitudeAnalyzer amplitudeAnalyzer;
38
39void setup() {
40
41 // Open serial communications and wait for port to open:
42
43 // A baud rate of 115200 is used instead of 9600 for a faster data rate
44
45 // on non-native USB ports
46
47 Serial.begin(115200);
48
49 while (!Serial) {
50
51 ; // wait for serial port to connect. Needed for native USB port only
52
53 }
54
55 // setup the I2S audio input for 44.1 kHz with 32-bits per sample
56
57 if (!AudioInI2S.begin(44100, 32)) {
58
59 Serial.println("Failed to initialize I2S input!");
60
61 while (1); // do nothing
62
63 }
64
65 // configure the I2S input as the input for the amplitude analyzer
66
67 if (!amplitudeAnalyzer.input(AudioInI2S)) {
68
69 Serial.println("Failed to set amplitude analyzer input!");
70
71 while (1); // do nothing
72
73 }
74}
75
76void loop() {
77
78 // check if a new analysis is available
79
80 if (amplitudeAnalyzer.available()) {
81
82 // read the new amplitude
83
84 int amplitude = amplitudeAnalyzer.read();
85
86 // print out the amplititude to the serial monitor
87
88 Serial.println(amplitude);
89
90 }
91}

Testing It Out

After you have uploaded the code, start to make some noise! You should now be able to observe the amplitude of your input on the Serial Plotter.

Serial Plotter.
Serial Plotter.

Troubleshoot

If the code is not working, there are some common issues we can troubleshoot:

  • The microphone is not wired correctly.
  • You have not installed the correct drivers.
  • You have not installed the ArduinoSound Library.

Conclusion

In this example, we have learned how to use the Serial Plotter to visualize amplitude using the ArduinoSound Library and a microphone.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.