I have an Arduino Nano ESP32 with Arduino IDE 2.3.8 on a Linux machine. Whenever I try to upload this sketch:
#include <driver/i2s.h>
#define I2S_WS 7
#define I2S_SCK 8
#define I2S_SD 6
#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 = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};
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 I wrote following this tutorial), the upload fails and the Arduino enters a bootloop state (connecting and disconnecting from the computer each time flashing the rainbow LED). In order to exit this stuck state I have to enter Download mode (purple LED) and re-flash the bootloader with the command
esptool.py --chip esp32s3 --port "/dev/ttyACM0" --before no_reset --baud 115200 write_flash --flash_mode dio --flash_freq 80m --flash_size 16MB 0x0 /tmp/nano32blink16mb.bin
After the command, the Arduino is back to working correctly and I am able to upload other sketches (e.g. the classic LED blink test). If I try to upload the indicted one, however, the bootloop state starts again.
How can I solve this problem? Is there a problem with the sketch?
Thank anybody!!


