top of page
  • 2020年5月7日
  • 讀畢需時 2 分鐘

The reference:

by DFRobot


We consider the mp3 player factory's official document and using it to drive the player in the right way. We, however, change part of the original code for better support and checking the state of player for checking the error.

Especially, we solved a significant problem of decrease the noise of the sound output, via the support of a web mate.



#include "Arduino.h" #include "SoftwareSerial.h" #include "DFRobotDFPlayerMini.h" SoftwareSerial mySoftwareSerial(10, 11); // RX, TX DFRobotDFPlayerMini myDFPlayer; void printDetail(uint8_t type, int value); void setup() { mySoftwareSerial.begin(9600); Serial.begin(115200); Serial.println(); Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3. Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); while(true); } Serial.println(F("DFPlayer Mini online.")); myDFPlayer.setTimeOut(500); //Set serial communictaion time out 500ms //----Set device we use SD as default---- // myDFPlayer.outputDevice(DFPLAYER_DEVICE_U_DISK); myDFPlayer.outputDevice(DFPLAYER_DEVICE_SD); // myDFPlayer.outputDevice(DFPLAYER_DEVICE_AUX); // myDFPlayer.outputDevice(DFPLAYER_DEVICE_SLEEP); // myDFPlayer.outputDevice(DFPLAYER_DEVICE_FLASH); //----Mp3 control---- // myDFPlayer.sleep(); //sleep // myDFPlayer.reset(); //Reset the module // myDFPlayer.enableDAC(); //Enable On-chip DAC // myDFPlayer.disableDAC(); //Disable On-chip DAC // myDFPlayer.outputSetting(true, 15); //output setting, enable the output and set the gain to 15 //----Mp3 play---- myDFPlayer.next(); //Play next mp3 delay(1000); myDFPlayer.previous(); //Play previous mp3 delay(1000); myDFPlayer.play(1); //Play the first mp3 delay(1000); myDFPlayer.loop(1); //Loop the first mp3 delay(1000); myDFPlayer.pause(); //pause the mp3 delay(1000); myDFPlayer.start(); //start the mp3 from the pause delay(1000); myDFPlayer.playFolder(15, 4); //play specific mp3 in SD:/15/004.mp3; Folder Name(1~99); File Name(1~255) delay(1000); myDFPlayer.enableLoopAll(); //loop all mp3 files. delay(1000); myDFPlayer.disableLoopAll(); //stop loop all mp3 files. delay(1000); myDFPlayer.playMp3Folder(4); //play specific mp3 in SD:/MP3/0004.mp3; File Name(0~65535) delay(1000); myDFPlayer.advertise(3); //advertise specific mp3 in SD:/ADVERT/0003.mp3; File Name(0~65535) delay(1000); myDFPlayer.stopAdvertise(); //stop advertise delay(1000); myDFPlayer.playLargeFolder(2, 999); //play specific mp3 in SD:/02/004.mp3; Folder Name(1~10); File Name(1~1000) delay(1000); myDFPlayer.loopFolder(5); //loop all mp3 files in folder SD:/05. delay(1000); myDFPlayer.randomAll(); //Random play all the mp3. delay(1000); myDFPlayer.enableLoop(); //enable loop. delay(1000); myDFPlayer.disableLoop(); //disable loop. delay(1000);

Solving the player mini mp3 noise




Our OWN type:

