Angled view of the pre-soldered PCM5102 I2S stereo DAC board and audio jack

PCM5102 Pre-Soldered I2S Stereo DAC Audio Module | ShillehTek Product Manual

ArduinoESP32Raspberry PiPicomanual-product-10645386101023
$6.99 USD Out of stock

Overview

The PCM5102 module is a stereo digital-to-analog converter (DAC). It takes I2S audio, the digital audio bus found on many microcontrollers and single-board computers, and turns it into a clean line-level stereo signal on a 3.5 mm jack. Feed that signal to an amplifier, powered speakers or the AUX input of a stereo.

It is a popular way to add good-quality sound to an ESP32, a Raspberry Pi or a Raspberry Pi Pico. The chip creates its own master clock, so three signal wires are enough, and the headers come pre-soldered. Note that this is a line output, not a speaker amplifier: it cannot drive a bare speaker.

At a Glance

Type
I2S stereo DAC, line output
DAC IC
PCM5102A
Supply
3.3 V to 5 V on VIN
Logic Level
3.3 V
Audio Format
I2S, up to 32-bit / 384 kHz
Output
2.1 Vrms stereo, 3.5 mm jack

Specifications

Parameter Value
DAC IC PCM5102A stereo DAC with built-in line driver
Audio input I2S: BCK (bit clock), LCK (word clock), DIN (data)
Master clock Not needed: tie SCK to GND and the chip makes its own clock from BCK
Sample rates 8 kHz to 384 kHz, detected automatically
Resolution 16, 24 or 32 bit
Output level 2.1 Vrms full scale (line level)
Outputs 3.5 mm stereo jack, plus LROUT, ROUT and AGND header pins
Supply voltage 3.3 V to 5 V on VIN
Logic level 3.3 V (not 5 V tolerant)
Option pins FLT, DEMP, XSMT and FMT, preset by solder jumpers on the back

Pinout Diagram

The six-pin header on the short edge carries power and the I2S signals: SCK, BCK, DIN, LCK, GND and VIN. The nine-pin header along the long edge carries the option pins (FLT, DEMP, XSMT, FMT), a 3.3 V output (A3V3) and the analog outputs (ROUT, LROUT, AGND). Most projects only use the six-pin header and the jack.

PCM5102 I2S stereo DAC module pinout diagram showing SCK, BCK, DIN, LCK, GND, VIN and the FLT, DEMP, XSMT, FMT, A3V3, AGND, ROUT, LROUT pins

Wiring Guide

Connect power, ground and the three I2S signals, and tie SCK to GND so the DAC generates its own master clock. Keep the I2S wires short. Then plug an amplifier or powered speakers into the 3.5 mm jack.

Arduino Wiring (Nano 33 IoT, MKR, Zero)

The Arduino Uno and classic Nano have no I2S port, so they cannot drive this DAC. The SAMD21 boards below can, using the I2S library that comes with their board package.

DAC Pin Nano 33 IoT MKR Zero
VIN 3.3V VCC 3.3V
GND GND GND GND
SCK GND GND GND
LCK A2 3 0
BCK A3 2 1
DIN 4 A6 9
No Uno: The Uno, Mega and classic Nano have no I2S hardware, and their 5 V logic is too high for this 3.3 V DAC. Use one of the boards above, an ESP32 or a Pico instead.

ESP32 Wiring

DAC Pin ESP32 Pin Function
VIN 5V Power
GND GND Ground
SCK GND Tie low
BCK GPIO 26 Bit clock
LCK GPIO 25 Word clock
DIN GPIO 22 Audio data
Any pins: The ESP32 can route I2S to almost any GPIO. If you use other pins, change the three pin numbers at the top of the sketch to match.

Raspberry Pi Wiring

Edit /boot/firmware/config.txt: put a # in front of dtparam=audio=on, add the line dtoverlay=hifiberry-dac, then reboot. The DAC then shows up as a sound card, which you can confirm with aplay -l.

DAC Pin Pi Pin Function
VIN 5V (Pin 2) Power
GND GND (Pin 6) Ground
SCK GND (Pin 9) Tie low
BCK GPIO 18 (Pin 12) Bit clock
LCK GPIO 19 (Pin 35) Word clock
DIN GPIO 21 (Pin 40) Audio data
No sound? If aplay -l lists more than one card, HDMI may be the default. Play to the DAC by name, for example: aplay -D plughw:CARD=sndrpihifiberry tone.wav

