Hi!
I have a mini project where i am using using nano esp32 with inmp441 microphone. Below you can see the prototype.
The code is as follows:
#include <driver/i2s.h>
#define I2S_WS D7
#define I2S_SCK D8
#define I2S_SD D6
#define I2S_PORT I2S_NUM_0
#define bufferLen 64
int16_t buff [bufferLen]; //immagazziniamo 16 campioni da 16 bit
//creare struttura tipo i2s config (i2s_config_t offerta dalla libreria )
const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX), //il dispositivo si comporta da MASTER e RICEVE i dati (dal mic)
.sample_rate = 44100, // frequenza di campionamento
.bits_per_sample = i2s_bits_per_sample_t(16), // quanti bit per campione (16)
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // solo canale sinistro
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = bufferLen, // lunghezzza del buffer
.use_apll = false
};
// config per impostare i pin (const i2s_pin_config_t offerta dalla libreria)
const i2s_pin_config_t pin_config = {
.bck_io_num = D7,
.ws_io_num = D8,
.data_out_num = -1,
.data_in_num = D10
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(2000);
Serial.println("I2s MIC");
//installiamo configurazioni
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL); //0 e null se non vogliamo una coda di eventi
i2s_set_pin(I2S_PORT, &pin_config);
i2s_start(I2S_PORT); //avviamo processore
delay(1000); //piccolo delay per permettere a tutto di partire
}
void loop() {
// qui riceviamo i dati
// size_t bytesRicevuti = 0; // quanti bit ricevuti
// esp_err_t res = i2s_read(I2S_PORT, &buff, bufferLen, &bytesRicevuti, portMAX_DELAY); //funzione di ricezione: prende processore, campioni ricevuti, lunghezza del buffer, quanti bit ricevuti, attendi se non ci sono campioni. risultato della lettura è oggetto esp_err_t
// if (res == ESP_OK) { //se res è uguale a esp ok↓
// int n = bytesRicevuti / 16; //andiamo a leggere i campioni. quanti ne abbiamo ricevuti ce lo dice bytesRicevuti diviso per 16
// if (n > 0) { // se il numero è > 0 vuol dire che abbiamo ricevuto qualcosa e possiamo leggerlo quindi processarlo
// for (int i = 0; i < n, i++;) {
// Serial.println(buff[i]); //li andiamo a stampare (i valori)
// }
}
Which should display some audio signal in the serial plotter. However, when I open the serial plotter nothing shows.
I have tried running this test code which should basically do the same thing (changing the pins accordingly), but even with this script the serial plotter stays flat, though in this case with x-values increasing (which doesn't happen in my code).
How can I manage it to work? I doubt it to be a hardware problem as both the mic and the Arduino are quite brand-new.
any help appreciated!!
