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…
@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!
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?
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…
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!
@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.
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++;
}
Don’t know where you found the URL; I must be blind. Thank you. I decided to take another look and I may have had the pinout mirror; yellow wire to bottom and other 2 up top. Going to test in a few minutes and see.
This fully-featured UDA1334A I2S Stereo DAC breakout is a perfect match for any I2S-output audio interface. It’s affordable but sounds great! The NXP UDA1334A is a jack-of-all-I2S-trades: you can use 3.3V - 5V logic levels (a rarity) and can process multiple different formats by setting two pins to high or low. The DAC will process data immediately and give you a clear, analog, stereo line-level output. It’s even cool with MCLK-less I2S interfaces such as the Raspberry Pi (which it’s ideal for) - a built-in PLL will generate the proper clock from the bitclock signal.
For inputs, you can use classic I2S (the default) or 16-bit, 20-bit, or 24-bit left justified data. You can set it up to take an input system/controller clock but we default-set it to just generate it for you, so you only need to connect Data In, Word Select (Left/Right Clock), and Bit Clock lines. If you want, there’s a mute pin and a de-emphasis filter you can turn on.
Guess I just didn’t do it right the first time (DAC from cable box a while back). Whether I wired it wrong, or just using crystal for DAC’s master clock that Xiao doesn’t reference in anyway, or … whatever.
Been sitting here for like 30 minutes listening to some borderline annoying 8 bit sounding loops because I’m just happy to hear it working.
PCM5102A DAC, $7.
1 pic per post limit… sick.