My brother is a toy maker and I'm building a circuit to animate a prototype toy for his business.
One of the component features of this toy is it will play an mp3 soundtrack while the device rotates on a base and is lit up from the interior. I have the motor and LED system working, but I'm having an issue with the mp3 portion of the circuit.
The mp3 player I bought for this project is: HiLetgo 2pcs mp3 Player Mini MP3 Player Audio Voice Module TF Card U Disk Board for DFPlayer Audio Voice Music Module.
I think the mp3 module I bought fits this post:
https://forum.arduino.cc/t/df-player-warning/952842
https://www.amazon.com/gp/product/B01D1D0E7Q/ref=ox_sc_saved_title_6?smid=A30QSGOJR8LMXA&psc=1
I can get the mp3 module to play, skip tracks, change volume, etc., by manually connecting the IO1 and IO2 pins to ground, but I can't seem to program it to perform these actions via the sketch.
For now, this is the basic order of operations:
Turn the power on and the sketch should automatically start playing a predetermined mp3 file, the toy begins to rotate on its base, and the LED lights up the interior of the toy.
Press the button once, toy continues to turn and LED remains lit, but mp3 changes tracks to a second predetermined track.
Press the button a second time, the toy continues to turn and the LED remains lit, but the mp3 changes tracks to a third predetermined track.
Press the button a fourth time, and the toy stops turning, the LEDs turn off, and the mp3 plays the "shut down" track.
I suppose this order of operations isn't all that important, as I can program it to do what I want once I understand how to get the mp3 to start playing.
I've learned that this particular mp3 player is one that requires a custom library, but I can't seem to find the library I need online, so I guess my question is a two-parter - can you tell me where I can find this library? Can I make this work using the libraries I included in the sketch?
Please see the sketch below.
Thank you in advance for any help you can offer.
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "mp3tf16p.h"
//#include "debounce.h"
//Named constants for the project.
static const uint8_t PIN_MP3_TX = 2; //Pin number for MP3 Transmit.
static const uint8_t PIN_MP3_RX = 3; //Pin number for MP3 Receive.
const int mp3DownPin = 5; //Pin number for MP3 "Previous Track" & "Volume Down." Short press for previous track; long press for volume down.
const int mp3UpPin = 6; //Pin number for MP3 "Next Track" & "Volume Up." Short press for next track; long press for volume up.
const int ledPin = 7; //Pin number for Qi-powered LED module.
const int motorPin = 8; //Pin number for motor.
const int buttonPin = 12; //Pin number for selection switch.
int buttonState;
int lastButtonState = LOW;
int ledState = LOW;
int motorState = LOW;
int mp3DownState = HIGH;
int mp3UpState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
//DFRobotDFPlayerMini myDFPlayer;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT); //Initialize the "Button" pin as an input.
pinMode(mp3DownPin, OUTPUT); //Initialize the "MP3 Down" pin as an output.
pinMode(mp3UpPin, OUTPUT); //Initialize the "MP3 Up" pin as an output.
pinMode(ledPin, OUTPUT); //Initialize the "LED" pin as an output.
pinMode(motorPin, OUTPUT); //Initialize the "Motor" pin as an output.
digitalWrite(mp3DownPin, mp3DownState);
digitalWrite(mp3UpPin, mp3UpState);
digitalWrite(ledPin, ledState);
digitalWrite(motorPin, motorState);
}
void loop() {
// put your main code here, to run repeatedly:
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
ledState = !ledState;
motorState = !motorState;
mp3DownState = !mp3DownState;
}
}
}
digitalWrite(ledPin, ledState);
digitalWrite(motorPin, motorState);
//myDFPlayer.play(1);
lastButtonState = reading;
}