Skip to content

External DAC

Phil Schatzmann edited this page Sep 7, 2021 · 39 revisions

The best sound quality can be achieved with an external DAC. Here is a quick overview of the most popular breakout boards that can be found. The framework uses the following default pins:

  • bck_io_num = 26
  • ws_io_num = 25
  • data_out_num = 22

Pcm5102-Dac-Decoder

This DAC is very easy to use: Just connect the 3 I2S pins and the power and everything works as expected, w/o changing the configuration!

DAC ESP32
BCK BCK (GPIO26)
DATA OUT (GPIO22)
WS WS (GPIO25)
GND GND
GND GND
VDD 5V

Adafuit / UDA1334A Breakout Board

It seems that most DACs from Adafruit have a different byte order then what the ESP32 expects and therefore you need to indicate the communication format as I2S_COMM_FORMAT_I2S_LSB:

    static const i2s_config_t i2s_config = {
         .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX),
         .sample_rate = 41000,
         .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
         .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
         .communication_format = (i2s_comm_format_t) (I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_LSB),
         .intr_alloc_flags = 0, // default interrupt priority
         .dma_buf_count = 8,
         .dma_buf_len = 64,
         .use_apll = false
    };
    a2dp_sink.set_i2s_config(i2s_config);
DAC ESP32
VIN 5V
GND GND
WSEL WS (GPIO25)
DIN OUT (GPIO22)
BCLK BCK (GPIO26)

24-bit PCM5102 PCM5102A Stereo DAC Digital-to-analog Converter PLL Voice Module pHAT

I was struggling quite a big to have this one working, because it needs some additional connections:

DAC ESP32
VCC 5V
GND GND
DIN OUT (GPIO22)
FMT GND
LCK WS (GPIO25)
BCK BCK (GPIO26)
FMT GND
XST 3V (or another GPIO PIN which is set to high)
  • DEP - De-emphasis control for 44.1kHz sampling rate(1): Off (Low) / On (High)
  • FLT - Filter select : Normal latency (Low) / Low latency (High)
  • SCK - System clock input (probably SCL on your board).
  • FMT - Audio format selection : I2S (Low) / Left justified (High)
  • XMT - Soft mute control(1): Soft mute (Low) / soft un-mute (High)

PCM5102 DAC

This is an often seen module on Amazon, Bangood ... that is quite easy to use.

DAC ESP32
SCK GND
BCK 26
DIN 22
LCK 25
GND GND
VIN 3.3

Any 32 bit DAC

There are some rare high end DACs which only support 32 bit data! The logic has been extended so that you can indicate 32 bit in the i2s_config.

    static const i2s_config_t i2s_config = {
        .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX),
        .sample_rate = 44100, // corrected by info from bluetooth
        .bits_per_sample = (i2s_bits_per_sample_t) 32, /* the A2DP 16 bits will be expanded to 32 bits */
        .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
        .communication_format = I2S_COMM_FORMAT_I2S_MSB,
        .intr_alloc_flags = 0, // default interrupt priority
        .dma_buf_count = 8,
        .dma_buf_len = 64,
        .use_apll = false
    };

    a2dp_sink.set_i2s_config(i2s_config);

Clone this wiki locally