当前位置:网站首页>Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
Mp3mini playback module Arduino < dfrobotdfplayermini H> function explanation
2022-07-06 12:04:00 【A geek is as deep as the sea】
Intended to DFRobotDFPlayerMini.h The common functions in the library are analyzed
The purpose of this paper is to analyze the serial port function of serial port communication , Do not analyze and use the hardware .
About the use of hardware IO mouth Make another analysis when you have time .
Use this library , The beginning is different
#include "DFRobotDFPlayerMini.h"
DFRobotDFPlayerMini myDFPlayer; // Example object name
MP3mini The module uses serial port communication , I use virtual serial port here
#include "DFRobotDFPlayerMini.h"
#include <SoftwareSerial.h>
#include <arduino.h>
DFRobotDFPlayerMini myDFPlayer; // Example object name
SoftwareSerial BTserial(12, 13); // establish SoftwareSerial object ,RX Pin 2, TX Pin 3
steup() Function to initialize
BTserial.begin(9600);
myDFPlayer.begin(BTserial);
First, simply test the communication
The wiring is as follows
TF Lieutenant general card MP3 The file is in the root directory MP3 The file is named 0003.mp3
/* 【Arduino】66 A series of sensor module experiments (85) Experiment 85 : Open source Mini MP3 Player TF Card player module (YX5200-24SS) One of the procedures , Loop Playback TF Carnet 0003.MP3(MP3 In the folder ), The volume 20 Arduino-------dfplayer 5V-------------VCC GND-----------GND D2-----------TXD D3-----------RXD */
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(2, 3);
DFRobotDFPlayerMini myDFPlayer;
void setup()
{
mySoftwareSerial.begin(9600);
myDFPlayer.begin(mySoftwareSerial);
myDFPlayer.volume(20); // The volume is set to 20
myDFPlayer.loop(3); // Loop Playback TF In the card 0003.mp3 file
}
void loop()
{
}
Next, we will explain the library functions one by one according to the order in the technical manual
Suppose we have instantiated a MP3mini Object of module
#include "DFRobotDFPlayerMini.h"
SoftwareSerial mySoftwareSerial(2, 3);
DFRobotDFPlayerMini myDFPlayer; // Example object name
void setup() {
mySoftwareSerial.begin(9600);
myDFPlayer.begin(mySoftwareSerial);
}
No return value
myDFPlayer.next() // Next song
myDFPlayer.previous() // Last song
myDFPlayer.play(3) // Specify track (NUM) 1-2999 Parameters are added int Type parameter
myDFPlayer.volumeUp() // The volume +
myDFPlayer.volumeDown() // The volume -
myDFPlayer.volume(20) // Specify the volume 0-30
myDFPlayer.EQ(0) // Appoint EQ 0/1/2/3/4/5 Parameter function Normal/Pop/Rock/Jazz/Classic/Bass ( This one hasn't been used , I'll explain it in detail when I know how to use it )
myDFPlayer.loop(3) // Single loop specifies the track to play 0-2999
myDFPlayer.outputDevice(2)// Specify playback settings 1/2/3/4/5 Parameter function U/SD/AUX/SLEEP/FLASH
myDFPlayer.sleep() // Go to sleep -- low power consumption
myDFPlayer.reset() // Module reset
myDFPlayer.start() // Play
myDFPlayer.pause() // Pause
myDFPlayer.playFolder(1,1) // Specify a folder to play 1-10( You need to make your own settings ) The front is folder , Followed by the file name in the folder
About the specified file plus playback , Appoint MP3 file . This place needs to be explained in detail , At that time, I fell into a big misunderstanding when debugging for the first time . After doing this, I found that the name of the folder was wrong .
1、 The name of the folder , Two digits are two digits such as 01, 02···· wait
2、 The folder should be placed in the root directory of the file .
3、 Some said they would put it in one mp3 In the folder of , After my measurement , There's no need . Of course, mine TF There are only files for playback in the card , Nothing else . If your TF There are other folders in the card , That may not be clear .
The naming method is as follows
The first three digits of the file are numbers .
Such as :
such ,playFolder Function can accurately find the specified file in the specified price folder
Folder name (1 ~ 99); file name (1 ~ 255)
such as , We want to play 02 The... In the folder 3 individual MP3
That's how we can write
myDFPlayer.playFolder(2,3)
Continue function interpretation
myDFPlayer.outputSetting(1,2) // Sound reinforcement settings ( nothing ) Parameters 1:bool type [DH=1: Open and amplify ] Parameters 2:uint8_t type [DL: Set the gain 0-31]
myDFPlayer.enableLoopAll() // Loop it all
myDFPlayer.disableLoopAll() // Stop looping
myDFPlayer.playMp3Folder(1) // Appoint MP3 Folder tracks 0--9999
myDFPlayer.advertise(1) // Insert ads 0--9999
myDFPlayer.playLargeFolder(1,2) // Usage and playFolder equally , This supports more
myDFPlayer.stopAdvertise() // Stop broadcasting , Play background
myDFPlayer.stop() // Stop playing
myDFPlayer.loopFolder(2) // Specify a folder to cycle through The parameter is the name in the specified folder
myDFPlayer.randomAll() // Random broadcast
myDFPlayer.enableLoop() // Loop playback is off
myDFPlayer.disableLoop() // Cycle play on
myDFPlayer.enableDAC() // close DAC
myDFPlayer.disableDAC() // Turn on DAC
Query type function , There is a return value , All return to int Data of type
myDFPlayer.readState() // Query current status
myDFPlayer.readVolume() // Query the current volume
myDFPlayer.readEQ() // Query the current EQ
myDFPlayer.readFileCounts(DFPLAYER_DEVICE_SD) // Number of query files
// DFPLAYER_DEVICE_U_DISK : Inquire about UDISK Total number of files
// DFPLAYER_DEVICE_SD : Inquire about TF Total number of files on the card
// DFPLAYER_DEVICE_FLASH : Inquire about FLASH Total number of files
myDFPlayer.readCurrentFileNumber(DFPLAYER_DEVICE_SD) // Query the current track
// DFPLAYER_DEVICE_U_DISK : Inquire about UDISK Your current track
// DFPLAYER_DEVICE_SD : Inquire about TF Current track of the card
// DFPLAYER_DEVICE_FLASH : Inquire about FLASH Your current track
myDFPlayer.readFileCountsInFolder(2) // Query the total number of files in the specified folder
myDFPlayer.readFolderCounts() // Query the total number of files
above , It's what I sorted DFRobotDFPlayerMini.h Library function sorting
边栏推荐
- Implementation scheme of distributed transaction
- Inline detailed explanation [C language]
- 機器學習--線性回歸(sklearn)
- 数据库面试常问的一些概念
- Vert. x: A simple TCP client and server demo
- C language, log print file name, function name, line number, date and time
- Hutool中那些常用的工具类和方法
- Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
- Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
- TypeScript
猜你喜欢
Unit test - unittest framework
Linux Yum install MySQL
MySQL数据库面试题
MySQL realizes read-write separation
FTP文件上传文件实现,定时扫描文件夹上传指定格式文件文件到服务器,C语言实现FTP文件上传详解及代码案例实现
MySQL主从复制的原理以及实现
【ESP32学习-2】esp32地址映射
Come and walk into the JVM
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)
IOT system framework learning
随机推荐
[template] KMP string matching
. elf . map . list . Hex file
Yarn installation and use
Matlab learning and actual combat notes
C语言回调函数【C语言】
AMBA、AHB、APB、AXI的理解
Detailed explanation of 5g working principle (explanation & illustration)
ESP学习问题记录
Small L's test paper
Implementation scheme of distributed transaction
2019 Tencent summer intern formal written examination
互聯網協議詳解
Machine learning -- decision tree (sklearn)
RT thread API reference manual
MongoDB
MySQL主从复制的原理以及实现
Redis面试题
PyTorch四种常用优化器测试
Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
A possible cause and solution of "stuck" main thread of RT thread