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?
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(); //
}
}
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:
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
}
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:
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: