🛠 Acquitter un microphone PDM externe

Arduino Nicla Sense ME · intermediaire · Schéma : IMG-nicla-sense-me-intermediaire-1-niclasense-micro-pdm.svg — Petit microphone MEMS au format boîtier avec deux fils horloge et données rejoignant les broches numériques du Nicla Sense ME, onde sonore stylisée au-dessus du micro

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials