Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Please add PDM example - proposal here #2075

Tuet started this conversation in Ideas
Discussion options

Problem Description

Hi, very nice library, but I took me ages to get PDM on ESP32-S3 to output something usable. Culprit was that .pin_bck MUST be set, otherwise no audio. I got it working now, please add the following example that is derived from examples/examples-stream/streams-generator-i2s/streams-generator-i2s.ino

/streams-generator-i2s-pdm.ino

Device Description

Use a ESP32-S3, select any Pin for PDM where your Amp/Speaker is connected. You MUST choose another pin for clock output even if you not use it - otherwise NO audio output.

Sketch

/**
 * @file streams-generator-i2s-pdm.ino
 * @author Phil Schatzmann
 * @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-stream/streams-generator-i2s-pdm/README.md 
 * @copyright GPLv3
 */
 
#include "AudioTools.h"
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
I2SStream out; 
StreamCopy copier(out, sound); // copies sound into i2s
// Arduino Setup
void setup(void) { 
 // Open Serial 
 Serial.begin(115200);
 while(!Serial);
 AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
 // start I2S
 Serial.println("starting I2S...");
 auto config = out.defaultConfig(TX_MODE);
 // special PDM config starts here...
 config.signal_type = PDM; // Use PDM
 config.pin_data = 6; // Pin on that audio comes out (but Left+Right is merged together!)
 config.pin_bck = 17; // Pin where clock comes out (you MUST select a pin even if nothing is connected to it, otherwise no audio output even from .pin_data!)
 // ...end of PDM config. Rest is standard config.
 
 config.copyFrom(info); 
 out.begin(config);
 // Setup sine wave
 sineWave.begin(info, N_B4);
 Serial.println("started...");
}
// Arduino loop - copy sound to out 
void loop() {
 copier.copy();
}

Other Steps to Reproduce

No response

What is your development environment (incl. core version info)

No response

I have checked existing issues, discussions and online documentation

  • I confirm I have checked existing issues, discussions and online documentation
You must be logged in to vote

Replies: 1 comment

Comment options

Please submit a pull request

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2030 on June 15, 2025 19:11.

AltStyle によって変換されたページ (->オリジナル) /