
本文来源:http://www.lpqz.cn/news/107366
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
不用写主标题直接从第1节开始。这篇博文按下述结构展开,重点放在“为什么这么做”和“实测经验”上,尽量让想复刻的人少走弯路。
1. 为何把目光落在ESP32与TEF6686这对组合上。先说结论,这套DIY方案做出来的不是普通收音机,而是一台“带大脑”的数字信号处理接收机。TEF6686负责把射频信号变成高保真音频,ESP32则充当大脑,承担控制、显示、联网甚至流媒体扩展的工作。两片芯片加起来不到30块钱物料成本,却能把市面上几百块的DSP便携收音机按在地上摩擦,这就是我最初被这个组合吸引的原因。TEF6686是NXP推出的车规级DSP收音机芯片,支持FM、AM、LW、SW全波段,内部集成了完整的射频前端、中频处理、立体声解码和音频DSP。它最革命性的地方在于,传统收音机需要用可变电容、电感线圈、陶瓷滤波器这些模拟元件去实现的选台和解调,在TEF6686里全部变成了数字算法。你不需要去计算本振频率、中频带宽、鉴频特性这些棘手参数,只需要通过I2C总线告诉芯片“我要听106.8MHz”,芯片内部就会自动完成从射频采样到音频输出的全部工作。ESP32在这里的角色同样不可替代。它自带Wi-Fi和蓝牙,性能足够跑起复杂的UI逻辑和网络协议栈,而且Arduino生态极其成熟,社区里有大量现成库可用。更重要的是ESP32的ADC和定时器资源可以灵活配置,配合编码器旋钮做频率扫描时手感能做到和商用收音机一样顺滑。如果未来想加RDS解码、网络电台、蓝牙音箱功能,ESP32的余量也完全够用。这个项目适合有一定Arduino基础、想深入理解无线电接收链路、又不想被模拟电路调试折磨的电子爱好者。它最大的价值不是让你拥有一台收音机,而是通过一个完整的软硬件闭环理解现代DSP接收机是怎么工作的。
2. 电路设计中的关键决策与元器件选型。2.1 电源路径让底噪降到可接受范围。这个项目最容易翻车的地方不是射频部分而是电源。TEF6686对电源纹波极其敏感,特别是FM频段,电源上的高频纹波会直接调制到音频输出上,表现为持续的“嘶嘶”声或“嗡嗡”声。ESP32的Wi-Fi射频开关瞬时功耗能达到300mA级别,这种脉冲负载会在共用电源轨上产生很大的瞬态压降,如果TEF6686和ESP32共用LDO,你会在喇叭里听到和Wi-Fi发包同步的“吱吱”声。我的方案是两级电源架构:锂电池首先经过一颗大电流LDO(我选了RT9013,3.3V/500mA)给ESP32供电,同时从电池端独立取电经过另一颗超低噪声LDO(型号选LP5907,输出3.3V,噪声只有12μVrms)单独给TEF6686供电。两路电源在PCB上完全分开走线,只在电池接入点单点汇合。这样做的好处是Wi-Fi瞬态电流的波动完全被第一级LDO吸收,不会耦合到TEF6686的供电轨上。实测数据对比,共用LDO时FM频段底噪大约在-55dBFS,改用独立LDO后底噪降到-68dBFS左右。人耳对这个差异的感受是“能接受”和“干净”的区别,所以电源分开走这一步绝对不能省。
2.2 I2C控制与音频输出的接线方案。TEF6686通过I2C总线与ESP32通信,地址固定为0x40。接线非常简单,SDA、SCL接ESP32的GPIO21和GPIO22(Arduino默认引脚),注意TEF6686的I2C是漏极开路结构,需要外接4.7kΩ上拉电阻到3.3V。我见过不少人在这一步偷懒直接用ESP32内部上拉,结果通讯时好时坏。内部上拉通常只有几十kΩ,在I2C总线较长或干扰大的情况下容易出错,所以老老实实用外部上拉电阻。音频输出方面,TEF6686的LNA_OUT引脚直接输出音频信号,但输出阻抗较高,不能直接驱动耳机或功放。标准做法是加一级运算放大器缓冲,我用了LMV321运放搭建同相跟随器,增益设为1倍,输出经过100μF耦合电容后驱动耳机。如果你想外接喇叭,可以再加一颗PAM8403这类D类功放板,注意D类功放的开关频率可能会干扰收音机,所以功放板要尽量远离天线和TEF6686,必要时在功放输入端加磁珠滤波。
2.3 显示与交互组件的选择。交互方案我建议使用带编码器按键的旋转编码器EC11加一块0.96寸SSD1306 OLED屏。EC11编码器负责频率调节和菜单选择,OLED屏显示频率、信号强度、立体声状态和RDS信息。OLED的I2C和TEF6686复用在同一条总线上,地址0x3C,两者互不影响。显示刷新这块有个坑:如果每转动一格编码器就让OLED整体重绘,屏幕会严重闪烁。正确的做法是采用“局部刷新”策略,只重绘频率数字变化的区域。SSD1306库支持设置显存窗口,我实测将刷新区域限定在频率数字那几行像素时,整个刷新手感非常流畅,而且几乎不占用ESP32的CPU时间。
3. PCB布局与外壳组装,从面包板到便携机。3.1 PCB布局的射频要点。如果你只是搭个面包板验证电路,那射频性能可以忽略,但要做到便携机的接收效果,PCB布局必须认真对待。TEF6686是QFN封装,底部有裸露焊盘,必须可靠接地,这不仅是散热问题更是射频接地问题。布局上我遵循几个原则:天线接口(SMA或IPEX)放在PCB边缘,进线后直接走微带线到TEF6686的RF输入引脚,路径尽量短避免打过孔;I2C和音频线走在PCB另一层,与RF走线用地层隔离;在TEF6686四周尽量多放过孔形成完善的射频接地屏蔽墙;电源电路的元器件布局在远离天线的一侧避免电源噪声耦合。另外要强调一点,TEF6686的参考时钟晶振位置离芯片越近越好,我见过有人把晶振放在PCB角落走很长线,结果FM接收灵敏度掉了将近20dB。晶振走线两旁加地线包边,底部不要走任何其他信号线。
3.2 屏蔽与接地技巧。便携收音机最容易忽视的是屏蔽。ESP32本身是一个强辐射源,Wi-Fi工作频段是2.4GHz,而TEF6686的FM前端工作频率在87到108MHz,虽然不直接重叠但ESP32的高次谐波会落入FM频段内,导致某些频点上出现“沙沙”的噪声底。解决方法是把ESP32部分做局部屏蔽,可以直接在ESP32模组上方贴一个铜箔屏蔽罩接地焊接到PCB的接地过孔上。还有一个接地细节,电池负极端到PCB地之间要用较粗的导线且尽量短。如果是18650电池加弹簧触点的方式供电,弹簧本身有电阻,当ESP32瞬间拉大电流时弹簧两端会产生电压降,引起地电位抖动,这个抖动会通过地回路耦合到TEF6686造成音频噪声。我最后用了双触点并联的电池仓,接触电阻从原来的90mΩ降到30mΩ,噪声问题明显缓解。
3.3 电池供电与功耗管理。系统总功耗大约在150mA左右(OLED全亮、ESP32工作、TEF6686运行),用一节18650电池容量以2500mAh为例理论上能工作16个小时。但ESP32在Wi-Fi开启状态下的静态功耗偏高,我在固件里做了两种处理:短按电源键进入深度睡眠模式,此时OLED也关闭,系统功耗降到30μA;长按则完全关机切断LDO使能脚。睡眠状态下按一下编码器按键就能唤醒,满足日常听收音机的使用习惯。充电管理方面我选了TP4056模块,充电电流设置为500mA,加装DW01A保护IC防止过放。数据线接口用Type-C母座,既能充电也能刷固件。
4. 固件架构,让ESP32驱动TEF6686。4.1 TEF6686寄存器与命令集初探。TEF6686的底层控制是通过写寄存器实现的,芯片内部其实是一套复杂的协议体系,需要按“应用层命令”的格式来操作。NXP提供的官方驱动很庞大不适合直接放进ESP32,好在开源社区里已有大神逆向整理出了精简版驱动,核心思想就几条:上电初始化时需要写入一系列Init序列大约十几条命令来配置芯片内部各路模块;选台时向0x04命令写入频率值和波段;读信号强度时向0x22命令发起查询再读取返回的RSSI值。I2C通讯格式上有个细节需要注意,TEF6686读取数据时要求主机先发送命令字节,等芯片内部处理完毕(典型延时5ms)再发起读操作,如果在命令发送后立即读取大概率读到的是无效数据。我最初在这个时序问题上卡了半天,后来加了延时就好。延时用delay(5)或用vTaskDelay(5/portTICK_PERIOD_MS)都行,推荐后者不阻塞系统调度。
4.2 Arduino环境下的驱动代码框架。我开发时用的板卡是ESP32 DevKitC V4(ESP32-WROOM-32模组),开发环境为Arduino IDE 2.x。驱动层我直接移植了peterus的TEF6686_Radio库,它已经把Init序列封装好了,你只需要实例化一个对象调用init()即可完成芯片初始化。核心代码骨架是include Wire.h和TEF6686_Radio.h,实例化radio对象,在setup里Wire.begin()、Serial.begin(115200)、radio.init()、radio.setBand(FM)、radio.setFrequency(106800)、radio.setStereo(true)、radio.setVolume(42),在loop里循环radio.getRSSI()并打印。注意setFrequency参数的单位是10Hz,所以106.8MHz要写成106800,这是新手最容易踩的坑之一。getRSSI返回的单位是dBμV,数值大概范围在20到70之间,数值越大信号越强。
4.3 旋钮与按键的状态机处理。EC11编码器的处理如果直接用查询方式,旋钮稍微转快点就会丢步。我采用定时中断方式,用ESP32的硬件定时器hw_timer_t以2ms周期采样编码器AB相,通过判断相位变化识别正反旋转,每转动一格累加频率步进。状态机方面我把旋钮的短按、长按、旋转分别映射为不同事件:旋转默认调节频率,步进模式可切换(10kHz、FM频道间隔或自动搜索),转动一格自动搜台;长按进入菜单,短按确认选项。这套交互逻辑用枚举状态机实现,模块间通过事件队列解耦,后续加功能很轻松。这里分享一个手感调校心得:频率显示要“即时响应”且不能跳跃太大,所以我把步进做了动态加速——转动速度快时自动加大步进,慢时恢复精细步进,体验和真机几乎一致,这个细节非常提升使用感受。
5. 显示界面与本地/网络控制。5.1 本地OLED显示逻辑。OLED显示内容我分为三层:主界面显示频率大字号、信号强度条形图、立体声/单声道状态、RDS文字;副界面显示菜单项目,支持“频率步进设置”“波段切换”“睡眠定时器”等选项;第三层是系统信息,比如电量、固件版本号。显示更新的核心优化是利用SSD1306的局部刷新能力。我用的是Adafruit_SSD1306库,display.display()会刷新整个显存,但如果我先把显存里的频率数字区域用fillRect清掉再重绘,最后统一display.display(),实际刷新的就是覆盖区域。在128x64分辨率下这只占用很少的I2C带宽。实测在循环里有Wi-Fi任务跑着的情况下显示刷新依然流畅,没有明显卡顿。
5.2 让收音机接入Wi-Fi网页遥控。既然用了ESP32不联网说不过去。我在固件里加了Wi-Fi控制页面,局域网内任何设备打开浏览器输入设备IP就能看到当前频率、信号强度和RDS信息,还能直接输入频率远程切台。这在客厅把收音机当背景音乐时很好用,手机当遥控器用不用专门凑到设备前操作。Web部分用的是ESPAsyncWebServer库,页面是嵌入式HTML加少量JavaScript,实现了简单的WebSocket推送,收音机状态变化时主动推送到网页避免重复轮询。后端把frequency、rssi、stereo等变量通过回调函数注册到WebSocket事件,前端拿到数据后更新DOM节点。整个过程不复杂但扩展性很好。这个功能也顺带解决了“固件升级后没法远程看状态”的痛点。如果你后续还想加网络电台,其实只需要在代码里增加一个HTTP音频流的解码任务,把解码后的PCM数据通过I2S输出到音频功放。不过音频流和收音机音频之间会有切换逻辑,这个就留给后续扩展了。
6. 天线、接收性能与灵敏度调校。6.1 拉杆天线匹配与前置滤波。TEF6686的RF输入是高阻抗输入,直接接一根几十厘米长的拉杆天线也能出声但灵敏度不理想,原因在于天线阻抗和芯片输入阻抗不匹配,信号在传输线上发生反射能量没有被充分吸收。商用DSP收音机内部都会做天线匹配网络,简单方案是用一个22nH到47nH的电感并联在RF输入端到地,再加一个1nF串联电容到天线端,构成简易的π型匹配网络。我实测了几种方案:直接接天线FM灵敏度大约在15dBμV,加了一个2.2pF并联电容后灵敏度提升到9dBμV,再加上电感匹配网络能做到6dBμV左右。这个数值差异反映在人耳上就是“弱台勉强能听”和“弱台清晰无误”的区别。匹配网络的具体参数因为PCB布局不同会有变化,建议你手边备几个不同值的元件边测边调,直到弱台的背景噪声最干净。
6.2 自动增益控制与信噪比实测。TEF6686内置AGC电路但需要软件配置AGC响应时间和目标增益,默认配置比较保守,在强台旁边容易产生互调干扰。我最终把AGC保持时间设为短档,增益上限设为中等,这样动态范围最均衡。实测数据:本地强台信号强度约60dBμV,信号下音频输出信噪比能做到68dB上下,立体声分离度大约42dB,听起来没有明显串音。市区弱台约25dBμV情况下单声道模式还能听清内容,但立体声模式就开始有噪声,此时固件里的自动模式会平滑从立体声切回单声道,这个切换算法需要在RSSI阈值附近做迟滞,否则会在边界反复横跳,迟滞设为3dB比较合适。
6.3 常见干扰源排查。便携设备本身的干扰源很隐蔽且和布局相关,我遇到过并且解决的几类问题供参考:ESP32的DCDC降压噪声干扰,当使用板上3.3V稳压器时DCDC开关噪声会辐射到FM频段,表现为全频段底噪升高,解决办法是把DCDC换成LDO;USB线带来的共模干扰,调试时USB线是连接到电脑的,电脑电源地噪声会顺着USB线进入设备,调试完成后用电池供电很多杂音会消失;OLED屏的I2C时钟辐射,1MHz的I2C时钟及其高次谐波可能会落在FM频段内,让I2C走线远离RF输入引脚,无法避免时加串联电阻330Ω减慢沿率。这些干扰排查起来都比较耗时,我的建议是拿到新PCB先做“裸板测试”,不焊OLED和编码器,只接必要接线,用示波器看音频输出波形噪声底。如果裸板噪声已经很大,不要指望后续软件救回来,先解决硬件基础再继续。
7. 踩坑记录,给后来者的避坑清单。7.1 问题一,I2C通讯间歇性失败。这几乎是所有TEF6686项目新手都会遇到的问题,现象是初始化偶尔成功、偶尔失败,或者工作一段时间后突然读不到RSSI。我排查的思路是这样:先测I2C波形,用示波器看SDA和SCL的上升沿是否变缓,如果上升沿时间超过1μs,典型原因是上拉电阻过大或总线电容过大,把上拉电阻从4.7kΩ换成2.2kΩ后问题解决。另一个容易被忽略的点是I2C总线上的电平冲突,TEF6686的I2C引脚支持1.8V到3.3V电平而ESP32的GPIO输出高电平是3.3V理论兼容,但如果OLED屏的VDD和TEF6686的VDD不是同一路可能导致逻辑电平不一致,确保所有I2C器件共用一个3.3V电源轨就没问题。
7.2 问题二,音频输出有滋滋声。“滋滋”声和“嗡嗡”声成因不同,“嗡嗡”多半是电源地环路问题,“滋滋”一般是数字信号耦合进音频路径。我在调试时发现OLED屏的刷新动作会在耳机里产生同步的“嘶嘶”声,尤其显示RDS信息时特别明显。用示波器测音频输出确实能看到和显示刷新同步的窄脉冲干扰。排查后确认是I2C数据线离音频走线太近,I2C的边沿脉冲通过寄生电容耦合进了音频信号。解决方法:把音频走线改到PCB另一层并用GND铜皮包裹,在运放输入端加一个100pF到地的低通电容。改板之后再测显示刷新产生的干扰完全消失。
7.3 问题三,FM立体声分离度忽好忽坏。这个问题的表现是同一个电台有时能听到明显立体声左右声道分离,过一会儿突然变成单声道,再过一会儿又恢复。初始以为是芯片故障,后来发现是RDS信号和立体声导频信号同时存在时音频DSP的自动模式切换得过于激进。TEF6686内部有个多路解码策略,当信号质量下降时它会把立体声解码自动切换到单声道以提高信噪比。解决办法不是关闭自动切换而是把切换的迟滞区间调大,在初始化序列里有一组配置立体声开关阈值的参数,手动把阈值从默认的25dBμV调整到30dBμV,恢复阈值设为28dBμV,迟滞量3dB,改完后就再也没有出现快速切换的情况。
8. 后续还能怎么玩,扩展思路。整台机器做完并稳定运行一段时间后你会发现这个系统的架构其实是一个“通用无线电前端”,收音机功能只是起点。我目前正在做几个方向的扩展:第一个是RDS数据利用,TEF6686自带RDS解调功能,目前固件已经能提取PI代码和电台名称,后续可以把PTY节目类型信息用于自动筛选,例如只搜音乐类电台、跳过广告类频道,这需要维护一张PI代码到节目类型的映射表,工作量不大但实用性很强;第二个是可变通带滤波,TEF6686的DSP滤波器带宽是可调的,从50kHz到200kHz不等,窄带能增强弱台的可读性,宽带能提升强台的音质,下一步我想把带宽参数暴露给用户做成可调旋钮实时调整听感;第三个是网络电台集成,ESP32连接Wi-Fi后可以播放MP3/AAC流,通过切换音频源实现“本地FM+网络电台”一体机模式,ESP32音频解码通常用VS1053模块或ESP-ADF框架,如果走I2S输出再接功放和当前收音机音频做个切换器就行;第四个是低功耗优化,当前深度睡眠已经能降到30μA,但RTC唤醒后只能看时间不能定时录音,后续计划用ESP32的RTC内存保存闹钟频率,到点自动唤醒并启动FM接收,把指定频点的音频通过ADC采样保存在SD卡,这样就成了一个简易的广播录音机,适合定时录制外语新闻或早间节目。最后再分享一个实际体会,做完这个项目你对“软件定义无线电”的理解会和看书完全不同。TEF6686本质上是一个高度集成化的小型无线电SoC,通过I2C控制它的过程其实就是在操作一个真实存在但看不见的接收机。当你亲手解决了电源噪声、I2C时序、天线匹配这些实际问题后再去看任何通信系统的原理图都会比以前通透得多,这或许就是DIY这类设备最大的收获。

