本帖最后由 depboy 于 2026-8-6 13:06 编辑
**I2S直驱功放,告别模拟功放电流声困扰,50W*2输出**
**可接入MusicAssistant,全天自动化播放背景音乐**
ESPHome老早就更新了基于ESP32S3的声音组件了,不过最近都在忙别的事情,一直没有时间去做起来。
一直想做一个背景音乐播放器,不过要和HA联动,还要音质好,还要能播放TTS,搜了一下论坛,各有千秋,但都不太优雅。
知道ESPHOME更新了声音组件,可以通过I2S输出声音信号,还支持TTS,就把这个项目提上了日程。
早先想到的方案是ESP32S3输出I2S信号给DAC,然后通过3.5mm耳机插口给模拟功放输出。
但做好后有细微电流声不说,模拟功放的开关和音量调整总是不能在HA中操作,很烦!
在一次淘宝浏览中发现了一枚数字功放IC,I2S输入,50W*2输出,可直接推书架音箱,这挺符合我的需求的。
随即购买回来研究。
仅需供电,I2S信号输入,I2C控制输入,即可直接输出中功率放大后的信号给书架音箱,简洁易用。
在搭建好测试板验证通过后开始正式绘制PCB。
DCDC使用RT7272A,外围元件简单,最高支持36V输入,结合数字功放参数,本电路最高支持电压为24V
ESP32部分支持ESP32与ESP32S3,设计打算支持不同场景应用,在不需要音频播放时焊接ESP32,就可作为一般的应用。
输入电压为12V-24V
在大功率端设置了两个保险,作为短路保护
散热片左侧的四个2.54插座是作为扩展接口使用,以便接入射频接收或发射,人感雷达,环境温度等等外设。
每个插座插针从上到下依次为GND,+3.3V,IO口,IO口。
在插座左侧标注插针IO编号,括号外为搭载ESP32时的IO号,括号内为搭载ESP32S3时的IO号。
左下角的三个MOS是作为LED灯带控制,灯带插座右侧的U7插座计划是作为触摸功能。
ESPHOME代码如下,烧录后即可对ACM8629进行控制。
需注意的是代码中“数字开关”为I2C控制,PDN为物理引脚控制,PDN需先置高,才允许I2C信号出入。
i2c:
sda: 13
scl: 14
frequency: 20kHz
scan: True
i2c_device:
id: i2cdev
address: 0x14
psram:
mode: octal
speed: 80MHz
#ignore_not_found: False
i2s_audio:
i2s_lrclk_pin: 10
i2s_bclk_pin: 11
speaker:
- platform: i2s_audio
id: speaker_id
dac_type: external
i2s_dout_pin: 12
sample_rate: 48000
- platform: mixer
id: mixer_speaker_id
output_speaker: speaker_id
source_speakers:
- id: announcement_spk_mixer_input
- id: media_spk_mixer_input
- platform: resampler
id: media_spk_resampling_input
output_speaker: media_spk_mixer_input
- platform: resampler
id: announcement_spk_resampling_input
output_speaker: announcement_spk_mixer_input
media_player:
- platform: speaker
name: "Speaker Media Player"
id: speaker_media_player_id
announcement_pipeline:
speaker: speaker_id
num_channels: 1
media_pipeline:
speaker: media_spk_resampling_input
num_channels: 2
switch:
- platform: template
name: "开关"
lambda: |-
uint8_t i2c_cache[1];
if(id(i2cdev).read_bytes(0x04, i2c_cache, 1)){
if((i2c_cache[0] & 0x02) && (i2c_cache[0] & 0x01)){
return true;
} else {
return false;
}
}
turn_on_action:
then:
lambda: id(i2cdev).write_byte(0x04, 0x03);
turn_off_action:
then:
lambda: id(i2cdev).write_byte(0x04, 0x00);
- platform: gpio
pin: 21
name: "ACM8629 PDN"
id: AMP_PDN
restore_mode: ALWAYS_ON
button:
- platform: template
name: "复位"
on_press:
then:
- lambda: id(i2cdev).write_byte(0x01, 0x80);
sensor:
- platform: adc
id: temp_adc
pin: 4
attenuation: auto
update_interval: 1s
- platform: resistance
sensor: temp_adc
id: resadc
resistor: 10kOhm
configuration: DOWNSTREAM
internal: True
name: "ADC1"
- platform: ntc
sensor: resadc
id: bambu_temp
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: "NTC1-功放温度"
- platform: adc
id: temp_adc2
pin: 5
attenuation: auto
update_interval: 1s
- platform: resistance
sensor: temp_adc2
id: resadc2
resistor: 10kOhm
configuration: DOWNSTREAM
internal: True
name: "ADC2"
- platform: ntc
sensor: resadc2
id: bambu_temp2
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
name: "NTC2-板上温度"
number:
- platform: template
name: "硬件音量"
icon: "mdi:volume-high"
min_value: 0
max_value: 255
step: 1
mode: SLIDER
restore_value: true
set_action:
then:
lambda: |-
id(i2cdev).write_byte(0x0f, x);
id(i2cdev).write_byte(0x10, x);
使用下来,功放输出音质还挺不错的,从MusicAssistant发送过来的FLAC数据流经过ESP32S3解码发送给ACM8629直接放大输出
省略了模拟电路,避免了开关机POP音与模拟电路引发的电流声。
最大50W*2功率带动家用书架音箱绰绰有余,最大声音可以覆盖整个房子
项目已经开源,有需要的朋友可以自行复刻
https://oshwhub.com/depboy/project_yutphmid
|