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. - 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.
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.
# Example: use PCM5122 GPIO4 as an output (e.g. to enable an amplifier)switch: - platform: gpio name: "Amplifier Enable" pin: pcm5122: pcm5122_dac number: 4 mode: output: true inverted: falsePin 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. - 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
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