当前位置:网站首页>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
边栏推荐
猜你喜欢
Kconfig Kbuild
Mysql database interview questions
RT thread API reference manual
Vert. x: A simple login access demo (simple use of router)
Principle and implementation of MySQL master-slave replication
Missing value filling in data analysis (focus on multiple interpolation method, miseforest)
Several declarations about pointers [C language]
B tree and b+ tree of MySQL index implementation
MongoDB
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
随机推荐
RT thread API reference manual
Word typesetting (subtotal)
物联网系统框架学习
AMBA、AHB、APB、AXI的理解
STM32 how to locate the code segment that causes hard fault
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries
Rough analysis of map file
The first simple case of GNN: Cora classification
Embedded startup process
2019 Tencent summer intern formal written examination
uCOS-III 的特点、任务状态、启动
列表的使用
FTP file upload file implementation, regularly scan folders to upload files in the specified format to the server, C language to realize FTP file upload details and code case implementation
Détails du Protocole Internet
Kconfig Kbuild
锂电池基础知识
mysql实现读写分离
arduino获取数组的长度
Some concepts often asked in database interview
Basic knowledge of lithium battery