AmplitudeSerialPlotter.ino 1.7 KB

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