风筝
发表于: 2019-4-18 22:24:50 | 显示全部楼层

学习使用SparkFun FM Tuner和Arduino Uno开发板制作一个简单的FM收音机,以接收和显示广播信息。


在之前的文章中,我们简单介绍了一下FM收音机的基础知识,以及从头开始制作简易FM收音机所需的零件。本篇文章将主要介绍如何制作一台FM收音机,该收音机能够接收有关广播的信息,并集成到您的项目中。


我们将使用Silicon Laboratories Si4703的SparkFun分线板,以及Arduino Uno开发板和有源扬声器来制作一个简单的FM收音机,可以寻找广播电台、调节音量、保存喜爱的电台,当然还有播放音频。


Arduino Uno将通过串行通信与计算机连接,允许通过系统进行控制,并向用户反馈。此外,该系统将能够接收和显示嵌入在子载波频率中的广播公司的信息。


现在,我们来看看制作过程。


Si4703分线板焊接排针

SparkFun Si4703 FM调谐器分线板没有焊接排针,这几乎是每个SparkFun分线板的出货方式。这使您可以灵活地将Si4703分线板与您需要的任何类型的连接器结合到您的项目中。


您可以将导线直接焊接到分线板上的引脚,可以将分线板连接到另一个PCB,或者可以焊接公头或母头。在这个项目中,因为我将在面包板上组装电路,所以焊接一个公头。但是,如果您不使用面包板,则可能希望使用母头排针。

The Si4703 Breakout Board.png

Si4703分线板

how_to_build_radio_SparkFun_FM_Tuner_Breakout_Arduino_SH_MP_image2.png

将排针焊接到电路板上就可以将其插入到面包板。


连接线缆

开始搭建项目时,我们将SparkFun Si4703分线板连接到Arduino Uno和扬声器。您可以直接将所有内容连接在一起,如上一节所述,或者将电子元件组装在面包板上。


下面的接线图和表格显示了使项目运行所需的所有连接。在接线图之后,提供了有关电子设计和不同连接的更多信息。

Wiring Table for Si4703 and Arduino Uno.png

Si4703和Arduino Uno的接线表格

Circuit Diagram of Arduino and Si4703.png

Arduino UNO和Si4703之间连接的电路图。


电源

首先,我们将电源和地连接到SparkFun Si4703 FM Tuner Basic分线板。


**请注意,Si4703的工作电源是3.3V,而不是5V。


将Arduino 3.3V引脚连接到Si4703分线板的VCC引脚。然后,将Arduino其中一个GND引脚连接到Si4703的GND引脚。

Power and ground connections to the SparkFun Si4703 FM Tuner Basic Breakout.png

parkFun Si4703 FM Tuner Basic分线板的电源和地连接。


数据连接

SparkFun FM Tuner Basic Breakout和Arduino Uno开发板通过四条线进行通信。 GPIO2连接允许Arduino Uno在不同的设备模式中进行选择,如搜索/调谐和RDS功能。


在本教程中,我们将使用双线接口来控制Si4703。这两根线是SDIO和SCLK引脚,分别连接到A4和A5。最后,RST引脚用于启用和禁用Si4703。当D2设置为LOW时,Si4703被禁用,当它设置为HIGH时,Si4703退出复位模式。

SparkFun FM Tuner Basic Breakout and the Arduino Uno Data Connections.png

SparkFun FM Tuner Basic分线板和Arduino Uno的数据连接。


扬声器连接

最后两个连接是Si4703分线板和有源扬声器之间的音频连接。


本项目中,左右音频通道连接的3.5mm连接器的哪一侧无关紧要。只需将3.5毫米尾纤连接器插入FM调谐器分线板上的Lout和Rout引脚即可。

audio connections between the Si4703 breakout board and the powered speaker.png

分线板和有源扬声器之间的音频连接。


代码