Raspberry Pi Pico Wiring

DAC Pin Pico Pin Function
VIN 3V3(OUT) (Pin 36) Power
GND GND (Pin 38) Ground
SCK GND (Pin 23) Tie low
BCK GP16 (Pin 21) Bit clock
LCK GP17 (Pin 22) Word clock
DIN GP18 (Pin 24) Audio data
Pin order: MicroPython on the Pico needs LCK on the GPIO right after BCK, for example GP16 and GP17. Any other pairing fails when the I2S object is created.

Code Examples

View or download this product's example code on GitHub.

Each example plays a steady test tone of about 440 Hz, enough to confirm the wiring before you move on to real audio. Keep the amplifier volume low for the first test.

Arduino Nano 33 IoT, MKR and Zero — Test Tone

pcm5102_tone_arduino.ino
// PCM5102 I2S DAC - 440 Hz test tone from an I2S-capable Arduino
// For SAMD21 boards (Nano 33 IoT, MKR family, Zero). The Uno and classic Nano have no I2S.
// Wiring: LCK = A2 (Nano 33 IoT), 3 (MKR) or 0 (Zero)
//         BCK = A3 (Nano 33 IoT), 2 (MKR) or 1 (Zero)
//         DIN = 4 (Nano 33 IoT), A6 (MKR) or 9 (Zero)
//         VIN = 3.3V, GND = GND, SCK = GND
#include <I2S.h>

const int sampleRate = 8000;       // samples per second
const int frequency  = 440;        // tone pitch in Hz
const int amplitude  = 2000;       // volume, up to 32767
const int halfWave   = sampleRate / frequency / 2;   // samples per half wave

short sample = amplitude;
int count = 0;

void setup() {
  Serial.begin(115200);
  if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) {
    Serial.println("Failed to start I2S");
    while (true) { delay(1000); }
  }
}

void loop() {
  if (count % halfWave == 0) {
    sample = -sample;                // flip the square wave
  }
  I2S.write(sample);                 // left channel
  I2S.write(sample);                 // right channel
  count++;
}

ESP32 — Sine Test Tone

pcm5102_tone_esp32.ino
// PCM5102 I2S DAC - 440 Hz sine test tone from an ESP32
// Needs the ESP32 board package 3.0 or newer, which provides ESP_I2S.h
// Wiring: VIN = 5V, GND = GND, SCK = GND, BCK = GPIO 26, LCK = GPIO 25, DIN = GPIO 22
#include <ESP_I2S.h>

const int PIN_BCK = 26;
const int PIN_LCK = 25;
const int PIN_DIN = 22;

const int sampleRate  = 44100;     // samples per second
const float frequency = 440.0;     // tone pitch in Hz
const int amplitude   = 4000;      // volume, up to 32767

I2SClass i2s;
int16_t samples[512];              // 256 stereo frames: left, right, left, right ...
float phase = 0.0;

void setup() {
  Serial.begin(115200);
  i2s.setPins(PIN_BCK, PIN_LCK, PIN_DIN);
  if (!i2s.begin(I2S_MODE_STD, sampleRate, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO)) {
    Serial.println("Failed to start I2S");
    while (true) { delay(1000); }
  }
}

void loop() {
  const float step = 2.0 * PI * frequency / sampleRate;
  for (int i = 0; i < 256; i++) {
    int16_t value = (int16_t)(amplitude * sin(phase));
    samples[2 * i] = value;          // left channel
    samples[2 * i + 1] = value;      // right channel
    phase += step;
    if (phase >= 2.0 * PI) phase -= 2.0 * PI;
  }
  i2s.write((uint8_t *)samples, sizeof(samples));   // waits until the samples are queued
}

Raspberry Pi — Play a Test Tone (Python)

pcm5102_tone.py
#!/usr/bin/env python3
# PCM5102 I2S DAC on Raspberry Pi - create a test tone and play it
# One-time setup in /boot/firmware/config.txt: put a # in front of dtparam=audio=on,
# add the line dtoverlay=hifiberry-dac, then reboot.
# Wiring: VIN = 5V (pin 2), GND = pin 6, SCK = GND, BCK = GPIO 18 (pin 12),
#         LCK = GPIO 19 (pin 35), DIN = GPIO 21 (pin 40)
import math
import struct
import subprocess
import wave

