The GY-PCM5102 is a compact I²S audio DAC module using the PCM5102 chip to convert digital I²S audio into clean analogue stereo output. Designed for Raspberry Pi, ESP32 and other I²S-capable hosts, this board delivers improved analogue audio quality compared to on-board audio outputs, and is ideal for DIY Hi-Fi players, network audio streamers and audio experiments.
PCM5102 Module Pin Raspberry Pi (40-pin header) ------------------ ----------------------------- GND GND (Pin 6, 9, 14, etc.) VCC 5V or 3.3V (see module spec) <-- CHECK MODULE BEFORE POWERING BCLK (Bit Clock) PCM_CLK / GPIO18 (Pin 12) LRCLK (Word Clock) PCM_FS / GPIO19 (Pin 35) DIN / DATA (SD) PCM_DIN / GPIO21 (Pin 40) <-- Pi outputs data on this pin Analog L / R RCA / header (module dependent)
IMPORTANT: Confirm VCC level on your module before connecting power. Wrong voltage can damage the board.
dtparam=i2s=on in /boot/config.txt or use raspi-config).sudo apt update && sudo apt install -y alsa-utils.aplay -l to list audio devices and play a test WAV with aplay -D plughw:0,0 sample.wav (device id may vary).Use this Arduino-style ESP32 sketch to test the PCM5102 by playing a 440 Hz sine tone over I²S.
// ESP32 — I2S sine test for PCM5102 (Arduino framework)
// Connect ESP32 I2S pins to PCM5102 (check your module pin labels).
// Example pin mapping (change to your wiring):
// BCLK -> GPIO26
// LRCLK -> GPIO25
// DOUT -> GPIO22
//
// This sketch generates a 440 Hz sine wave (stereo, 16-bit, 44.1kHz)
// and outputs continuously via I2S to the DAC (PCM5102).
#include <driver/i2s.h>
#include <math.h>
#define I2S_NUM I2S_NUM_0
#define SAMPLE_RATE 44100
#define SINE_FREQ 440.0f
#define PI 3.14159265f
const int I2S_BCLK_PIN = 26;
const int I2S_LRCK_PIN = 25;
const int I2S_DATA_PIN = 22;
const int BUFFER_SAMPLES = 512;
int16_t i2s_buffer[BUFFER_SAMPLES * 2];
void setupI2S() {
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
.intr_alloc_flags = 0,
.dma_buf_count = 4,
.dma_buf_len = BUFFER_SAMPLES,
.use_apll = false,
.tx_desc_auto_clear = true
};
i2s_pin_config_t pin_config = {
.bck_io_num = I2S_BCLK_PIN,
.ws_io_num = I2S_LRCK_PIN,
.data_out_num = I2S_DATA_PIN,
.data_in_num = I2S_PIN_NO_CHANGE
};
i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM, &pin_config);
}
void fill_sine_buffer(float frequency) {
const float amplitude = 0.7f * 32767.0f;
for (int i = 0; i < BUFFER_SAMPLES; ++i) {
float sample = amplitude * sinf(2.0f * PI * frequency * ((float)i / (float)SAMPLE_RATE));
int16_t s = (int16_t)sample;
i2s_buffer[2 * i] = s;
i2s_buffer[2 * i + 1] = s;
}
}
void setup() {
Serial.begin(115200);
delay(200);
Serial.println("ESP32 I2S PCM5102 sine test starting...");
setupI2S();
fill_sine_buffer(SINE_FREQ);
}
void loop() {
size_t bytes_written = 0;
size_t bytes_to_write = sizeof(i2s_buffer);
esp_err_t err = i2s_write(I2S_NUM, (const char*)i2s_buffer, bytes_to_write, &bytes_written, portMAX_DELAY);
if (err != ESP_OK) {
Serial.printf("i2s_write error: %d\n", err);
delay(200);
}
}
// Note: For Raspberry Pi use ALSA/overlays; for Arduino-based MCUs with I2S support (ESP32 above) use the provided ESP32 example. // To play stored audio files you need an audio decoder (e.g., WAV decode) and a file system (SPIFFS/SD) or streaming source.
✨ Fast Shipping • 🔒 Secure Checkout