After skimming through the SAMD21 datasheet I saw that the chip can support 1 I2S interface. My understanding is that the SERCOM are somewhat flexible. Can they be modified in code to get one I2S or is it completely disabled in this board?
The ATSAMD21G18 Support Inter-IC Sound (I2S) interface, from my search it also routed XIOA Board, I don’t about software support, but since XIAO have the debug port, we might can enable that.
I2S Pin list from the ATSAMD21G18 Datasheet
XIAO Schematic marked the I2S Pins.
Thank you for that information. I have been thinking about this and as you point out there is a debug port. So I wonder if the pin definitions are selected in the software kit from manufacturer and that is initialized in the bootloader. I know that if you use STM32 software to create firmware you can manipulate what interfaces to include in the design, for example do you want 2 SPI interfaces then you can deactivate other interfaces like lets say if the UART conflicts with a second SPI then you deactivate it. I have to admit I don’t have any particular need for a I2S on the XIAO but thank you again for looking into it, whoknows maybe I’ll have a real need for it later.
I would really like to use an I2S MEMS microphone with the XIAO, does anyone know if it’s possible? I don’t fully understand the posts above…
I know the chip is capable, and it looks like the I2S Pins highlighted in the XIAO schematic are connected to some GPIO, but I’m not sure if there is additional configuration needed. Any help or pointers appreciated, as there is not much information out there yet it seems.
Thank you @Baozhu. I will investigate that now to see if I can make use of some of those functions.
My aim is to monitor sound pressure levels and analyse pitch using FFT, rather than record audio. Size is very important, that’s why I am interested in using the XIAO over larger boards. I currently do this with an analog input, but would much rather switch to I2S.
As always, the best starting point is example sketches, but both the Seeeduino XIAO > I2S ones return this error
\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.7.9\libraries\I2S\src/I2S.h:111:2: error: #error “I2S is not supported on your board!”
The I2S.h library only seems to support arduino boards, so I don’t know if there’s another that does. I will do more investigating…
Thanks @Baozhu, for performance and functionality, you are absolutely correct! That looks brilliant, but unfortunately my project is miniature, so the XIAO is the board I will have to use. I already have it all up and running with analog audio, I would just rather switch to digital I2S, if possible.
I have done as much research as I can and I now have I2S enabled, pins allocated correctly and the example sketch in Arduino IDE running fine, but get nothing back from the mic. I have amended variant.h, tried changing SERCOM and the I2S library, but am way out of my depth now.
I think it probably needs someone cleverer than me to make a new I2S library that works with this board. Unless, of course, it is not possible with this hardware…
Any updates on this?
@JoDu I never did get it to work. I ended up making my own mini custom board based around the ESP-WROOM-32 module. That way I could make use of the ESP32 I2S library. It works well, but the XIAO would have been much cheaper and simpler!
Thanks for the reply - looks like I’m marching down a similar path that you were. I’ll check out that module. Take care!
Do you mind sharing your schematics and how you got it to work? I just started messing with Arduino and It would be nice to have something to reference.
@james_ma Sure. If you’ve just started messing with Arduino, then you’ll probably be better working with existing microphone breakouts, such as the SPH0645LM4H, along with a suitable Arduino or ESP-32 development board (I couldn’t get this to work with the XIAO). I made sure my code worked on those first. However, if you wanted to make your own custom board too, then these are the schematics for my current version.
For size reasons, I am currently using the smaller TTGO Micro32 module, but I would generally recommend the more commonly available ESP-WROOM-32 instead (same pins). There’s USB input for power and data, a USB serial to UART chip for programming, dual transistors for putting the ESP into flashing mode and the MEMS microphone module.
Thanks for the info. I like the size of the xiao but I don’t have the time to try to reprogram the boot loader … I might try the esp32. How do you think the tiny pico would work?
Yes, the ESP pico is just a smaller version with the same functionality as far as I can tell, so you should be fine.
I know this is an old thread now, but I did get I2S working on the Seeeduino XIAO. I manually edited the variant.h file for the hardware profile in Arduino and changed…
// I2S Interfaces
// --------------
#define I2S_INTERFACES_COUNT 0
to…
// I2S Interfaces
// --------------
#define I2S_INTERFACES_COUNT 1
#define I2S_DEVICE 0
#define I2S_CLOCK_GENERATOR 3
#define PIN_I2S_SD (PIN_A8)
#define PIN_I2S_SCK (2u)
#define PIN_I2S_FS (3u)
I used the schematics for the XIAO and the SAMD21 Datasheet to confirm the pins, but ultimately just copied this from the variant.h file in the Arduino MKR Zero profile which also uses the SAMD21. From there I quickly wired up a cheap little UDA1334A I2S DAC audio decoder board and programmed my XIAO with the Adafruit Zero I2S Library’s tone generator example and it happily started playing the sine. sawtooth, triangle, and square waves through my speakers.
I know it may be a little late for the original poster, but in case anyone else encounters this question, it is definitely doable!
are you using i2c pullup resisters?
how many ohms?
to what voltage 3v or 5v?
@DevonB Yes! That was it. Thank you! I had changed the interfaces count, but not added the extra lines.
I have moved on to a different ESP32-based setup now, but I just dug out the XIAO and tested my INMP441 mic on those pins with the InputSerialPlotter example and can confirm that it works!
The MEMS i2s mic pins are fixed and as follows:
SD / DOUT - 8
SCK / BCLK - 2
WS / LRCL - 3
LR / SEL - can either be LOW (ground) for Left or HIGH (3v3) for Right.
A heads-up for others: If you update your boards in the Arduino Boards Manager, that variant.h file can get reset to default and you’ll need to amend again. I feel like this should really be enabled by default.
I’m using I2S, not I2C. Everything is running at 3.3v, so no pull-up resistors are needed in my setup.
Editing the Variant.h file seems to be the simplest solution.
An alternative is to select a board with I2S activated by default. (and the same processor)
I got my XIAO running with I2S by selecting an Adafruit Itsybitsy M0 as board.
Advantage is you don’t need to worry about board updates that remove your modifications to Variants.h
Disadvantage is that it’s a small puzzle to find out on whitch XIAO pins the Itsybitsy pins are.
example program:
/*
This example generates a square wave based tone at a specified frequency
and sample rate. Then outputs the data using the I2S interface to a
MAX98357 I2S Amp Breakout board.
Circuit:
* Seeed studio XIAO
* MAX98357:
*
* GND connected GND
* VIN connected 5V
* LRC connected to pin D3
* BCLK connected to pin D2
* DIN connected to pin D8
created 17 November 2016
by Sandeep Mistry
Modified for Seeed studio XIAO
18 August 2022
by G.Wolters
*/
// intended for Seeed studio XIAO
// use Adafruit Itsybitsy M0 as Board setting to get I2S support
// ItsyBitsy M0 pin & functions Processor pin XIAO pin
// Dig/ Adc / special / int / touch / Sercom / Sercom alt / Timer / Timer alt
// 14 / A0 / Vout / 2 / Y0 / / / / PA02 D0
// 17 / A3 / Vrefb / 4 / Y2 / / / / PA04 D1
// 18 / A4 / / 5 / Y3 / / S0.1 / TCC0[1] / PA05 D9
// 8 / A10 / / 6 / Y4 / / S0.2 / TCC1[0] / PA06 D10
// 9 / A11 / I2S_SD0 / 7 / Y5 / / S0.3 / TCC1[1] / PA07 D8
// 4 / A8 / I2S_SD1 / NMI / / S0.0 / S2.0 / TCC0[0] / TCC1[2] PA08 D4
// 3 / A9 / I2S_MCK0 / 9 / / S0.1 / S2.0 / TCC0[1] / TCC1[3] PA09 D5
// 1 / A7 / I2S_SCK0 / 10 / / S0.2 / S2.2 / TCC1[0] / TCC0[2] PA10 D2
// 0 / A6 / I2S_FS0 / 11 / / S0.3 / S2.3 / TCC1[1] / TCC0[3] PA11 D3
// 15 / A1 / / 8 / Y14 / / S4.0 / TC4[0] / PB8 D6
// 16 / A2 / / 9 / Y15 / / S4.1 / TC4[1] / PB9 D7
// on-board leds, ON when output is LOW
// 13 PA17 yellow led
// 10 PA18 blue Rx led
// 12 PA19 blue Tx led
// Remark: PA06 is not used on the Itsybitsy, but is defined as 8 / A10
// Remark: Serial1 is using Sercom0 on PA10/PA11, these are available on the XIAO (D2/D3)
// Because PA10/PA11 are needed for I2s, this is not a usable configuration.
// Alternative is Sercom0 on PA4/PA5 Sercom0 on PA8/PA9 or Sercom4 on PB8/PB9
// Remark: I2C (wire) is using Sercom3 on PA22/PA23 which are not available on the XIAO
// If I2c is needed, Sercom4 on PB8/PB9 can be used
// Remark: SPI is using Sercom4 on PA12/PB10/PB11 which are not available on the XIAO
// If SPI is needed, Sercom0 on PA4/PA5/PA6 can be used.
#include <I2S.h>
const int frequency = 440; // frequency of square wave in Hz
const int amplitude = 500; // amplitude of square wave
const int sampleRate = 8000; // sample rate in Hz
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
short sample = amplitude; // current sample value
int count = 0;
void setup() {
Serial.begin(9600);
Serial.println("I2S simple tone");
// start I2S at the sample rate with 16-bits per sample
if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) {
Serial.println("Failed to initialize I2S!");
while (1); // do nothing
}
}
void loop() {
if (count % halfWavelength == 0) {
// invert the sample every half wavelength count multiple to generate square wave
sample = -1 * sample;
}
// write the same sample twice, once for left and once for the right channel
I2S.write(sample);
I2S.write(sample);
// increment the counter for the next sample
count++;
}