🛠 Son sur CM4 : DAC I2S/PCM (PCM5102) sans prise jack
Objectives
The CM4 has no audio jack (no embedded ADC/DAC), but exposes a PCM (I2S) interface on its pins. This tutorial connects an inexpensive I2S DAC (PCM5102) to the HAT footprint of the IO Board and configures the board as the default audio output via a device tree overlay — the standard approach across the entire BCM2711 ecosystem.
Hardware
- 1 × CM4 on IO Board, running 64-bit Raspberry Pi OS
- 1 × PCM5102 I2S DAC (an "I2S stereo DAC" module, ~€5), powered by 5 V
- HAT wiring: GPIO18=SCLK (bit clock), GPIO19=LRCLK (word clock), GPIO21=BCLK/DIN (data), 5 V and GND — verify the exact pinout of the module (some invert BCLK/LRCLK)
- Amplified speaker or headphones connected to the DAC output
Complete code
# 1) Activer I2S et charger le driver du DAC
sudo raspi-config nonint do_i2s 0 # active device tree I2S
{ echo 'dtparam=i2s=on'; echo 'dtoverlay=hifiberry-dac'; } | sudo tee -a /boot/firmware/config.txt
sudo reboot
# 2) Vérifier la carte audio
aplay -l # attendu : snd_rpi_hifiberry_dac
cat /proc/asound/cards
# 3) En faire la sortie par défaut
cat > /etc/asound.conf <<'EOF'
pcm.!default {
type plug
slave.pcm "hw:1,0"}
EOF
# 4) Test sonore
speaker-test -D plughw:1,0 -c 2 -t sin -f 440 --duration 3
Expected verification
aplay -l lists snd_rpi_hifiberry_dac; speaker-test produces a clear 440 Hz tone in the speaker; a wav file plays with aplay music.wav without options. dmesg | grep -i hifiberry shows no probe errors.
Common errors
- Looking for the Pi 4B's jack: the CM4 doesn't have one; without an external DAC,
aplay -lonly shows HDMI — this is normal. - SCLK/LRCLK/DIN swapped: the classic symptom is total silence or mono crackling; swap LRCLK and BCLK on the DAC module.
- Missing overlay: without
dtoverlay=hifiberry-dac, the I2S bus runs idle and no ALSA card appears. - Powering the DAC with 3.3 V when it requires 5 V: inaudible or distorted volume; check the pinout of the purchased module.
Other tutorials for this board
- Premier démarrage d'un CM4 Lite depuis la microSD de l'IO Board
- GPIO du CM4 : comprendre les banks 1,8 V / 3,3 V avant de câbler
- Basculer le Wi-Fi du CM4 sur l'antenne externe U.FL (dtparam=ant2)
- Bootloader EEPROM du CM4 : maîtriser BOOT_ORDER via usbboot
- Ajouter une RTC au CM4 (PCF8523 sur I2C1 via dt-blob)
- Horodatage industriel : PTP IEEE 1588 sur le PHY Ethernet du CM4
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash