Musical jewellery case

How feasible would it be to make the following please. A case that when opened would play a random choice of music previously stored on a USB stick or mini SD card. Is there an Arduino add-on that can do that?

Dfrobot dfPlayer

As stated earlier, you can use the DFRobot DF Player. With the DF Player Pro, you won't even need the arduino (probably) since you can configure it over a serial port to play tracks randomly.

Thanks both, studying that and looks very promising.

But I assume that doesn’t imply a permanent PC connection?

What I have in mind is populating a USB or SD card with a number (50?) of short (20s?) musical pieces. The battery powered circuit would play one each time the lid was opened. Next time it would play another randomly selected track.

Inspired by desire to avoid yet another ‘earrrings and necklace’ Christmas present for my wife.
:slightly_smiling_face:

I’m still on the lower slopes of the Arduino learning curve so to accelerate the project does anyone know of something I can plagiarise please?

Meanwhile duly ordered.

Terry

Correct, you can disconnect the PC after setting it up. I just built something similar for a client although it only played a single track. Some of the settings of the DF Player can be changed through the serial port and will persist after power off. Unfortunately, not all of them are so you'll have to check which ones can be saved. I know that you can set volume and play mode (single track, all tracks, etc.,) and they will be saved to persistent memory.

This is the one I used: Fermion: DFPlayer Pro - A Mini MP3 Player for Arduino - DFRobot

Thanks. I suspect that getting a random track might prove over ambitious. I’d be happy enough to achieve successive tracks.

My order was for the same product.

Terry

If you look at the product wiki, Playmode 4 is play random song. This can be set over the serial port, and I'm pretty sure it will "remember" it. Otherwise you'll need to control it with an arduino.

One of the disappointments with this product (actually, the only one I had!) is that only certain settings are persistent. If all the settings would remain in memory, then the product would be a lot more useful, especially at such a low price point.

Thanks, looking forward to its arrival, when I'll switch my current Arduino project work onto experimenting with it.

Module arrived yesterday. Could you please tell me where to find the details you mention? Does it also include an example Arduino sketch? And what USB cable is needed for that unusual socket?

I found the ‘wiki page but it’s sparse on practical info about how to connect it etc!
E.g “By using a USB cable, you can easily copy your favorite songs into this module .” Sure ... once you know what cable and what software!

If you plug it into your PC, it shows up as a USB drive and you can copy the songs over.
It's a USB type C socket.

Thank you. I’d passed over that type, as all described them as ‘charging cables’ , which I mistakenly assumed implied they didn’t handle data.

Duly ordered one.

Did you have more success than me in searching for a detailed explanation about using it? With 5V applied and a couple of speakers, it outputs a spoken recording of the word ‘music’ repeatedly. I’ll soon find out when I get the cable, but am I right in assuming that when several music files have been copied across, they will play in sequence? Presumably the Key and/or Play terminals have a role in this?

Thanks for your patient help.

The wiki is all I know of, refer to the "AT Commands" near the bottom for the serial commands to configure it. You can disable that "Music" thing. It bugged me because my client wanted to be able to just play a single track with a button press. The command to turn it off is called "Prompt disable" or something like that. Once you send that command over the serial port (you'll need a USB to TTL serial cable to talk to the board if you are not using an arduino), the prompt is disabled permanently.

Yes, I think the default is to play each track in order and repeat indefinitely when you press the Play button.

Glad I could help. It's a pretty fun device to play with!

Can’t say I’ve reached the ‘fun’ stage yet! Still at the frustration end of the learning curve. Main problem, which currently looks like a show-stopper, is the annoyingly erratic playback.

With five roughly 3 second MP3 files for my initial tests, on module power-up (or UNO sketch upload/reset), the first batch of tracks played should be 1, 2, 3, 4, 5. Instead they seem unpredictable. The first four to eight tracks vary each time, before the correct sequence begins.

—————
EDIT
One day later and I’ve made good progress. I can play those five test tracks in a ‘random’ order. However, the fixed set (4,2,3,5,1) play repeatedly. Unlike the tracks played by my UNO sketch, which continued to remain acceptably random for as long as it ran.

But the intended purpose is playing a little music when triggered, from say 50-100 files, with a high probability of it being different each time. So my tentative conclusion is that it would need support from the previously programmed 328.

BTW I was pleased to find that the three file types I tested (MP3, WAV and OGG) all played OK.

As a non-programmer and a relative Arduino novice that's probably a piece of cake to you, but I'm still struggling!

Could you (anyone!) possibly show me one example sketch to get me started please?
I assume these initial few lines from the wiki are correct:

#include <DFRobot_DF1201S.h>
#include <SoftwareSerial.h>

SoftwareSerial DF1201SSerial(2, 3);  //RX  TX

DFRobot_DF1201S DF1201S;
void setup(void)
{
  Serial.begin(115200);
  DF1201SSerial.begin(115200);
  while (!DF1201S.begin(DF1201SSerial))
  {
    Serial.println("Init failed, please check the wire connection!");
    delay(1000);
  }
}

I have several files loaded and playing in the module. What would I add to that code to be able to type 'AT commands' and get them applied? And if I just type "AT+VOL=10" (with the quotes) into the text box of the serial monitor and click Send, should that immediately reduce the volume?

BTW, I posted to their Forum four days ago and to Reddit|Arduino later, but no replies so far.

Doing it in code (properly) is complex. The approach I took was to use a terminal program (I think I used TeraTerm) and connect to the dfplayer's Tx & Rx lines using a USB to serial converter then I manually entered the AT command just as they're shown.

I couldn't get it to work with the Arduino serial monitor (that's why I used TeraTerm). The board needs both a Carriage Return and Line Feed after each command and I think the arduino serial monitor only sends one of those two. But yes, if you enter the commands as you describe, the response would be to change the volume.

Also, there is a library that's supposed to make this much easier. In my case I ended up not needing an arduino at all, so I never looked into it.

Thanks, at least it’s slightly reassuring that I’m not alone in finding arduino control of this so impenetrable. There seems no consistency to it. I can change the volume, and whether it plays all tracks in succession or randomly (the latter requiring the arduino code to remain running), but that’s about all. Attempts to

  • play a specific file
  • play next or previous files
  • fast forward
    have defeated me.
    Using your alternative approach, did you succeed in reliably controlling those functions?

Can you explain how it works at all with that While blocking all after the first loop? In fact I don’t see why the code cannot therefore all be placed in setup?

I don’t want to embark on additional hw or sw so I’ll persist for a while, DFRobot’s forum on the topic has been useless. I’ve had a reply from tech support to my emails basically saying they have no other arduino code other than play.ino.

Unfortunately it seems that there are very few using this module, at least with arduino!

OK, but my use case was a very simple one: play a single file at a fixed volume when the user presses a button.

Literally all I did was set the Prompt command to disable that annoying "Music" reminder at power up and set the volume. Having done that (manually, over the serial port using TeraTerm), it saved the result of those commands so I don't need to do it again. Since I only loaded a single file, pressing Play would only play that file. I think it defaults to auto-repeat.

explain how it works at all with that While blocking all after the first loop

Once the call to Begin succeeds, it breaks out of the loop.

This code is using their library. If you're using an arduino and the DfPlayer library, you should not need to send AT commands. I only mentioned them as a way to experiment with the board manually.

Since I haven't used their library, I can't comment on how well it works.

My understanding (I don't use it that much) is that it can be configured to send both.