Arduino TKJHAT
Arduino library for Pico HAT extension board
Loading...
Searching...
No Matches
Microphone Class Reference

A class to control MEMS microphone. More...

#include <Microphone.h>

Public Member Functions

int begin ()
 Initialize the PDM MEMS microphone.
int getSamples (int16_t *buffer, size_t samples)
 Read PCM samples from the microphone buffer.
 Microphone (uint8_t dataPin, uint8_t clkPin)
 Construct a new Microphone object.
void setCallback (pdm_samples_ready_handler_t handler)
 Set a callback function to be called when new samples are ready.
int start ()
 Start capturing audio samples.
void stop ()
 Stop capturing audio samples.

Detailed Description

A class to control MEMS microphone.

This class provides control for the PDM MEMS microphone connected via PIO.

**Microphone (PDM_CLK — GPIO 15, PDM_DATA — GPIO 16)**

Default microphone parameters:

Setting Value
Data pin PDM_DATA (GPIO 16)
Clock pin PDM_CLK (GPIO 15)
Sample rate 16 kHz
Buffer size 256 samples

Constructor & Destructor Documentation

◆ Microphone()

Microphone::Microphone ( uint8_t dataPin,
uint8_t clkPin )

Construct a new Microphone object.

Parameters
dataPinGPIO pin connected to the PDM data signal (default: GPIO 16)
clkPinGPIO pin connected to the PDM clock signal (default: GPIO 15)

Member Function Documentation

◆ begin()

int Microphone::begin ( )

Initialize the PDM MEMS microphone.

Configures the microphone using PIO to capture PDM data and the OpenPDM2PCM library to transform it into PCM samples.

Implementation is based on the official [Arm Developer Ecosystem microphone library for Pico] (https://github.com/ArmDeveloperEcosystem/microphone-library-for-pico/tree/main).

Default parameters:

  • Data pin: GPIO 16
  • Clock pin: GPIO 15
  • Sample rate: 16 kHz
  • Buffer size: 256 samples
Returns
0 on success, negative value on error.

◆ getSamples()

int Microphone::getSamples ( int16_t * buffer,
size_t samples )

Read PCM samples from the microphone buffer.

Parameters
bufferPointer to an array where the samples will be stored.
samplesNumber of samples to read.
Returns
The number of samples actually read, or negative on error.

◆ setCallback()

void Microphone::setCallback ( pdm_samples_ready_handler_t handler)

Set a callback function to be called when new samples are ready.

Parameters
handlerCallback function of type ::pdm_samples_ready_handler_t.

◆ start()

int Microphone::start ( )

Start capturing audio samples.

Returns
0 on success, negative value on error.

◆ stop()

void Microphone::stop ( )

Stop capturing audio samples.

Returns
0 on success, negative value on error.

The documentation for this class was generated from the following file: