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 entryaudio_dac: - platform: pcm5122 id: pcm5122_dacConfiguration variables
Section titled “Configuration variables”- 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, or32bit. Defaults to16bit. - analog_gain (Optional, enum): The analog output gain applied by the PCM5122. One of
0dbor-6db. Defaults to0db. - 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.0dBto24.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.0dBto24.0dB. Defaults to0dB. - 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.
Automations
Section titled “Automations”All Audio DAC Automations are supported by this platform.
Switch
Section titled “Switch”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"Switch Configuration Variables
Section titled “Switch Configuration Variables”- 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
standbyorpowerdown. Defaults topowerdown. - All other options from Switch.
Pin Configuration
Section titled “Pin Configuration”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: truePin configuration variables
Section titled “Pin configuration variables”- pcm5122 (Required, ID): The ID of the PCM5122 component.
- number (Required, int): The GPIO pin number. Must be between
3and6. - mode (Required): Configure the pin direction. Exactly one of
inputoroutputmust be set totrue.- input (Optional, bool): Set as input pin. Defaults to
false. Not available on GPIO6. - output (Optional, bool): Set as output pin. Defaults to
false.
- input (Optional, bool): Set as input pin. Defaults to
- inverted (Optional, bool): Invert the logic level of the pin. Defaults to
false.
Configuration Example
Section titled “Configuration Example”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 pinswitch: - 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 inputbinary_sensor: - platform: gpio id: pcm5122_gpio_input pin: pcm5122: pcm5122_dac number: 5 mode: input: true