RATE = 44100          # samples per second
FREQ = 440.0          # tone pitch in Hz
SECONDS = 2
VOLUME = 0.2          # 0.0 to 1.0

frames = bytearray()
for n in range(RATE * SECONDS):
    value = int(32767 * VOLUME * math.sin(2 * math.pi * FREQ * n / RATE))
    frames += struct.pack("<hh", value, value)      # left and right sample

with wave.open("tone.wav", "wb") as wav:
    wav.setnchannels(2)         # stereo
    wav.setsampwidth(2)         # 16-bit samples
    wav.setframerate(RATE)
    wav.writeframes(bytes(frames))

subprocess.run(["aplay", "tone.wav"], check=True)

Raspberry Pi Pico — Sine Test Tone (MicroPython)

pcm5102_pico.py
# PCM5102 I2S DAC on Raspberry Pi Pico (MicroPython) - 441 Hz sine test tone
# Wiring: VIN = 3V3(OUT), GND = GND, SCK = GND, BCK = GP16, LCK = GP17, DIN = GP18
from machine import I2S, Pin
import math
import struct

RATE = 22050          # samples per second
FREQ = 441            # tone pitch in Hz (exactly 50 samples per wave at this rate)
VOLUME = 0.2          # 0.0 to 1.0

# On the Pico the LCK (ws) pin must be the GPIO right after the BCK (sck) pin
audio = I2S(0, sck=Pin(16), ws=Pin(17), sd=Pin(18),
            mode=I2S.TX, bits=16, format=I2S.MONO, rate=RATE, ibuf=4000)

samples_per_wave = RATE // FREQ
wave = bytearray(samples_per_wave * 2)
for n in range(samples_per_wave):
    value = int(32767 * VOLUME * math.sin(2 * math.pi * n / samples_per_wave))
    struct.pack_into("<h", wave, n * 2, value)

try:
    while True:
        audio.write(wave)       # waits until the samples are queued
except KeyboardInterrupt:
    audio.deinit()

Frequently Asked Questions

Why is there no sound from my PCM5102?
Check four things. SCK must be tied to GND. XSMT must be high: the DAC is muted while it is low, so if the jumper on the back is not set that way, connect XSMT to the A3V3 pin. BCK, LCK and DIN must go to the pins named in your code. And the jack needs an amplifier or powered speakers, because the output is line level.
Do I need to connect SCK?
You do not need to feed it a master clock. With SCK tied to GND, the PCM5102A builds its own clock from BCK, which is why three signal wires are enough. Do not leave SCK floating: a floating pin picks up noise and can cause dropouts or silence.
Can I connect a speaker or headphones directly?
Not a speaker. The module is a line-level output with no power amplifier, so it needs an amplifier or powered speakers after it. Headphones plugged straight into the jack play quietly at best. To drive a small speaker directly from I2S, use an amplifier such as the MAX98357 instead.
Does it work with an Arduino Uno?
No. The Uno, Mega and classic Nano have no I2S hardware, and their 5 V logic is too high for this 3.3 V DAC. Use an I2S-capable board such as an ESP32, a Raspberry Pi, a Pico, or a SAMD21 Arduino like the Nano 33 IoT.
What do FLT, DEMP, XSMT and FMT do?
They are option pins, preset by the solder jumpers on the back. FLT picks the digital filter: low is normal, high is low latency. DEMP switches 44.1 kHz de-emphasis on when high. XSMT is the soft mute: low mutes, high plays. FMT selects the audio format: low is I2S, high is left-justified. For normal I2S playback you want FLT low, DEMP low, XSMT high and FMT low.
Which Raspberry Pi overlay do I use?
Add dtoverlay=hifiberry-dac to /boot/firmware/config.txt, put a # in front of dtparam=audio=on, and reboot. That overlay is made for PCM5102A boards like this one. The DAC then appears as a normal ALSA sound card, so aplay, mpd and other players can use it.
What sample rates and bit depths can it play?
The PCM5102A accepts 16, 24 and 32-bit I2S audio at sample rates from 8 kHz up to 384 kHz. It detects the rate from the incoming clocks, so there is nothing to set on the board. CD-quality audio at 16 bit and 44.1 kHz works without any changes.

Related Tutorials