Arduino I2S library is no(t)w working on the Autonomo

I connected successfully the digital I2S microphone ICS43432 with the Adafruit Feather M0, Because this Feather version has a Cortex M0 I thought is should be no problem to run the Arduino I2S lib also on the Autonomo

The test sketch from https://www.arduino.cc/en/Tutorial/I2SInputSerialPlotter Does not compile an puts out various errors:

C:\Users\xx\AppData\Local\Temp\arduino_modified_sketch_92209\sketch_jul17c.ino: In function 'void setup()':
sketch_jul17c:32: error: 'I2S' was not declared in this scope

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

C:\Users\xx\AppData\Local\Temp\arduino_modified_sketch_92209\sketch_jul17c.ino: In function 'void loop()':
sketch_jul17c:40: error: 'I2S' was not declared in this scope
   int sample = I2S.read();
                ^

exit status 1
'I2S' was not declared in this scope

How can I make the Autonomo working with the I2S lib?

For the Feather I had to install additionally Arduino SAMD and Adafruit SAMD see
https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/using-with-arduino-ide is there similar code for the Autonomo or can I run the Autonomo with an other board definition - e.g. Feather M0 or Arduino Zero, MKRZero, MKR1000 where this modules are available?

I have tried to use “Arduino Zero” as board instead of “SODAQ Autonomo”

My hardware connection:

Arduino Zero or                    Arduino
MKR1000 / MRKZero                  ICS43432 
[board]                            [mic]

GND                            --  GND
3.3V (Zero) or VCC (MKRx)      --  3V3 
pin 0 (Zero) or pin 3 (MKRx)   --  WS 
pin 1 (Zero) or pin 2 (MKRx)   --  CLK 
pin 9 (Zero) or pin A6 (MKRx)  --  SD

In the sketch I changed Serial to SerialUSB. Is Serial USB pin 0 / 1? So it would lead to conflicts to the I2S mic on D0 and D1?

Output is not correct atm - I get allways 0 values so something must be still wrong.

/*
 This example reads audio data from an Invensense's ICS43432 I2S microphone
 breakout board, and prints out the spectrum to the Serial console. The
 Serial Plotter built into the Arduino IDE can be used to plot the audio
 amplitude 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)

 created 21 November 2016
 by Sandeep Mistry
 */

#include <ArduinoSound.h>

// sample rate for the input
const int sampleRate = 8000;

// size of the FFT to compute
const int fftSize = 128;

// size of the spectrum output, half of FFT size
const int spectrumSize = fftSize / 2;

// array to store spectrum output
int spectrum[spectrumSize];

// create an FFT analyzer to be used with the I2S input
FFTAnalyzer fftAnalyzer(fftSize);

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
  SerialUSB.begin(115200);
  while (!SerialUSB) {
    ; // wait for SerialUSB port to connect. Needed for native USB port only
  }

  // setup the I2S audio input for the sample rate with 32-bits per sample
  if (!AudioInI2S.begin(sampleRate, 32)) {
    SerialUSB.println("Failed to initialize I2S input!");
    while (1); // do nothing
  }

  // configure the I2S input as the input for the FFT analyzer
  if (!fftAnalyzer.input(AudioInI2S)) {
    SerialUSB.println("Failed to set FFT analyzer input!");
    while (1); // do nothing
  }
}

void loop() {
  // check if a new analysis is available
  if (fftAnalyzer.available()) {
    // read the new spectrum
    fftAnalyzer.read(spectrum, spectrumSize);

    // print out the spectrum
    for (int i = 0; i < spectrumSize; i++) {
      //SerialUSB.print((i * sampleRate) / fftSize); // the starting frequency
      SerialUSB.print(spectrum[i]); // the spectrum value
      SerialUSB.print("\t"); 
    }
    SerialUSB.println(); // 
  }
}

@Clemens

In windows you can navigate to the hidden folder:
%localappdata%
C:\Users\user\AppData\Local\Arduino15\packages\