组装完电子器件后,下一步是将代码上传到Arduino开发板。共有两个步骤:

1.    安装Si4703库

2.    将Si4703_test草图上传到Arduino Uno


安装库

为了更容易控制SparkFun FM Tuner Basic Breakout,以及项目代码更简洁,我们将使用具有控制Si4703功能的库。


首先下载Si4703库.zip文件夹并将其保存在计算机上的某个位置,以便稍后查找。然后,打开Arduino IDE。在Arduino IDE中,从菜单中选择Sketch> Include Library> Add .ZIP Library ....

Adding Zip Library in Arduino.png

然后,导航到存储Si4703库的位置并选择.zip文件。库安装成功后,窗口底部会显示确认信息。

Notification after the Library has been Added.png


上传代码

现在Si4703库已经安装到Arduino开发环境中,我们可以使用运行简单的FM收音机的代码对Arduino Uno进行编程。首先,下载草图并在Arduino IDE中打开它。

  1. // Arduino Uno Basic FM Radio using SparkFun Si4703 Breakout
  2. // Author:  Scott Hatfield (aka Toglefritz)

  3. /*
  4. DESCRIPTION:  
  5.   This sketch for the Arduino Uno controls a simple FM radio using an Si4703 radio
  6.   receiver. The sketch allows control of the system and feedback to the user over
  7.   serial. The system can seek radio stations, store three favorited radio stations,
  8.   adjust volume, and print RDS information.

  9. PARTS:
  10.   * Arduino Uno R3: < https://www.sparkfun.com/products/11021 >
  11.   * SparkFun FM Tuner Basic Breakout:  < https://www.sparkfun.com/products/11083 >
  12.   * Generic powered speaker

  13. HARDWARE CONNECTIONS:
  14.   * Si4703 VCC --> 3.3V
  15.   * Si4703 GND --> GND
  16.   * Si4703 SDIO --> A4
  17.   * Si4703 SCLK --> A5
  18.   * Si4703 RST --> D2
  19.   * Si4703 GPIO2 --> D3
  20.   * Si4703 ROUT --> Speaker
  21.   * Si4703 LOUT --> Speaker
  22. */

  23. #include <Si4703_Breakout.h>    // Load the SparkFun Si4703 library < https://cdn.sparkfun.com/assets/learn_tutorials/2/7/4/Si4703_Breakout.zip >
  24. #include <Wire.h>

  25. int resetPin = 2;   // The Si4703 breakout RST pin connects to the Arduino D2 pin
  26. int SDIO = A4;    // The Si4703 breakout SDIO pin connects to the Arduino A4 pin
  27. int SCLK = A5;    // The Si4703 breakout SCLK pin connects to the Arduino A5 pin

  28. // Initialize the Si4703_Breakout object
  29. Si4703_Breakout radio(resetPin, SDIO, SCLK);
  30. int channel;
  31. int volume = 5;
  32. char rdsBuffer[10];

  33. // Favorite stations
  34. int favA = 1041;    // Set your favorite stations by inputting their FM frequency (omitting the period)
  35. int favB = 931;
  36. int favC = 937;

  37. void setup()
  38. {
  39.   // The Arduino communicates with the computer via serial
  40.   Serial.begin(9600);
  41.   Serial.println("\n\nSi4703_Breakout Basic Radio");
  42.   Serial.println("\n\nControls:");  
  43.   Serial.println("a, b, c     Favourite stations");    // In the configuration above, you can set three favorite stations
  44.   Serial.println("+, -     Volume (max 15)");
  45.   Serial.println("u, d     Seek up / down");
  46.   Serial.println("r,       Print RDS Data (15 sec timeout)");
  47.   Serial.println("\n\n");

  48.   radio.powerOn();    // Enable the Si4703
  49.   radio.setVolume(5);    // Set the starting volume to 5 (out of 15)
  50. }

  51. void loop()
  52. {
  53.   // Listen for serial commands
  54.   if (Serial.available())
  55.   {
  56.     char ch = Serial.read();

  57.     // u = seek up
  58.     if (ch == 'u')
  59.     {
  60.       channel = radio.seekUp();
  61.       displayInfo();
  62.     }

  63.     // d = seek down
  64.     else if (ch == 'd')
  65.     {
  66.       channel = radio.seekDown();
  67.       displayInfo();
  68.     }

  69.     // + = increase volume
  70.     else if (ch == '+')
  71.     {
  72.       volume ++;
  73.       if (volume == 16) volume = 15;
  74.       radio.setVolume(volume);
  75.       displayInfo();
  76.     }

  77.      // - = decrease volume
  78.     else if (ch == '-')
  79.     {
  80.       volume --;
  81.       if (volume < 0) volume = 0;
  82.       radio.setVolume(volume);
  83.       displayInfo();
  84.     }

  85.     // a = favorite station a
  86.     else if (ch == 'a')
  87.     {
  88.       channel = favA;
  89.       radio.setChannel(channel);
  90.       displayInfo();
  91.     }

  92.     // b = favorite station b
  93.     else if (ch == 'b')
  94.     {
  95.       channel = favB;
  96.       radio.setChannel(channel);
  97.       displayInfo();
  98.     }

  99.     // c = favorite station c
  100.     else if (ch == 'c')
  101.     {
  102.       channel = favC;
  103.       radio.setChannel(channel);
  104.       displayInfo();
  105.     }

  106.     // r = print RDS information
  107.     else if (ch == 'r')
  108.     {
  109.       Serial.println("RDS listening...");
  110.       radio.readRDS(rdsBuffer, 15000);
  111.       Serial.print("RDS info: ");
  112.       Serial.println(rdsBuffer);      
  113.     }
  114.   }
  115. }

  116. // The displayInfo function prints the current channel and volume over serial
  117. void displayInfo()
  118. {
  119.    Serial.print("Channel:");
  120.    Serial.print(channel);
  121.    Serial.print(" Volume:");
  122.    Serial.println(volume);
  123. }
