It took me forever and a day to figure out what was not working.
I try to play an mp3 using the adafruit vs1053 library and it works fine if I use
musicPlayer.playFullFile("test.mp3") This stops code execution until the file is done playing.
However If I use musicPlayer.startPlayingFile("test.mp3") the file will not play but code execution does not stop. Go figure.
Here is the confusing part to me... This code snippit from the cpp file.
PlayFullFile works, and it calls startPlayingFile. so why the heck does calling startPlayingFile not work from my sketch. Or any sketch for that matter.
boolean Adafruit_VS1053_FilePlayer::playFullFile(const char *trackname) {
if (! startPlayingFile(trackname)) return false;
while (playingMusic) {
// twiddle thumbs
feedBuffer();
delay(5); // give IRQs a chance
}
// music file finished!
return true;
}
boolean Adafruit_VS1053_FilePlayer::startPlayingFile(const char *trackname) {
// reset playback
sciWrite(VS1053_REG_MODE, VS1053_MODE_SM_LINE1 | VS1053_MODE_SM_SDINEW);
// resync
sciWrite(VS1053_REG_WRAMADDR, 0x1e29);
sciWrite(VS1053_REG_WRAM, 0);
currentTrack = SD.open(trackname);
if (!currentTrack) {
return false;
}
// don't let the IRQ get triggered by accident here
noInterrupts();
// As explained in datasheet, set twice 0 in REG_DECODETIME to set time back to 0
sciWrite(VS1053_REG_DECODETIME, 0x00);
sciWrite(VS1053_REG_DECODETIME, 0x00);
playingMusic = true;
// wait till its ready for data
while (! readyForData() ) {
#if defined(ESP8266)
yield();
#endif
}
// fill it up!
while (playingMusic && readyForData()) {
feedBuffer();
}
// ok going forward, we can use the IRQ
interrupts();
return true;
}
I checked my dreq and even rewired it to a different pin but nothing seems to work. I am not sure what I am missing here. Can someone point me in the right direction.
The libraries have been modified to support SdFat. That part appears to be working fine.
I am using a Mega with a seeed music sheild v 1.3.
This is odd because this symbol is defined in Adafruit_VS1053.h so this redefinition should generate a compiler error. The interrupt pin number is defined by DREQ in the original library.
If you are using a modified fork of the Adafruit library, revert to the original version. I suggest posting your sketch code to get more help.
Try adding Serial.print messages in the library to verify the code is doing what you expect. The useInterrupt function has commented out a Serial.print message which will tell you whether the interrupt function has been attached. Uncomment it and see if the message appears or not. If not, it has something to do with VS1053_FILEPLAYER_PIN_INT.
The function feeder is the interrupt service routine so to determine whether it is being called or not, add some digitalWrites to toggle a GPIO pin. Hook up an LED and see if it blinks or not. If it does not, the interrupt attach failed.
Trying to get this working on due. After much deliberation ( AKA Cursing and frustration) I figured out where it is crashing but why is beyond me. I think it has something to do with SPI.
Here is the part of the library that it crashes at. This line "Serial.println("DEBUG: SD Card Disabled Starting SPI for VS1053 ");" Shows up on the serial monitor like this
">>> Intializing VS1053 MP3 Player chip (NOTE: This is in my sketch to call the VS1053 Begin)
DEBUG: SD Card Disabled Starting SPI for"
If I add the delay sometimes it will get a little further but not much. The SPI for the VS 1053 never gets activated. If it gets that far in the code it just hangs and will not go any further.
boolean VS1053_FilePlayer::begin(void) {
// Set the card to be disabled while we get the VS1053 up
pinMode(_cardCS, OUTPUT);
digitalWrite(_cardCS, HIGH);
Serial.println("DEBUG: SD Card Disabled Starting SPI for VS1053 ");
delayMicroseconds(10000);
uint8_t v = VS1053::begin();
return (v == 4);
}
uint8_t VS1053::begin(void) {
//Serial.println("DEBUG: VS1053 Configuring SPI ");
if (_reset >= 0) {
Serial.println("DEBUG ---------- Reset >=0 ");
pinMode(_reset, OUTPUT);
digitalWrite(_reset, LOW);
}
pinMode(_cs, OUTPUT);
digitalWrite(_cs, HIGH);
pinMode(_dcs, OUTPUT);
digitalWrite(_dcs, HIGH);
pinMode(_dreq, INPUT);
if (! useHardwareSPI) {
Serial.println("DEBUG ---------- Not using Hardware SPI");
pinMode(_mosi, OUTPUT);
pinMode(_clk, OUTPUT);
pinMode(_miso, INPUT);
Serial.println("DEBUG ---------- Non Hardware -cs SPI Started");
} else {
SPI.begin();
Serial.println("DEBUG ---------- SPI Started");
SPI.setDataMode(SPI_MODE0);
Serial.println("DEBUG ---------- SPI Mode set to MODE0");
SPI.setBitOrder(MSBFIRST);
Serial.println("DEBUG ---------- SPI Bit Order MSB");
SPI.setClockDivider(SPI_CLOCK_DIV128);
Serial.println("DEBUG ---------- SPI CLock Divider set to 128");
}
Serial.println((sciRead(VS1053_REG_STATUS) >> 4));
reset();
return (sciRead(VS1053_REG_STATUS) >> 4) & 0x0F;
}
My Configuration is pin 10 for the SD Card CS and Pin 52 for the VS1053 CS. Mosi, Miso, and SCLK are on the 6pin header. (Sorry I forgot the name of it.)
This works fine on mega. but will not work on due.
I think this may have something to do with the reset in this code. I pulled my Serial prints out and added them back one line at a time. I found that when it gets to the reset it is locking up.
1.0.4 includes all the fixes. I had to git pull to update my local copy.
I can only guess _reset, _cs, or _dcs are not set to the correct pins. Maybe Serial.print the values of _reset, _cs, _dcs inside the reset function to make sure. Or is it possible there is other hardware connected to the same pins?
>>> Intializing VS1053 MP3 Player chip
DEBUG: Card CS 10
DEBUG: SD Card Disabled Starting MP3 Chip
DEBUG: Reset 19
DEBUG: CS 52
DEBUG: DCS 17
DEBUG: DREQ 18
DEBUG: mosi 109
DEBUG: miso 108
DEBUG: clk 110
DEBUG: Not Using Hardware SPI
DEBUG: Getting ready for reset
D "And I think i just might crash right here..."
I ordered a different mp3 shield to see if I can get it to work. My first issue was not getting it to read the SD Card with SD Fat. I found 3 resistors in series with the miso, mosi, and clock lines that were causing that issue. Now it reads the SD but will not communicate with the VS1053B.
I am guessing the resistors are included because the board was intended for use with 5V AVR but the vs1053 used 3.3V logic. Since Due uses 3.3V logic the resistors are not needed and must be removed. Is it possible the other pins such as _reset, _cs, _dcs have the same problem?
The Adafruit VS1053 feather wing board is designed for 3.3V operation. I used it with an ESP8266 board (3.3V logic) with no problems.
The resistors and an unsoldered pin on the vs1053 chip. Quality control issue there. The pin was just sitting on the solder on the reset line.
I reflowed the entire chip and replaced the 1.8K resistors with 1 Ohm resistors. Now I just can't forget to keep it away from the Mega board or I may get some smoke.
So with the seeed studio music player v 1.2 replace R3, R31, R32, R33, R24, R29 and R26 with 1 ohm resistor to get it working on a Arduino Due. ( At Your Own risk )
I have it working with A Fat 32 16gig SD Card Also.
Now to integrate it into the Gauges and clock.
Thank You for the help. I will keep you updated on my progress.
I can't get the FM Radio to work on DUE. The SI4703 chip will not initialize. It appears to lock up the DUE. The SI4703 work great on mega but not on DUE. It is a i2c interface with a pin for reset. I think the issue is in the wire library. Or at least that is the way it looks to me.
I am using this library I commented out A4 and A5 also tried changing them to 20 and 21. No Luck. I also tried with it hooked up to A4 and A5.
I am unfamiliar with i2c that does not have address. Unless I am misunderstanding what I am reading it uses pin 2 to initialize the device and start communication on the bus. There is not and address involved. I did find a document that said it had an address of 0x11 So I tried it with a i2c scanner sketch and it comes back as no devices found.