You need to modificate the Autonomo board files, add the I2S pins.
I hope this helps you a bit to find the solution

Regards,
Jan

I could found some pin definitions in

C:\Users\xx\AppData\Local\Arduino15\packages\SODAQ\hardware\samd\1.6.14\variants\sodaq_autonomo
then variant.cpp and variant.h

The corresponding Feather M0 file seems to be
C:\Users\xx\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.0.15\variants\feather_m0_express

there is this I2S section in variant.h

/*
 * I2S Interfaces
 */
#define I2S_INTERFACES_COUNT 1

#define I2S_DEVICE          0
#define I2S_CLOCK_GENERATOR 3
#define PIN_I2S_SD          (9u)
#define PIN_I2S_SCK         (1u)
#define PIN_I2S_FS          (0u)

I copied this to the variant.h in the SODAQ folder, but now I get this compiling error:

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp: In member function 'int AudioInI2SClass::begin(long int, int)':

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp:36:8: error: 'I2S' was not declared in this scope
   if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, bitsPerSample)) {
        ^

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp:44:3: error: 'I2S' was not declared in this scope
   I2S.onReceive(AudioInI2SClass::onI2SReceive);
   ^

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp: In member function 'virtual void AudioInI2SClass::end()':

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp:58:3: error: 'I2S' was not declared in this scope
   I2S.end();
   ^

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp: In member function 'virtual int AudioInI2SClass::read(void*, size_t)':

C:\Users\xx\Documents\Arduino\libraries\ArduinoSound\src\AudioInI2S.cpp:85:14: error: 'I2S' was not declared in this scope
   int read = I2S.read(buffer, size);
              ^

exit status 1
Fehler beim Kompilieren fĂĽr das Board SODAQ Autonomo.

It is strange that you are still getting that compile error. Are you certain that you copied it to the correct variant.h file? I would expect it to compile as the definition of the global I2S is dependent on I2S_INTERFACES_COUNT being defined with a value of at least 1.

However, the pin mapping is different on the Autonomo compared to the other variants. Can you try using the code listed below. It needs to be copied to:

AppData/Local/Arduino15/packages/SODAQ/hardware/samd/1.6.14/variants/sodaq_autonomo/variant.h

/*
 * I2S Interfaces
 */
#define I2S_INTERFACES_COUNT 1

#define I2S_DEVICE          0
#define I2S_CLOCK_GENERATOR (0u)
#define PIN_I2S_SD          (14u) 
#define PIN_I2S_SCK         (1u)
#define PIN_I2S_FS          (2u)

For wiring, the numbers correspond to the equivalent digital pin number. i.e. MCK = D0, SD = D14, SCK = D1, & FS = D2

Did you manage to test the fix listed above?

My “old” fix did now “work” in direction compiling, don’t know what was wrong at my last trial. But is not working functionally.

With “my” fix I can compile the sketch, but I get only “0” in all FTT bins. After that I changed to your pin definitions and could not manage to open the Serial Monitor after uploading the sketch. Could you doublecheck the pins in your code.

Why is the I2S_CLOCK definition at the Feather code with the number “3” only
#define I2S_CLOCK_GENERATOR 3

and in your code with brackets “()”? Is this equivalent?
#define I2S_CLOCK_GENERATOR (0u)

This is the error message after uploading the sketch:

I tried also to remove waiting for serial and deleted

  while (!SerialUSB) {
    ; // wait for SerialUSB port to connect. Needed for native USB port only
  }

but it makes no difference.

I believe I made a mistake. I thought the I2S_CLOCK_GENERATOR was the I2S_MCK pin (which appears to be unused). That definition actually specifies the correct GCLK to use. The correct mapping should be:

/*
 * I2S Interfaces
 */
#define I2S_INTERFACES_COUNT 1

#define I2S_DEVICE          0
#define I2S_CLOCK_GENERATOR 3
#define PIN_I2S_SD          (14u) 
#define PIN_I2S_SCK         (1u)
#define PIN_I2S_FS          (2u)

The external pins for wiring to are:

MCK: D0 (unused)
SCK: D1
FS:  D2
SD:  D14
1 Like

Thanks Gabriel for the quick response, now it seems to work basically. I get some output on the serial monitor but it looks like the output has some dropouts:

0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	46340	0	113511	0	417068	705844	481589	0	179477	0	122606	0	92681	0	80264	0	92681	0	92681	0	92681	0	113511	0	131071	0	173391	0	245213	0	409272	0	1247768	1973166	1268252	0	432239	0	266208	0	196607	0	160529	0	139022	0	122606	0	122606	0	113511	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	65535	46340	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	46340	80264	46340	0	
65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	0	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	65535	46340	46340	46340	46340	46340	46340	46340	65535	46340	46340	46340	46340	46340	46340	46340	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	92681	0	92681	0	92681	0	92681	0	92681	0	92681	0	92681	0	103621	0	122606	0	139022	0	173391	0	355951	403991	167084	0	80264	0	103621	0	139022	0	191068	0	274156	0	449292	0	1327002	2056306	1288411	0	411887	0	236293	0	160529	0	113511	0	80264	0	65535	0	46340	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	65535	0	236293	395937	266208	0	80264	0	46340	0	46340	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	46340	0	80264	0	113511	0	196607	0	609520	967627	621729	0	212360	0	122606	0	92681	0	80264	0	65535	0	65535	0	65535	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0

Could it be a performance problem? When I reduce sample rate and FFT size to

// sample rate for the input
const int sampleRate = 4000;

// size of the FFT to compute
const int fftSize = 64;

I get less dropouts (see below) but not no dropouts like on the Adafruit Feather M0

0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
131071	122606	122606	122606	122606	122606	122606	122606	131071	122606	122606	122606	122606	122606	122606	122606	131071	122606	122606	122606	122606	122606	122606	122606	131071	122606	122606	122606	122606	122606	122606	122606	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
786431	1173259	1246907	811959	1079853	1294232	881696	977563	1309080	977563	881696	1294232	1079853	811959	1246907	1173259	786431	1173259	1246907	811959	1079853	1294232	881696	977563	1309080	977563	881696	1294232	1079853	811959	1246907	1173259	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
8388607	8388479	8388479	8388479	8388479	8388479	8388479	8388479	8388607	8388479	8388479	8388479	8388479	8388479	8388479	8388479	8388607	8388479	8388479	8388479	8388479	8388479	8388479	8388479	8388607	8388479	8388479	8388479	8388479	8388479	8388479	8388479	
46340	46340	65535	0	65535	65535	46340	46340	80264	46340	46340	65535	65535	0	65535	46340	46340	46340	65535	0	65535	65535	46340	46340	80264	46340	46340	65535	65535	0	65535	46340	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
258015	258015	258015	258015	258015	258015	258015	258015	262143	258015	258015	258015	258015	258015	258015	258015	258015	258015	258015	258015	258015	258015	258015	258015	262143	258015	258015	258015	258015	258015	258015	258015	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
262143	262143	258015	258015	262143	262143	258015	262143	262143	262143	258015	258015	262143	262143	258015	262143	262143	262143	258015	258015	262143	262143	258015	262143	262143	262143	258015	258015	262143	258015	258015	262143	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	
0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0

You could try changing:

#define PIN_I2S_SD          (14u) 

to:

#define PIN_I2S_SD          A10

This would put it on the same package pin (PA07) as used by the M0 feather. D14 is on PA19 which should also work as I2S[0] SD.

I had a wrong wiring yesterday, it’s working with

#define I2S_DEVICE          0
#define I2S_CLOCK_GENERATOR 3
#define PIN_I2S_SD          (14u)
#define PIN_I2S_SCK         (1u)
#define PIN_I2S_FS          (2u)

Thanks Gabriel for your help, I think we have it working on the Autonomo!

Some sinus tones:

… and Bach’s Toccata und Fuge d-moll

1 Like