Analog MEMS Microphone Breakout - SPH8878LR5H-1 - How to Record Audio

Hello,

I am using ESP32 DevKit V1 and got the delivery of 2 new Analog MEMS Microphone Breakout - SPH8878LR5H-1 a couple of days back. I wanted to record the audio from it and send it to the UDP Server for later Listening to the Audio. All I am listening to is noise no audio.

Code:

#include <WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "WIFISSID";
const char* password = "WIFIPASSWORD";
const char* udpServerAddress = "LOCALSYSTEMIP"; // Change to your UDP server address
const int udpServerPort = 57399; // Change to your UDP server port
const int microphonePin = 34; // Analog pin connected to the microphone output
const int bufferSize = 1024; // Size of the buffer for audio samples
const float sampleRate = 8000.0f; // Sample rate of 8000 Hz

WiFiUDP udp;

void setup() {
  Serial.begin(115200);
  connectToWiFi();
  connectToUDP();
}

void loop() {
  int16_t sampleArr[bufferSize]; // Array to store audio samples
  record(sampleArr); // Record audio samples
  sendAudioData(sampleArr, sizeof(sampleArr)); // Send recorded audio data over UDP
}

void connectToWiFi() {
  Serial.println("Connecting to WiFi...");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void connectToUDP() {
  if (udp.begin(udpServerPort)) {
    Serial.println("UDP connection established on port " + String(udpServerPort));
  } else {
    Serial.println("Error establishing UDP connection");
  }
}

void record(int16_t* sampleArr) {
  for (int i = 0; i < bufferSize; i++) {
    // Record sound continuously
    float analogValue = analogRead(microphonePin); // Read analog value from the microphone
    // Apply low-pass filter to remove high-frequency noise
    analogValue = lowPassFilter(analogValue);
    // Scale the analog value to fit within the range of int16_t
    sampleArr[i] = static_cast<int16_t>((analogValue / 4095.0) * 32767); // Scale to fit within [-32768, 32767]
    delayMicroseconds(1000000 / sampleRate); // Calculate delay based on sample rate
  }
}

float lowPassFilter(float input) {
  static float filteredValue = 0.0f;
  const float alpha = 0.1f; // Adjust this value for the desired filter strength
  filteredValue = (alpha * input) + ((1.0f - alpha) * filteredValue);
  return filteredValue;
}

void sendAudioData(int16_t* data, size_t size) {
  udp.beginPacket(udpServerAddress, udpServerPort);
  udp.write((uint8_t*)data, size); // Send audio data as bytes
  udp.endPacket();
}

Please help me fix the issue.

For hardware:

Verify that all pins of the Analog MEMS Microphone Breakout are connected correctly to their corresponding pins on the audio shield PCB and vice versa. This can be done by checking each pin connection using a multimeter or oscilloscope.

Check if the microphone array is working independently by connecting it directly to an audio input port (such as a computer’s line-in jack) and verifying that sound is being recorded correctly.

Check if the audio shield is functioning properly without the microphone array connected. This can be done by recording sound using the built-in microphone on the audio shield and checking if it is working correctly.

Software:

Make sure the low pass filter is set a level that doesn’t filter your signal (adjust the alpha to change)

Sir, I am not using the hardware you mentioned above. In my post I mentioned that I am using ESP32 DevKit V1 board. The code is uploaded on the ESP32 DevKitV1 board and the PIN used is D34. Please suggest any Hardware or software changes accordingly.

Sir, I am not using the hardware you mentioned above.

I think @TS-Russell pasted a different audio breakout but the advice is the same: check your connections.

He goes on to correctly recommend testing the breakout independently of the processor. I look forward to seeing your results.

Sir, I currently don’t have access to an oscilloscope or multimeter. I’m wondering if there’s a tutorial available for using the breakout board with an ESP32 DevKit V1. Following such a guide would help me understand the setup better and potentially isolate any issues. If necessary, I’m prepared to order another batch of the breakout boards to conduct further testing. Your guidance on this matter would be greatly appreciated.

oops, corrected the part #

Here’s our guide https://learn.sparkfun.com/tutorials/an … okup-guide

TS-Russell:
oops, corrected the part #

Here’s our guide https://learn.sparkfun.com/tutorials/an … okup-guide

Thank you for the link. I have indeed reviewed the guide, but unfortunately, I couldn’t find any specific instructions or code examples for pairing this Breakout board with Arduino or ESP32 for audio recording.

Could you please provide additional guidance or point me to any resources that cover this aspect? I’m eager to proceed with my project and any assistance you can offer would be greatly appreciated.

Thank you for your help!

Might try this:

https://medium.com/codex/the-complete-g … 440ec2d1a2

YellowDog:
Might try this:

https://medium.com/codex/the-complete-g … 440ec2d1a2

This is a paid article. I do not have the access.

That article might answer your questions.

If you create an account they should give you access. Even if you have to pay $5.00, it might be worth it to get an answer.

Check if the microphone array is working independently by connecting it directly to an audio input port (such as a computer’s line-in jack) and verifying that sound is being recorded correctly.

Check if the audio shield is functioning properly without the microphone array connected. This can be done by recording sound using the built-in microphone on the audio shield and checking if it is working correctly.

He goes on to correctly recommend testing the breakout independently of the processor. I look forward to seeing your results.