🛠 Acquitter un microphone PDM externe
Objectives
Acquire a PDM (Pulse Density Modulation) audio stream from an external MEMS microphone connected to the exposed pins of the Nicla Sense ME, then transfer the decoded samples to the serial port. The nRF52832 features a hardware PDM peripheral, which the mbed core exposes in principle via the PDM/arPDM library used on Arduino nRF boards. This tutorial also serves as a documentation warning: the official ABX00050 database does not reference any embedded microphone, unlike other boards in the family.
Hardware
- Arduino Nicla Sense ME board (ABX00050) and micro-USB cable
- PDM MEMS microphone (INMP441 type or equivalent with VDD, GND, CLK, DATA pins)
- > be validated before any permanent assembly.
- >
Complete Code
#include <PDM.h>
short buffer[256];
volatile size_t echantillonsLus = 0;
void onDonneesPDM {
int octets = PDM.available;
PDM.read(buffer, octets);
echantillonsLus = octets / 2;
}
void setup {
Serial.begin(115200);
while (!Serial);
PDM.onReceive(onDonneesPDM);
PDM.setGain(30);
if (!PDM.begin(1, 16000)) { // 1 canal, 16 kHz
Serial.println("Aucun micro PDM detecte");
while (1);
}
}
void loop {
if (echantillonsLus) {
for (size_t i = 0; i < echantillonsLus; i++) {
Serial.println(buffer[i]);
}
echantillonsLus = 0;
}
}
Expected Verification
If the PDM peripheral is available and the microphone is correctly wired, the serial console (115200 bauds) outputs 16-bit PCM samples; clapping produces visible peaks. Without a microphone, PDM.begin fails and an error message is displayed, which is already a useful verification of the setup.
Common Errors
- Confusing PDM and I²S: a PDM microphone does not output standard timestamped PCM; the CLK clock must remain continuous, otherwise zeros or white noise will result.
- Inappropriate microphone power supply: the board core operates at 1.8 V and external pins are level-shifted (VDDIO_EXT 1.8-3.3 V); check the compatibility of the CLK level of the chosen microphone.
- Swapping CLK and DATA: typical symptom, a constant zero signal or perfectly random noise.
- Forgetting that the stream is demanding for the CPU: at 16 kHz, sending samples one by one over serial cannot keep up; send in packets or reduce the display rate.
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_bhi260.inoArduinorotation_fusion.inoArduinopression_bmp390.inoArduinonose_electronique.inoArduinoboussole_bmm150.inoArduino