sfera-labs / arduino-pico-i2s-audio

I2S digital audio input Arduino library for the Raspberry Pi Pico RP2040
8 stars 2 forks source link

Documentation, example(s), maybe a Discussion tab? #1

Open Andy2No opened 2 years ago

Andy2No commented 2 years ago

Will you be adding a readme to the code page, and ideally an example or two, as with other Arduino libraries? I'm not entirely clear how to try this out, without them.

This probably should have been on a Discussion thread, rather than in an issue, but there currently isn't a Discussion page. Maybe worth adding one?

I'm intrigued to see that you can set the three I2S pins separately, as opposed to the standard arduino-pico I2S (16 bit out only), where two of them have to be adjacent, so you only get to set two. Can all three be on any GPIO pin, in this version? Does that place any limitations on the use of PIO functions on other pins, e.g. adjacent ones?

giampiero7 commented 2 years ago

Hi Andy, This repo is, hopefully, only a temporary solution for a more integrated one. I'm discussing about it here: https://github.com/earlephilhower/arduino-pico/issues/99

Actually this version too needs WS and SCK to be subsequent, it is enforced here: https://github.com/sfera-labs/arduino-pico-i2s-audio/blob/master/src/machine_i2s.c#L678

Anyway, if you want to try it, here is some hints:

#include <I2S.h>

#define APP_BUFFER_SIZE 10000

I2SClass I2S;
uint8_t buff[APP_BUFFER_SIZE];

void setup() {
    I2S.setSCK(PIN_I2S_SCK);
    I2S.setWS(PIN_I2S_WS);
    I2S.setSD(PIN_I2S_SD);
    I2S.setBufferSize(40000);
    I2S.begin(I2S_MODE_MONO, 44100, 32);
}

void loop() {
    int ret = I2S.read(buff, APP_BUFFER_SIZE);
    if (ret < 0) {
      Serial.print("Microphone read error: ");
      Serial.println(ret);
      delay(1000);
      return;
    }
    Serial.print("Read ");
    Serial.print(ret);
    Serial.println(" bytes");
}
Andy2No commented 2 years ago

Thanks. I'll have a go at that soon.