if (digitalRead(Button)==LOW) { delay(10); if (mp3.available()) { printDetail(mp3.readType(), mp3.read()); //Print the detail message from DFPlayer to handle different errors and states. } } else if (digitalRead(Button)==HIGH) { delay(10); if ( ds18b20.getTempC() >= 32 ) { for (int index = 0; index < 1; index++) { //music play mp3.play(2); if (mp3.available()) { printDetail(mp3.readType(), mp3.read()); //Print the detail message from DFPlayer to handle different errors and states. } } for (int index = 0; index < 1; index++) {

mp3.pause(); if (mp3.available()) { printDetail(mp3.readType(), mp3.read()); //Print the detail message from DFPlayer to handle different errors and states. } while (!(32>ds18b20.getTempC())) {} }//redLED

  • 2020年5月4日
  • 讀畢需時 2 分鐘

已更新:2020年5月7日



For a higher speed work on our project, we choose a visual coding tool, Mind+, to support our work. Though all codes are typed by myself, mind+ gives us extremely good support on various libraries of different modules, which saved our time on searching the correct codes of modules in a mess.

Moreover, mind+ also helps me on learning the different code via a visual language instead of an abstract word description.

And I need to thanks all developers around the world. They give me a lot of support on coding on the project.

The full codes are presented below. And I add as more as possible marks on codes for support more people using it for their projects.


/*! * MindPlus * nano * */ #include <DFRobot_PlayerMini.h> #include <DFRobot_LedControl.h> #include <SoftwareSerial.h> #include <DFRobot_DS18B20.h> // Define LedPins #define greenLED 6 #define yellowLED 7 #define redLED 8 // Common Data const uint8_t maxBitmap[][8] = { {B01111111,B01111111,B01100011,B01111111,B01111111,B01100000,B01100000,B01100000}, {B01100000,B01100000,B01100000,B01100000,B01100000,B01100000,B01111110,B01111110}, {B01111110,B01111110,B00001100,B00001000,B00011000,B00110000,B01111110,B01111110}, {B00011100,B00011100,B00011100,B00001000,B00111011,B00001011,B01111111,B01000001}, {B00000000,B00110000,B01111001,B11111011,B10010011,B11000001,B01100011,B00110110}, {B00100000,B01000000,B10101000,B00010001,B00100110,B00001100,B00001010,B00011001}, {B00000000,B00011000,B01011010,B01011010,B01011010,B00111100,B01100110,B11000011}, {B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000} }; // Create Objects DFRobot_LedControl max7219; SoftwareSerial softSerialmp3(10, 11); DFRobot_PlayerMini mp3; DFRobot_DS18B20 ds18b20; int Button = 2; // Main Program void setup() { Serial.begin(9600); mp3.begin(&softSerialmp3); max7219.begin(3, 5, 4); max7219.show(maxBitmap[0]); pinMode(Button, INPUT); ds18b20.begin(12); pinMode(greenLED, OUTPUT); pinMode(yellowLED, OUTPUT); pinMode(redLED, OUTPUT); } void loop() { Serial.print(" degrees C - "); Serial.println(ds18b20.getTempC()); Serial.print(" ButtonStatue - "); Serial.println(digitalRead(Button)); if (digitalRead(Button)==LOW) { delay(10); max7219.show(maxBitmap[7]); Serial.print(" Statue - "); Serial.println("ALL OFF"); } else if (digitalRead(Button)==HIGH) { delay(10); if ( ds18b20.getTempC() >= 32 ) { //temperatureDetect-R digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(redLED, HIGH); Serial.print(" Statue - "); Serial.println("WARM"); Serial.print(" redLED - "); Serial.println("ON"); for (int index = 0; index < 1; index++) { //music play mp3.play(1); } for (int index = 0; index < 3; index++) { //led animation max7219.show(maxBitmap[0]); delay(500); max7219.show(maxBitmap[1]); delay(500); max7219.show(maxBitmap[2]); delay(500); max7219.show(maxBitmap[3]); delay(500); max7219.show(maxBitmap[4]); delay(500); max7219.show(maxBitmap[5]); delay(500); max7219.show(maxBitmap[6]); delay(500); } delay(1000); digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(redLED, LOW); Serial.print(" redLED - "); Serial.println("OFF"); max7219.show(maxBitmap[7]); mp3.pause(); while (!(32>ds18b20.getTempC())) {} }//redLED else if ( 32 > ds18b20.getTempC() && ds18b20.getTempC()>=30) { //temperatureDetect-Y digitalWrite(greenLED, LOW); digitalWrite(yellowLED, HIGH); digitalWrite(redLED, LOW); Serial.print(" Statue - "); Serial.println("Confort"); Serial.print(" yellowLED - "); Serial.println("ON"); for (int index = 0; index < 1; index++) { //music play mp3.play(2); } for (int index = 0; index < 3; index++) { //led animation max7219.show(maxBitmap[0]); delay(500); max7219.show(maxBitmap[1]); delay(500); max7219.show(maxBitmap[2]); delay(500); max7219.show(maxBitmap[3]); delay(500); max7219.show(maxBitmap[4]); delay(500); max7219.show(maxBitmap[5]); delay(500); max7219.show(maxBitmap[6]); delay(500); } delay(1000); digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(redLED, LOW); Serial.print(" yellowLED - "); Serial.println("OFF"); max7219.show(maxBitmap[7]); mp3.pause(); while (!((ds18b20.getTempC()>=32) || (30>ds18b20.getTempC()))) {} }//yellowLED else { //temperatureDetect-G digitalWrite(greenLED, HIGH); digitalWrite(yellowLED, LOW); digitalWrite(redLED, LOW); Serial.print(" Statue - "); Serial.println("Cold"); Serial.print(" redLED - "); Serial.println("ON"); for (int index = 0; index < 1; index++) { //music play mp3.play(3); } for (int index = 0; index < 3; index++) { //led animation max7219.show(maxBitmap[0]); delay(500); max7219.show(maxBitmap[1]); delay(500); max7219.show(maxBitmap[2]); delay(500); max7219.show(maxBitmap[3]); delay(500); max7219.show(maxBitmap[4]); delay(500); max7219.show(maxBitmap[5]); delay(500); max7219.show(maxBitmap[6]); delay(500); } delay(1000); digitalWrite(greenLED, LOW); digitalWrite(yellowLED, LOW); digitalWrite(redLED, LOW); Serial.print(" greenLED - "); Serial.println("OFF"); max7219.show(maxBitmap[7]); mp3.pause(); while (!(ds18b20.getTempC()>=30)) {} }//greenLED }//PressDown delay(500); }//WholeLoop


© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page