本文来源:http://www.lpqz.cn/news/107366
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。
No main heading needed—start directly from Section 1. This blog post follows the structure below, focusing on 'why we do it this way' and 'lessons from hands-on testing,' so that those who want to replicate it can avoid as many detours as possible.
1. Why focus on the ESP32 and TEF6686 combination? Let me start with the conclusion: this DIY project produces not an ordinary radio, but a 'brain-equipped' digital signal processing receiver. The TEF6686 converts RF signals into high-fidelity audio, while the ESP32 acts as the brain, handling control, display, networking, and even streaming expansion. The two chips together cost less than 30 yuan in materials, yet they can utterly outperform DSP portable radios costing hundreds of yuan on the market—that's what first drew me to this combination. The TEF6686 is an automotive-grade DSP radio chip from NXP, supporting full-band FM, AM, LW, and SW reception, with a complete RF front end, IF processing, stereo decoding, and audio DSP integrated on chip. Its most revolutionary aspect is that station selection and demodulation—which in traditional radios require analog components such as variable capacitors, inductor coils, and ceramic filters—are all converted into digital algorithms inside the TEF6686. You don't need to calculate tricky parameters like local oscillator frequency, IF bandwidth, or discriminator characteristics; you simply tell the chip over the I2C bus 'I want to listen to 106.8 MHz,' and the chip automatically handles everything from RF sampling to audio output. The ESP32's role here is equally indispensable. It has built-in Wi-Fi and Bluetooth, performance sufficient to run complex UI logic and network protocol stacks, and an extremely mature Arduino ecosystem with a wealth of ready-made libraries in the community. More importantly, the ESP32's ADC and timer resources can be flexibly configured; when paired with an encoder knob for frequency scanning, the feel can be as smooth as a commercial radio. If you want to add RDS decoding, internet radio, or Bluetooth speaker functions later, the ESP32 has more than enough headroom. This project is suited to electronics enthusiasts who have some Arduino experience, want to deeply understand the radio reception chain, and don't want to be tormented by analog circuit debugging. Its greatest value is not that you end up with a radio, but that through a complete hardware-software loop you come to understand how a modern DSP receiver works.
2. Key decisions in circuit design and component selection. 2.1 Power path design to bring the noise floor down to an acceptable level. The most likely place for this project to fail is not the RF section but the power supply. The TEF6686 is extremely sensitive to power supply ripple, especially in the FM band; high-frequency ripple on the supply modulates directly onto the audio output, manifesting as a persistent 'hiss' or 'hum.' The ESP32's Wi-Fi RF switching can draw instantaneous power on the order of 300 mA, and this pulsed load produces a large transient voltage drop on a shared power rail. If the TEF6686 and ESP32 share an LDO, you'll hear a 'chirping' sound in the speaker synchronized with Wi-Fi packet transmission. My approach is a two-stage power architecture: the lithium battery first passes through a high-current LDO (I chose the RT9013, 3.3 V/500 mA) to power the ESP32, while power is taken independently from the battery terminal through another ultra-low-noise LDO (I chose the LP5907, 3.3 V output, with noise of only 12 μVrms) to supply the TEF6686 alone. The two power rails are routed completely separately on the PCB, meeting at a single point only at the battery input. The benefit is that Wi-Fi transient current fluctuations are fully absorbed by the first-stage LDO and don't couple onto the TEF6686's supply rail. Comparing measured data, with a shared LDO the FM-band noise floor was around -55 dBFS; after switching to a separate LDO it dropped to about -68 dBFS. To the human ear this difference is the difference between 'acceptable' and 'clean,' so the step of separating the power rails absolutely cannot be skipped.
2.2 Wiring scheme for I2C control and audio output. The TEF6686 communicates with the ESP32 over the I2C bus, with a fixed address of 0x40. The wiring is very simple: SDA and SCL connect to the ESP32's GPIO21 and GPIO22 (the Arduino default pins). Note that the TEF6686's I2C is an open-drain structure, requiring external 4.7 kΩ pull-up resistors to 3.3 V. I've seen many people take a shortcut here and use the ESP32's internal pull-ups directly, with the result that communication is intermittent. Internal pull-ups are typically only tens of kΩ, which is error-prone when the I2C bus is long or interference is strong, so just use external pull-up resistors properly. For audio output, the TEF6686's LNA_OUT pin outputs the audio signal directly, but its output impedance is relatively high and cannot directly drive headphones or an amplifier. The standard approach is to add an op-amp buffer stage; I used an LMV321 op-amp to build a non-inverting follower with the gain set to 1, and the output drives headphones through a 100 μF coupling capacitor. If you want to connect an external speaker, you can add a class-D amplifier board such as the PAM8403. Note that the switching frequency of a class-D amplifier may interfere with the radio, so keep the amp board as far as possible from the antenna and the TEF6686, and add ferrite bead filtering at the amplifier input if necessary.
2.3 Selection of display and interaction components. For the interaction scheme I recommend a rotary encoder with a built-in push button—the EC11—plus a 0.96-inch SSD1306 OLED display. The EC11 encoder handles frequency adjustment and menu selection, while the OLED displays the frequency, signal strength, stereo status, and RDS information. The OLED's I2C shares the same bus as the TEF6686, at address 0x3C, and the two don't affect each other. There's a pitfall when it comes to display refresh: if you redraw the entire OLED every time the encoder turns one detent, the screen will flicker badly. The correct approach is to use a 'partial refresh' strategy, redrawing only the region where the frequency digits change. The SSD1306 library supports setting a display-memory window. In my testing, when I limited the refresh region to just the few rows of pixels containing the frequency digits, the whole refresh felt very smooth and barely consumed any ESP32 CPU time.
3. PCB layout and enclosure assembly—from breadboard to portable unit. 3.1 RF essentials of PCB layout. If you're just building a breadboard to verify the circuit, RF performance can be ignored, but to achieve the reception performance of a portable unit, PCB layout must be taken seriously. The TEF6686 is in a QFN package with an exposed pad on the bottom that must be reliably grounded—this is not only a thermal issue but, more importantly, an RF grounding issue. In layout I follow several principles: place the antenna connector (SMA or IPEX) at the edge of the PCB, and route the incoming line directly as a microstrip to the TEF6686's RF input pin, keeping the path as short as possible and avoiding vias; route the I2C and audio traces on the other layer of the PCB, isolated from the RF traces by a ground plane; place as many vias as possible around the TEF6686 to form a proper RF ground shielding wall; and arrange the power circuit components on the side away from the antenna to avoid power-noise coupling. One more point worth emphasizing: the TEF6686's reference clock crystal should be placed as close to the chip as possible. I've seen people put the crystal in a corner of the PCB with a very long trace, and as a result FM reception sensitivity dropped by nearly 20 dB. Add ground guard traces along both sides of the crystal traces, and don't route any other signal traces underneath it.
3.2 Shielding and grounding techniques. The most easily overlooked aspect of a portable radio is shielding. The ESP32 itself is a strong radiation source—its Wi-Fi operating band is 2.4 GHz, while the TEF6686's FM front end operates at 87 to 108 MHz. Although these don't overlap directly, the ESP32's higher harmonics fall within the FM band, producing a 'hissing' noise floor at certain frequencies. The solution is to locally shield the ESP32 section: you can place a copper-foil shield can directly over the ESP32 module, grounding and soldering it to the PCB's ground vias. There's another grounding detail: use a fairly thick wire between the battery negative terminal and PCB ground, and keep it as short as possible. If you power the device with an 18650 battery plus spring contacts, the spring itself has resistance; when the ESP32 momentarily draws a large current, a voltage drop appears across the spring, causing ground-potential jitter. This jitter couples through the ground loop into the TEF6686, producing audio noise. In the end I used a battery holder with dual contacts in parallel, reducing contact resistance from 90 mΩ to 30 mΩ, which noticeably alleviated the noise problem.
3.3 Battery power and power management. Total system power consumption is around 150 mA (OLED fully on, ESP32 active, TEF6686 running); with a single 18650 battery of, say, 2500 mAh capacity, this theoretically gives about 16 hours of operation. However, the ESP32's quiescent power draw with Wi-Fi enabled is relatively high, so I handled this in the firmware in two ways: a short press of the power button enters deep-sleep mode, with the OLED also turned off, dropping system power consumption to 30 μA; a long press powers the device fully off by cutting the LDO's enable pin. In sleep mode, a single press of the encoder button wakes the device, which suits the daily habit of listening to the radio. For charge management I chose a TP4056 module with the charge current set to 500 mA, and added a DW01A protection IC to prevent over-discharge. The data connector is a Type-C female socket, used both for charging and for flashing firmware.
4. Firmware architecture—getting the ESP32 to drive the TEF6686. 4.1 A first look at the TEF6686 registers and command set. Low-level control of the TEF6686 is achieved by writing registers; inside the chip there is actually a complex protocol system that must be operated in the format of 'application-layer commands.' The official driver provided by NXP is very large and not suitable for direct inclusion in the ESP32, but fortunately someone in the open-source community has reverse-engineered and organized a streamlined driver. Its core ideas are just a few: at power-on initialization you write a series of Init sequences—roughly a dozen or so commands—to configure the chip's internal modules; to select a station you write the frequency value and band to command 0x04; and to read signal strength you issue a query to command 0x22 and then read the returned RSSI value. There's a detail in the I2C communication format worth noting: when reading data, the TEF6686 requires the host to first send the command byte, wait until the chip has finished internal processing (a typical delay of 5 ms), and then initiate the read operation. If you read immediately after sending the command, chances are you'll get invalid data. I was stuck on this timing issue for quite a while at first, and adding the delay fixed it. You can use delay(5) or vTaskDelay(5/portTICK_PERIOD_MS) for the delay; the latter is recommended because it doesn't block system scheduling.
4.2 Driver code framework in the Arduino environment. The board I used for development was the ESP32 DevKitC V4 (ESP32-WROOM-32 module), with Arduino IDE 2.x as the development environment. For the driver layer I directly ported peterus's TEF6686_Radio library, which has already wrapped the Init sequences, so you only need to instantiate an object and call init() to complete chip initialization. The core code skeleton is: include Wire.h and TEF6686_Radio.h, instantiate the radio object, and in setup() call Wire.begin(), Serial.begin(115200), radio.init(), radio.setBand(FM), radio.setFrequency(106800), radio.setStereo(true), radio.setVolume(42); in loop() repeatedly call radio.getRSSI() and print it. Note that the setFrequency parameter is in units of 10 Hz, so 106.8 MHz must be written as 106800—this is one of the most common pitfalls for beginners. getRSSI returns a value in dBμV, roughly in the range of 20 to 70, with larger values indicating a stronger signal.
4.3 State-machine handling of the knob and buttons. If you handle the EC11 encoder by simple polling, the knob will lose steps as soon as you turn it a bit faster. I used a timed-interrupt approach, sampling the encoder's A/B phases with the ESP32's hardware timer hw_timer_t at a 2 ms period, identifying forward versus reverse rotation from the phase changes, and accumulating a frequency step for each detent. For the state machine I map the knob's short press, long press, and rotation to different events: rotation adjusts frequency by default, with a switchable step mode (10 kHz, FM channel spacing, or auto-search), and one detent triggers automatic station seeking; a long press enters the menu, and a short press confirms an option. This interaction logic is implemented with an enumerated state machine, with modules decoupled through an event queue, so adding features later is easy. Here's a tip I'd like to share about tuning the feel: the frequency display needs to respond 'instantly' without jumping too far, so I gave the step size dynamic acceleration—when you turn fast it automatically increases the step, and when you turn slowly it returns to a fine step. The experience is nearly identical to a real commercial unit, and this detail greatly improves the feel of use.
5. Display interface and local/network control. 5.1 Local OLED display logic. I divide the OLED display content into three layers: the main screen shows the frequency in large digits, a signal-strength bar graph, stereo/mono status, and RDS text; the secondary screen shows menu items, supporting options such as 'frequency step setting,' 'band switching,' and 'sleep timer'; the third layer is system information, such as battery level and firmware version number. The core optimization for display updates is to exploit the SSD1306's partial-refresh capability. I use the Adafruit_SSD1306 library, where display.display() refreshes the entire display memory; but if I first clear the frequency-digit region in display memory with fillRect and then redraw it, finally calling display.display() once, what actually gets refreshed is just the covered region. At 128x64 resolution this consumes very little I2C bandwidth. In testing, even with Wi-Fi tasks running in the loop, display refresh remained smooth with no noticeable stutter.
5.2 Adding Wi-Fi web remote control to the radio. Since we're using an ESP32, it would be a shame not to connect it to a network. I added a Wi-Fi control page to the firmware; any device on the local network can open a browser, enter the device's IP address, and see the current frequency, signal strength, and RDS information, and can even enter a frequency directly to switch stations remotely. This is very handy when using the radio as background music in the living room—you can use your phone as a remote without having to go up to the device. The web part uses the ESPAsyncWebServer library; the page is embedded HTML plus a little JavaScript, implementing simple WebSocket push, so when the radio's state changes it proactively pushes to the page, avoiding repeated polling. On the back end, variables such as frequency, rssi, and stereo are registered to WebSocket events through callback functions, and the front end updates DOM nodes when it receives the data. The whole process isn't complicated but scales well. This feature also happens to solve the pain point of 'not being able to check the status remotely after a firmware upgrade.' If you want to add internet radio later, you really only need to add an HTTP audio-stream decoding task to the code and output the decoded PCM data through I2S to the audio amplifier. There will be switching logic between the audio stream and the radio audio, but I'll leave that for a future expansion.
6. Antenna, reception performance, and sensitivity tuning. 6.1 Telescopic antenna matching and front-end filtering. The TEF6686's RF input is a high-impedance input; connecting a telescopic antenna a few tens of centimeters long directly will produce sound, but sensitivity won't be ideal because the antenna impedance doesn't match the chip's input impedance, so signals reflect on the transmission line and their energy isn't fully absorbed. Commercial DSP radios all include an antenna matching network internally. A simple approach is to use a 22 nH to 47 nH inductor in parallel from the RF input to ground, plus a 1 nF series capacitor to the antenna terminal, forming a simple π-type matching network. I tested several approaches: with the antenna connected directly, FM sensitivity was around 15 dBμV; after adding a 2.2 pF parallel capacitor it improved to 9 dBμV; and with the inductor matching network added as well, it could reach around 6 dBμV. To the human ear this numeric difference is the difference between 'weak stations are barely audible' and 'weak stations are clear and error-free.' The specific parameters of the matching network vary with PCB layout, so I suggest keeping a few components of different values on hand and tuning as you measure, until the background noise on weak stations is cleanest.
6.2 Automatic gain control and signal-to-noise ratio measurements. The TEF6686 has a built-in AGC circuit, but the AGC response time and target gain must be configured in software; the default configuration is fairly conservative and prone to intermodulation interference next to strong stations. In the end I set the AGC hold time to a short setting and the gain ceiling to medium, which gave the most balanced dynamic range. Measured data: a strong local station has a signal strength of about 60 dBμV, the audio-output signal-to-noise ratio under signal can reach around 68 dB, and stereo separation is about 42 dB, with no noticeable crosstalk when listening. For a weak urban station at around 25 dBμV, mono mode still lets you hear the content clearly, but stereo mode starts to produce noise. At this point the automatic mode in the firmware smoothly switches from stereo back to mono. This switching algorithm needs hysteresis near the RSSI threshold, otherwise it will flip back and forth at the boundary; a hysteresis of 3 dB works well.
6.3 Troubleshooting common interference sources. Interference sources within a portable device are subtle and layout-dependent. Here are a few types of problems I've encountered and solved for your reference: ESP32 DC-DC buck noise interference—when using the on-board 3.3 V regulator, DC-DC switching noise radiates into the FM band, showing up as a raised noise floor across the whole band; the fix is to replace the DC-DC with an LDO. Common-mode interference from the USB cable—during debugging the USB cable is connected to a computer, and noise from the computer's power-supply ground travels along the USB cable into the device; once debugging is finished and you power from battery, much of the noise disappears. OLED I2C clock radiation—the 1 MHz I2C clock and its higher harmonics may fall within the FM band; keep the I2C traces away from the RF input pin, and when that can't be avoided add a 330 Ω series resistor to slow the edge rate. These interference issues are all fairly time-consuming to track down. My suggestion is that when you get a new PCB, first do a 'bare-board test'—don't solder the OLED or encoder, connect only the necessary wiring, and use an oscilloscope to look at the noise floor of the audio-output waveform. If the bare board is already very noisy, don't expect software to fix it later; solve the hardware fundamentals first before moving on.
7. Pitfall log—a list of things to avoid for those who follow. 7.1 Problem one: intermittent I2C communication failure. This is almost something every beginner on a TEF6686 project encounters: initialization succeeds sometimes and fails others, or after working for a while you suddenly can't read the RSSI. My troubleshooting approach is this: first measure the I2C waveform—use an oscilloscope to see whether the rising edges of SDA and SCL have slowed down. If the rise time exceeds 1 μs, the typical cause is pull-up resistors that are too large or excessive bus capacitance; changing the pull-ups from 4.7 kΩ to 2.2 kΩ solved the problem. Another easily overlooked point is level conflicts on the I2C bus. The TEF6686's I2C pins support 1.8 V to 3.3 V levels and the ESP32's GPIO high output is 3.3 V, so they're theoretically compatible; but if the OLED's VDD and the TEF6686's VDD aren't from the same rail, logic levels may be inconsistent. Just make sure all I2C devices share a single 3.3 V power rail and you'll be fine.
7.2 Problem two: 'crackling' sound in the audio output. 'Crackling' and 'humming' have different causes: a 'hum' is mostly a power-supply ground-loop problem, while a 'crackle' is generally digital signals coupling into the audio path. During debugging I found that the OLED's refresh action produced a synchronized 'hiss' in the headphones, especially noticeable when displaying RDS information. Measuring the audio output with an oscilloscope indeed showed narrow-pulse interference synchronized with the display refresh. After investigation I confirmed that the I2C data line was too close to the audio trace, and the I2C edge pulses were coupling into the audio signal through parasitic capacitance. The fix: move the audio trace to the other layer of the PCB and wrap it in GND copper, and add a 100 pF low-pass capacitor to ground at the op-amp input. After the board revision, retesting showed the interference from display refresh had completely disappeared.
7.3 Problem three: FM stereo separation is inconsistent. This problem shows up as the same station sometimes having clearly separated left and right stereo channels, then suddenly switching to mono after a while, then recovering again. I initially thought it was a chip fault, but later found that when the RDS signal and the stereo pilot signal are both present, the audio DSP's automatic mode switching is too aggressive. The TEF6686 has an internal multipath decoding strategy: when signal quality degrades, it automatically switches stereo decoding to mono to improve the signal-to-noise ratio. The solution isn't to disable automatic switching but to widen the hysteresis band of the switch. In the initialization sequence there's a set of parameters that configure the stereo switching threshold; I manually adjusted the threshold from the default 25 dBμV to 30 dBμV, set the restore threshold to 28 dBμV, with a hysteresis of 3 dB. After the change, rapid switching never occurred again.
8. What else you can do—ideas for expansion. Once the whole machine is built and has been running stably for a while, you'll realize the architecture of this system is actually a 'universal radio front end,' and the radio function is just the starting point. I'm currently working on several directions of expansion: first, RDS data utilization. The TEF6686 has built-in RDS demodulation, and the firmware can already extract the PI code and station name. Later you can use PTY program-type information for automatic filtering—for example, searching only for music stations and skipping ad channels. This requires maintaining a mapping table from PI codes to program types; it's not much work but very practical. Second, adjustable bandwidth filtering. The TEF6686's DSP filter bandwidth is adjustable, ranging from 50 kHz to 200 kHz; narrow bandwidth improves the readability of weak stations, while wide bandwidth improves the sound quality of strong stations. Next I want to expose the bandwidth parameter to the user as an adjustable knob for real-time tuning of the listening experience. Third, internet radio integration. Once the ESP32 is connected to Wi-Fi it can play MP3/AAC streams, and by switching the audio source you can achieve an all-in-one 'local FM + internet radio' mode. ESP32 audio decoding usually uses a VS1053 module or the ESP-ADF framework; if you go the I2S output route, just add a switcher between the amplifier and the current radio audio. Fourth, low-power optimization. Deep sleep can already drop to 30 μA, but after RTC wake-up you can only check the time, not record on a schedule. The plan is to use the ESP32's RTC memory to store an alarm frequency, automatically wake at the set time and start FM reception, sampling the audio at the specified frequency through the ADC and saving it to an SD card—turning it into a simple broadcast recorder, suitable for scheduled recording of foreign-language news or morning programs. Finally, let me share one more takeaway from experience: after completing this project, your understanding of 'software-defined radio' will be completely different from what you get from books. The TEF6686 is essentially a highly integrated small radio SoC, and controlling it over I2C is really operating a real but invisible receiver. Once you've personally solved practical problems like power noise, I2C timing, and antenna matching, looking at the schematic of any communication system will feel far clearer than before—and that's perhaps the greatest reward of DIY-ing a device like this.