Meet the culprit, the WTV020M01 module :
(Yes, one pin broke during transport).
This thing is a "MP3 audio player SD card module". That's for the title. Now a few teeny tiny details :
- By "MP3", it means that it supports 'next', 'prev', 'stop' and 'play' buttons like classic MP3 players, NOT that it is able to read MP3 files. Really. It does not support the mp3 format.
- By "SD card", it means that it only works with Sandisk Micro SD card of 1 or 2 GB. According to reviews on the Internet, you have to try dozens of cards to find a compatible one.
- By "audio player", it means that somebody on the Internet says he knows someone who got it to read a .wav file. But nobody can reproduce that. Instead, you have to use the obscure .ad4 file format
- The datasheet is written by a Markov chain. It looks like a datasheet, it has the structure of a datasheet, some words seems to make sense, but in the end, it is just pure randomness.
Caveat emptor : do not buy this thing ;-)
Ok, maybe it's just me. After all, it's my first real project. But after spending two days to get this thing working, I give up. It is supposed to work in a standalone fashion, it does not. It is supposed to work with a weird two wire interface, it does not. All I managed to get is some kind of static. At least this static lasts the duration of the sound supposedly played. I do not have the tools or the skills to debug what's going on so, time to move to plan B.
I'm now using the PCM library from "high-low tech". It allows me to load a small (~ 3 sec.) low quality sample in the Trinket Pro flash and play it through an output pin. I'm disappointed that I cannot play the whole Trololo song but the deadline is approaching and I still must deliver a minimum viable product.
I quickly hacked the PCM library to loop the sample instead of just playing it once. It's really easy : in the ISR after the call to stopPlayback(), just add a call to startPlayback(sounddata_data, sounddata_length); and the sample will loop forever !
I used Audacity to extract a sample and sox to convert it to 8 Khz :
sox in.wav -c 1 -r 8000 -u -1 out.wav
Then, I used the EncodeAudio tool to get the set of bytes to paste into the Arduino sketch and voilà !
The setback with the nonworking so-called MP3-SD module was annoying, especially with the deadline approaching. But in the end, the PCM library offers a quick work-around, even if it means only playing a part of the Trololo song.