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
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.
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 |
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 |
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 |
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 |
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 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 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)
#!/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 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()



