Let me start by saying that what a wonderful community this is. I have been reading and getting help without asking any questions so far for months.
I am a DIY Enthusiast and a software developer, always had fascination for hardware and because of arduino and esp32 i've been looking into it lately.
I have the following setup at the moment.
1: ESP32-WROOM-32U
2: 5v SD Card Module
3: INMP441 Microphones
I am trying to build an automatic audio recorder which turns on upon hearing a certain volume. So far I am able to read and write streams to SD Card using SD.h and arduino audio tools library but the audio files only contain white noise.
I have tried doing it using ESP-IDF with i2s_read but failed. Moved to Arduino IDE which made my life much easier but still can't get it to work.
Here is my test code:
#include <AudioTools.h>
#include "SD.h"
#include "FS.h"
#include <SPI.h>
// Uncomment and set up if you want to use custom pins for the SPI communication
#define REASSIGN_PINS
int sck = 0;
int miso = 4;
int mosi = 15;
int cs = 18;
I2SStream i2sStream; // Access I2S as stream
File audioFile; // final output stream
WAVEncoder encoder;
EncodedAudioStream out_stream(&audioFile, &encoder); // encode as wav file
StreamCopy copier(out_stream, i2sStream); // copies sound into
void setup() {
// Set up Serial Monitor
Serial.begin(115200);
//AudioLogger::instance().begin(Serial, AudioLogger::Debug);
I2SConfig config = i2sStream.defaultConfig(RX_MODE);
config.i2s_format = I2S_STD_FORMAT;
config.sample_rate = 44100;
config.channels = 1;
config.bits_per_sample = 32;
config.is_master = true;
config.use_apll = false;
// i2s pins used on ESP32
config.pin_bck = 32;
config.pin_ws = 25;
config.pin_data_rx = 33; // input
// config.pin_data = 33; // output
i2sStream.begin(config);
out_stream.begin(config);
SPI.begin(sck, miso, mosi, cs);
if(!SD.begin(cs)){
ESP.restart();
}
int randNumber = random(30000);
String filename;
filename += "/";
filename += randNumber;
filename += ".wav";
if (!SD.exists(filename)) {
audioFile = SD.open(filename, FILE_WRITE);
} else {
ESP.restart();
}
}
void loop() {
copier.copy();
audioFile.flush(); // force write down of data
}
Currently only trying to sample data on left channel with 1 microphone. I have been stuck on this for weeks now, any directions would be helpful.
Another issue is that if i remove config.pin_data = 33; ESP starts crashing with Guru Meditation error