Stacking Music Maker on a USB2.0 circuitsathome shield

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Stacking Music Maker on a USB2.0 circuitsathome shield

Post by adafruit_support_rick »

sbrown22 wrote:Should I try and use the music maker in breakout mode?
That may be your only option. I'm kind of at the limit of debugging this.

User avatar
sbrown22
 
Posts: 28
Joined: Thu Oct 23, 2014 6:21 pm

Re: Stacking Music Maker on a USB2.0 circuitsathome shield

Post by sbrown22 »

Ok thanks. So I've gone down the road of using software spi and I've _almost_ got the music maker shield working just on the mega (not tried yet through the usb shield). I had to download the latest SDcard code that lets you specify non-standard SPI pins in the constructor. Everything works except:

1) The speed the file is played back seems to depend on how big it is - I played a 400k WAV file and it was veryyy slow and I played a 23k MP3 file and it plays too fast.

2) The "startPlayingFile" method seems to block until the file has finished playing. I really need it to work in the background. I do

Code: Select all

  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // 
in the setup and I've defined DREQ as pin 3 and construct the musicPlayer as follows:

Code: Select all

 Adafruit_VS1053_FilePlayer musicPlayer = 
  Adafruit_VS1053_FilePlayer(MOSI, MISO, CLK, RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS); 
Anything else I need to do to get interrupts to work with software SPI?

Many thanks

Simon

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Stacking Music Maker on a USB2.0 circuitsathome shield

Post by adafruit_support_rick »

You're going down a road I've never traveled. I'll have to do some playing around with this.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Stacking Music Maker on a USB2.0 circuitsathome shield

Post by adafruit_support_rick »

Hmmm. I've got this running with a VS1053 breakout on a Uno, using three of the analog pins for SPI (yes, they're also digital pins), and it works fine. Next up, I'll try it with the shield on a Mega.

Aaannnnd ... OK. The shield works with the Mega. Not sure why you're having problems.

Here's the code I'm using:

Code: Select all

/*************************************************** 
  This is an example for the Adafruit VS1053 Codec Breakout

  Designed specifically to work with the Adafruit VS1053 Codec Breakout 
  ----> https://www.adafruit.com/products/1381

  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
//#define CLK 13       // SPI Clock, shared with SD card
//#define MISO 12      // Input data, from VS1053/SD card
//#define MOSI 11      // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins. 
// See http://arduino.cc/en/Reference/SPI "Connections"

// These are the pins used for the breakout example
#define BREAKOUT_RESET  9      // VS1053 reset pin (output)
#define BREAKOUT_CS     10     // VS1053 chip select pin (output)
#define BREAKOUT_DCS    8      // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_CS     7      // VS1053 chip select pin (output)
#define SHIELD_DCS    6      // VS1053 Data/command select pin (output)

// These are common pins between breakout and shield
#define CARDCS 4     // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3       // VS1053 Data request, ideally an Interrupt pin

Adafruit_VS1053_FilePlayer musicPlayer = 
  // create breakout-example object!
 // Adafruit_VS1053_FilePlayer(16, 15, 14, BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(11, 12, 13, 9, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
  
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
  
  SD.begin(CARDCS, 11, 12, 13);    // initialise the SD card
  
  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  
  // Play one file, don't return until complete
  Serial.println(F("Playing track 001"));
  musicPlayer.playFullFile("track001.mp3");
  // Play another file in the background, REQUIRES interrupts!
  Serial.println(F("Playing track 002"));
  musicPlayer.startPlayingFile("track002.mp3");
}

void loop() {
  // File is playing in the background
  if (musicPlayer.stopped()) {
    Serial.println("Done playing music");
    while (1);
  }
  if (Serial.available()) {
    char c = Serial.read();
    
    // if we get an 's' on the serial console, stop!
    if (c == 's') {
      musicPlayer.stopPlaying();
    }
    
    // if we get an 'p' on the serial console, pause/unpause!
    if (c == 'p') {
      if (! musicPlayer.paused()) {
        Serial.println("Paused");
        musicPlayer.pausePlaying(true);
      } else { 
        Serial.println("Resumed");
        musicPlayer.pausePlaying(false);
      }
    }
  }

  delay(100);
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”