music maker shield issue

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mantaraffu
 
Posts: 5
Joined: Fri Jun 20, 2014 7:55 pm

music maker shield issue

Post by mantaraffu »

hello, I'm trying to make a simple switch case mp3 player with this shield. this is my first day with it and this is my code maded of cut and paste. obviously it doesn't work. any suggestion?

Code: Select all

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define SHIELD_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(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

const int sensorMin = 0;      // sensor minimum, discovered through experiment
const int sensorMax = 600;    // sensor maximum, discovered through experiment

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
    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);    // 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() {
  // read the sensor:
  int sensorReading = analogRead(A0);
  // map the sensor range to a range of four options:
  int range = map(sensorReading, sensorMin, sensorMax, 0, 2);

  // do something different depending on the
  // range value:
  switch (range) {
    case 0:    // your hand is on the sensor
      Serial.println("dark");
      musicPlayer.stopPlaying();
      break;
    case 1:    // your hand is close to the sensor
      Serial.println("dim");
      musicPlayer.pausePlaying(true);
      break;
    case 2:    // your hand is a few inches from the sensor
      Serial.println("medium");
      musicPlayer.pausePlaying(false);
      break;
  }
  delay(1);        // delay in between reads for stability
}

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: music maker shield issue

Post by Franklin97355 »

obviously it doesn't work. any suggestion?
Yes, elaborate on the "doesn't work" part. I don't have one so I can't test it but I might be able to spot errors.

User avatar
mantaraffu
 
Posts: 5
Joined: Fri Jun 20, 2014 7:55 pm

Re: music maker shield issue

Post by mantaraffu »

yes, you're right. I've spent a couple of hour to understand that this shield doen't work well on arduino 2009 and I'm a little tired. :-)
This library is new for me, in the previous code I was trying to make a simple pause and start for a track using an analog value.

User avatar
mantaraffu
 
Posts: 5
Joined: Fri Jun 20, 2014 7:55 pm

Re: music maker shield issue

Post by mantaraffu »

ok, I obtained a simple code for pause and play.

Code: Select all

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define SHIELD_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(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

const int sensorMin = 0;     
const int sensorMax = 1023;    

void setup() {
  
  Serial.begin(9600);
    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);    // 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.startPlayingFile("track001.mp3");
}


void loop() {

  int sensorReading = analogRead(A0);

  int range = map(sensorReading, sensorMin, sensorMax, 0, 1);


  switch (range) {
    case 0:   
      Serial.println("1");
      musicPlayer.pausePlaying(false);;
      break;
    case 1:    
      Serial.println("2");
      musicPlayer.pausePlaying(true);
      break;
   
  }
  delay(100);        
}





User avatar
mantaraffu
 
Posts: 5
Joined: Fri Jun 20, 2014 7:55 pm

Re: music maker shield issue

Post by mantaraffu »

now I'm trying to set the valume by the same analog in of the switch case.

Code: Select all

void loop() {
 

  int val = analogRead(A0);
  
  analogWrite(musicPlayer.setVolume(val,val));
a this point I have an error message like this

sensor_volume.ino: In function 'void loop()':
sensor_volume:65: error: invalid use of void expression

User avatar
mantaraffu
 
Posts: 5
Joined: Fri Jun 20, 2014 7:55 pm

Re: music maker shield issue

Post by mantaraffu »

ok, got it. it's weird but works.

Code: Select all

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

#define SHIELD_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(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
  // create shield-example object!
  Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

const int sensorMin = 0;     
const int sensorMax = 1023;    
const int val = 0;

void setup() {
  
  Serial.begin(9600);
    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);    // initialise the SD card
  
  // Set volume for left, right channels. lower numbers == louder volume!
  //musicPlayer.setVolume(10,100);

  // 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.startPlayingFile("track001.mp3");
}


void loop() {
 

  int val = analogRead(A0);
  
  analogWrite ;musicPlayer.setVolume(val*100/1000,val*100/1000);
 
 

  int range = map(val, sensorMin, sensorMax, 0, 1);


  switch (range) {
    case 0:   
      Serial.println("1");
      musicPlayer.pausePlaying(false);;
      break;
    case 1:    
      Serial.println("2");
      musicPlayer.pausePlaying(true);
      break;
   
  }
  delay(100);  
  }  






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

Return to “Arduino Shields from Adafruit”