Arduino IDE with PDM

siab14
Posts: 1
Joined: Thu Sep 28, 2023 10:46 am

Arduino IDE with PDM

Postby siab14 » Thu Sep 28, 2023 10:57 am

Code: Untitled.cpp Select all

I'm working on a program which is communicating via PDM with a microphone (IM72D128V01) from the ESP32-S3-WROOM-2 (Devkit-C).
I believe this is supported by the ESP32, although getting it to work via the Arduino IDE has proved difficult to me. I am getting some bits of information in the buffer every time I reset, but not a constant stream of data.

Any advice or working examples of similar would be much appreciated!

Code: Select all

#include <I2S.h>

const int buff_size = 128;
uint8_t buffer[buff_size];
const int sclkPin = 14;
const int wsPin = 3;
const int sdataPin = 16;
const int outSdPin = 9;
const int inSdPin = 10;
const int bufferSize = 128;
int readD;

//SCK (Serial Clock): is the clock signal also referred as BCLK (Bit Clock Line);
//FS (Frame Select): used to discriminate Right or Left Channel data also referred WS (Word Select);
//SD (Serial Data): the serial data to be transmitted;

//Frequency = SampleRate x BitsPerChannel x numberOfChannels
// begin(int mode, int sampleRate, int bitsPerSample)

void setup()
{
  Serial.begin(115200);
  
  I2S.setAllPins(sclkPin, wsPin, sdataPin, outSdPin, inSdPin);
  I2S.setBufferSize(bufferSize);
  I2S.setDuplex();
  
  I2S.begin(PDM_MONO_MODE, 4000, 16);
  I2S.read(); // Switch the driver in simplex mode to receive
  /* Modes:
    I2S_PHILIPS_MODE
    I2S_RIGHT_JUSTIFIED_MODE
    I2S_LEFT_JUSTIFIED_MODE
    PDM_MONO_MODE
  */
  
  I2S.setAllPins(sclkPin, wsPin, sdataPin, outSdPin, inSdPin);
  I2S.setBufferSize(bufferSize);
  I2S.setSimplex();
  I2S.read(); // Switch the driver in simplex mode to receive
}

void loop()
{
  I2S.read();
  Serial.println(I2S.available());
  if(I2S.available() < buff_size)
  {
    readD = I2S.read(buffer, I2S.available());
  }
  else
  {
    readD = I2S.read(buffer, buff_size);
  }
  Serial.println(readD);
  Serial.println("");
}

Shanjai_247
Posts: 2
Joined: Tue Apr 15, 2025 3:30 pm

Re: Arduino IDE with PDM

Postby Shanjai_247 » Tue Apr 15, 2025 3:35 pm

Hi, I'm also working on a similar project where I'm using the IM69D130 mic. Were you able to successfully read data from the PDM mic in the Arduino IDE? I need to read the PDM data and convert it to PCM for FFT.
Would be great help if you could share any information. Thanks!

Who is online

Users browsing this forum: Google [Bot], Qwantbot and 4 guests