Fireduino 开源创意平台 立即购买

拥有双核Cortex-M3处理器,集成高质量音频Codec和WiFi模组,拥有良好的IOT扩展性能,完美兼容Arduino IDE和Arduino标准接口,并支持FireBlock图形化编程软件,是一款首选的编程启蒙教学平台,更是一款开源的创意原型平台。

Fireduino Audio DLNA播放器

更新时间:2017-08-08 阅读:1775

Fireduino Audio

Fireduino 内部集成了HIFI级高质量的音频解码器、专业的硬件MP3解码加速器、硬件低损耗音频解码加速器和丰富的外设,支持WI-FI协议,支持24bits 192k Hz 采样率、低损耗、低功耗的音频解码。
Fireduino 支持播放在SD卡以及网络上的音频文件,解码格式支持APE/FLAC/WAV/MP3/WMA/AAC/OGG;

Fireduino Audio 库

Fireduino在音频解码方面非常优秀,使用Audio库中的API可以让用户更简单易用的进行音频开发。Fireduino提供了音频接口如下图:

Earphone jack.jpg

FireDuino audio.jpg

Fireduino Audio 播放通过DLNA推送来的音乐

本案例演示如何在Fireduino 播放通过DLNA协议传输过来的音乐文件。

硬件要求

1.Fireduino board
2.TF Card
3.已经安装了支持DLNA音乐播放APP(网易云音乐)的智能手机

代码

开始之前

使用Audio、WiFi与TF Card 之前,首先得包含Audio、WiFi与TF库头文件。确认WiFi连接成功,开始播放通过DLNA推送过来的音乐。

void setup() {
	Serial.begin(115200);
	Serial.print("\r\narduino setup ...\r\n");
 
	if(!SD.begin())
	{
		Serial.println("sd init err\r\n");
		while(1);
	}
 
	// check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
 
  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }
 
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
 
    // wait 10 seconds for connection:
    // delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
 
 
	Audio.begin(AUDIO_DLNA);
 
}

loop()

定时打印提示信息。

void loop() {
	Serial.println("loop");
	delay(2000);
}

手机端推送音乐

按照以下步骤完成音乐推送。

1 . 打开播放器设置
2 . 连接DLNA设备
3 . 选择DLNA设备
4 . 播放DLNA音乐

示例程序 -- 播放DLNA推送音乐

Code

#include <Arduino.h>
#include "TF.h"
#include "Audio.h"
#include <WiFi.h>
 
char ssid[] = "nanod";     //  your network SSID (name)
char pass[] = "12345678";  // your network password
int status = WL_IDLE_STATUS;
 
 
void printWifiStatus();
void setup() {
	Serial.begin(115200);
	Serial.print("\r\narduino setup ...\r\n");
 
	if(!SD.begin())
	{
		Serial.println("sd init err\r\n");
		while(1);
	}
 
	// check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
 
  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }
 
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
 
    // wait 10 seconds for connection:
    // delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
 
 
	Audio.begin(AUDIO_DLNA);
 
}
 
void loop() {
	Serial.println("loop");
	delay(2000);
 
}
 
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
 
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
 
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

串口打印信息

如下:

FireDuino DLNA audio debug.png