Skip to content

PCM5122

The pcm5122 platform allows your ESPHome devices to use the PCM5122 high-performance stereo audio DAC. This allows the playback of audio via the microcontroller from a range of sources via Speaker or Media Player.

The I²C bus is required in your configuration as this is used to communicate with the PCM5122.

# Example configuration entry
audio_dac:
- platform: pcm5122
id: pcm5122_dac
  • address (Optional, int): The I²C address of the device. Defaults to 0x4D.
  • bits_per_sample (Optional, enum): The bit depth of the audio samples. One of 16bit, 24bit, or 32bit. Defaults to 16bit.
  • analog_gain (Optional, enum): The analog output gain applied by the PCM5122. One of 0db or -6db. Defaults to 0db.
  • channel_mix (Optional, enum): How audio channel data is routed to the left and right outputs. One of:
    • stereo (default): Left data to left output, right data to right output.
    • left: Left channel data to both outputs.
    • right: Right channel data to both outputs.
    • swapped: Left and right outputs swapped.
  • volume_min_db (Optional, dB): The volume level that maps to the minimum volume (fully turned down). Must be less than volume_max_db. Range: -103.0dB to 24.0dB. Defaults to -52.5dB.
  • volume_max_db (Optional, dB): The volume level that maps to the maximum volume (fully turned up). Must be greater than volume_min_db. Range: -103.0dB to 24.0dB. Defaults to 0dB.
  • enable_pin (Optional, Pin): GPIO pin connected to the PCM5122's XSMT (soft mute) pin. Held low during setup() and driven high once initialization succeeds. Omit if XSMT is hardwired high.
  • i2c_id (Optional): The ID of the I²C bus the PCM5122 is connected to.
  • All other options from Audio DAC.

All Audio DAC Automations are supported by this platform.

The pcm5122 switch platform provides a switch to place the PCM5122 into standby or powerdown mode.

switch:
- platform: pcm5122
pcm5122: pcm5122_dac
name: "PCM5122 Power Down"
  • pcm5122 (Required, ID): The ID of the PCM5122 component.
  • power_mode (Optional, enum): The power state to enter when the switch is turned on. One of standby or powerdown. Defaults to powerdown.
  • All other options from Switch.

The PCM5122 exposes GPIO pins 3 through 6 that can be used as general-purpose input or output pins within ESPHome. These pins can be used anywhere a GPIO pin is accepted.

NOTE

GPIO6 cannot be used as an input pin on the PCM5122.

# Example: use PCM5122 GPIO4 as an output (e.g. to enable an amplifier)
output:
- platform: gpio
id: pcm5122_amp_enable
pin:
pcm5122: pcm5122_dac
number: 4
mode:
output: true
  • pcm5122 (Required, ID): The ID of the PCM5122 component.
  • number (Required, int): The GPIO pin number. Must be between 3 and 6.
  • mode (Required): Configure the pin direction. Exactly one of input or output must be set to true.
    • input (Optional, bool): Set as input pin. Defaults to false. Not available on GPIO6.
    • output (Optional, bool): Set as output pin. Defaults to false.
  • inverted (Optional, bool): Invert the logic level of the pin. Defaults to false.
i2c:
sda: GPIOXX
scl: GPIOXX
i2s_audio:
- id: i2s_output
i2s_lrclk_pin: GPIOXX
i2s_bclk_pin: GPIOXX
audio_dac:
- platform: pcm5122
id: pcm5122_dac
address: 0x4D
bits_per_sample: 16bit
analog_gain: -6db
channel_mix: stereo
volume_min_db: -60dB
volume_max_db: -3dB
enable_pin: GPIOXX
speaker:
- platform: i2s_audio
i2s_audio_id: i2s_output
id: speaker_id
i2s_dout_pin: GPIOXX
dac_type: external
audio_dac: pcm5122_dac
# Use PCM5122 GPIO4 to control an external amplifier enable pin
switch:
- platform: gpio
name: "Amplifier Enable"
pin:
pcm5122: pcm5122_dac
number: 4
mode:
output: true
restore_mode: RESTORE_DEFAULT_ON
- platform: pcm5122
pcm5122: pcm5122_dac
name: "PCM5122 Power Down"
# Use PCM5122 GPIO5 as a binary sensor input
binary_sensor:
- platform: gpio
id: pcm5122_gpio_input
pin:
pcm5122: pcm5122_dac
number: 5
mode:
input: true