复制代码

代码可以像任何其他草图一样通过USB上传到Arduino Uno开发板。

Uploading the code to the Arduino Uno over USB.png

代码将使用串行通信连接您的计算机。因此,在代码成功上传到Arduino Uno之后,我们需要打开并设置串行监视器。您将在Tools > Serial Monitor中找到串口监视器工具。


Opening the Serial Monitor.png

打开串口监视器后,请确保使用窗口右下角的下拉列表将波特率设置为9600。当草图开始运行时,您应该看到来自Arduino的消息,其中包含控制无线电的说明。

the baud rate is set to 9600 using the drop-down in the lower-right corner of th.png



控制收音机

Arduino Uno通过串口与计算机通信,以便接收命令并发送反馈。当草图首次开始运行时,Arduino将使用用于控制系统的各种命令向串行监视器打印指令。

The Arduino Uno communicates with the computer over serial.png

Si4703 Breakout Basic Radio Controls.png


连接可选天线

如果您发现系统很难接收无线电台,您可以通过将天线连接到分线板上的ANT引脚来提高Si4703的性能。 如果您希望收听的电台在您所在地区有强烈信号,则天线不是绝对必要的。 但是,天线对于拾取更远的信号非常有用。


天线由单根导线制成。 电线可以焊接到FM Tuner Basic Breakout上的ANT引脚上,也可以用鳄鱼夹固定。 连接天线后,您应该能够更轻松地接收无线电信号。

跳转到指定楼层
林雨天心
发表于: 2019-12-15 18:42:43 | 显示全部楼层

大佬,这个是不是缺少一个调台的教程。是外置矩阵键盘还是用电脑输指令?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 700 | 回复: 1480



手机版|

GMT+8, 2024-4-18 23:00 , Processed in 0.154667 second(s), 6 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表