Attaching a Music Maker Shield to an Arduino Mega

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
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

Hi,
I am currently working on a project with 6 stepper motors, a music maker shield and an Arduino Mega. I am using a Mega since I will need 12 digital pins for the motors. Each motor has a step pin and a direction pin.
I am using A4988 Stepper Motor Drivers. When I tested the shield with the mega and one motor, I attached the motor using pins d50 and d51. The motor did not rotate. My colleague told me not to use those pins since they might be interfering with the shield (MOSI and MISO). I then attached the motor using pins d48 and d49 and the motor is running beautifully. Which other 10 pins can I use for the remaining motors?
Thank you for your help,
Reyce Krause
Attachments
IMG_0985.jpg
IMG_0985.jpg (1003.89 KiB) Viewed 891 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by adafruit_support_bill »

You will want to avoid pins 3, 4, 6 and 7 plus pins 50-53 on the Mega. All the other pins should be free.

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

Thank you so much!
I have another question.
For my project I would like the music to start playing a few seconds before the stepper motor starts rotating. In loop it looks like the music is starting before the motor but when I run the program the music starts after the motor is already rotating.
Thank you for your help,
Reyce

Code: Select all


/*     Simple Stepper Motor Control Exaple Code     
 *     by Dejan Nedelkovski, http://www.HowToMechatronics.com
 *     Blink the steppin on and off 
 */
 
// 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_RESET  -1      // VS1053 reset pin (unused!)
#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);

int currfilenum = 0;
const int stepPin48 = 48; 
const int dirPin49 = 49; 

void setup() {

  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");
  Serial.println("Working_Stepper_Music_Shield");

  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"));
  
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);                        // don't do anything more
  }
  
  // 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

  pinMode(stepPin48,OUTPUT); 
  pinMode(dirPin49,OUTPUT);
}

void loop() {

 if (musicPlayer.stopped()) {
    currfilenum = -1;
    Serial.println("Done playing music");
  }
 
 if (currfilenum != 0) {
    currfilenum = 0;
    musicPlayer.stopPlaying();
    musicPlayer.startPlayingFile("Andy.mp3"); 
  }

  digitalWrite(dirPin49,HIGH); // Enables the motor to move in a particular direction
 
  // Makes 200 pulses for making one full cycle rotation
  // increase x to do more rotations
  // increase delay microseconds to decrease speed
  
  for(int x = 0; x < 400; x++) {
    
    digitalWrite(stepPin48,HIGH);  
    delayMicroseconds(2000); 
    digitalWrite(stepPin48,LOW); 
    delayMicroseconds(2000); 
  }
  delay(1000); // One second delay
  
  digitalWrite(dirPin49,LOW); //Changes the rotations direction
  
  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin48,HIGH);   
    delayMicroseconds(2000);
    digitalWrite(stepPin48,LOW);  
    delayMicroseconds(2000);
  }
  delay(1000);
}
Last edited by adafruit_support_bill on Thu Jan 04, 2018 2:26 pm, edited 1 time in total.
Reason: Fixed [code] tags

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by adafruit_support_bill »

It could be that your music track has some seconds of dead-time at the start. If you add some serial output to your sketch you can follow the exact sequence of events.

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

Thank you I will try that.

As you can can see from the attached picture I have 4 out of 6 steppers attached to the mega, yet when I run the program only the first 3 rotate. The motor on pins 42 and 43 does not rotate. I am using an AC/DC adapter with 12V output connected to VIN.
Can the mega handle 6 stepper motors or is it my power supply?
Thank You very much,
Reyce

Code: Select all


/*     Simple Stepper Motor Control Exaple Code     
 *     by Dejan Nedelkovski, http://www.HowToMechatronics.com
 *     Blink the steppin on and off 
 */
 
// 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_RESET  -1      // VS1053 reset pin (unused!)
#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);

int currfilenum = 0;

const int stepPin42 = 42; 
const int dirPin43 = 43; 

const int stepPin44 = 44; 
const int dirPin45 = 45; 

const int stepPin46 = 46; 
const int dirPin47 = 47; 

const int stepPin48 = 48; 
const int dirPin49 = 49; 

void setup() {

  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");
  Serial.println("Three_Working_Steppers_Music_Shield");

  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"));
  
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);                        // don't do anything more
  }
  
  // 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

  pinMode(stepPin42,OUTPUT); 
  pinMode(dirPin43,OUTPUT);
  
  pinMode(stepPin44,OUTPUT); 
  pinMode(dirPin45,OUTPUT);
  
  pinMode(stepPin46,OUTPUT); 
  pinMode(dirPin47,OUTPUT);
  
  pinMode(stepPin48,OUTPUT); 
  pinMode(dirPin49,OUTPUT);
}

void loop() {

 if (musicPlayer.stopped()) {
    currfilenum = -1;
    Serial.println("Done playing music");
  }
 
 if (currfilenum != 0) {
    currfilenum = 0;
    musicPlayer.stopPlaying();
    musicPlayer.startPlayingFile("Andy.mp3"); 
  }

  digitalWrite(dirPin43,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(dirPin45,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(dirPin47,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(dirPin49,HIGH); // Enables the motor to move in a particular direction
 
  // Makes 200 pulses for making one full cycle rotation
  // increase x to do more rotations
  // increase delay microseconds to decrease speed
  
  for(int x = 0; x < 400; x++) {
    
    digitalWrite(stepPin42,HIGH);
    digitalWrite(stepPin44,HIGH);  
    digitalWrite(stepPin46,HIGH);  
    digitalWrite(stepPin48,HIGH);  
    delayMicroseconds(2000); 
    digitalWrite(stepPin42,LOW);
    digitalWrite(stepPin44,LOW); 
    digitalWrite(stepPin46,LOW); 
    digitalWrite(stepPin48,LOW); 
    delayMicroseconds(2000);               
  }
  delay(1000); // One second delay
  
  digitalWrite(dirPin43,LOW); //Changes the rotations direction
  digitalWrite(dirPin45,LOW); //Changes the rotations direction
  digitalWrite(dirPin47,LOW); //Changes the rotations direction
  digitalWrite(dirPin49,LOW); //Changes the rotations direction
  
  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin42,HIGH); 
    digitalWrite(stepPin44,HIGH);   
    digitalWrite(stepPin46,HIGH);   
    digitalWrite(stepPin48,HIGH);   
    delayMicroseconds(2000);
    digitalWrite(stepPin42,LOW); 
    digitalWrite(stepPin44,LOW); 
    digitalWrite(stepPin46,LOW); 
    digitalWrite(stepPin48,LOW);  
    delayMicroseconds(2000);
  }
  delay(1000);
]
Attachments
IMG_1007.jpg
IMG_1007.jpg (428.75 KiB) Viewed 816 times
IMG_1006.jpg
IMG_1006.jpg (704.65 KiB) Viewed 816 times
Last edited by adafruit_support_bill on Thu Jan 04, 2018 5:56 pm, edited 1 time in total.
Reason: Fixed [code] tags

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by adafruit_support_bill »

What kind of motors are you using?

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »


User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

You can see the specs on a white piece of paper on the previous picture I sent of the motors.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by adafruit_support_bill »

With a phase resistance of 30 ohms and a supply voltage of 12v, these motors are going to pull 400mA per phase or 800mA each. Your 1A power supply will be straining to supply more than one motor at a time.

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

What power supply, how many amps, would you recommend to power these 6 Stepper motors ?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by adafruit_support_bill »

6 steppers at 800mA each will need a total of 4800mA or 4.8A. A 12v/5A supply would do it: https://www.adafruit.com/product/352

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

Thank You.

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

Hi,
As of today the Music Maker Shield is not working properly. The program starts playing the music and I get this displayed on my monitor:

"Adafruit VS1053 Simple Test
Three_Working_Steppers_Music_Shield
VS1053 found
Done playing music"

but after a random number of seconds it stops playing and I get this message:

"Adafruit VS1053 Simple Test
Three_Working_Steppers_Music_Shield
Couldn't find VS1053, do you have the right pins defined?"

When I press down with my fingers on the shield it might or might not start playing again. I've checked and nothing is loose. It is very arbitrary when it stops and starts playing.

This is my purchase info:

ORDER #1552350-7130067528
I purchased this item on September 25, 2017.
Adafruit Adafruit "Music Maker" MP3 Shield for Arduino w/3W Stereo Amp - v1.0 PID: 1788

Thank you for your help,
Reyce

Code: Select all

[

/*     Simple Stepper Motor Control Exaple Code with Adafruit Music Maker Shield    
 *     by Dejan Nedelkovski, http://www.HowToMechatronics.com
 *     Blink the steppin on and off 
 */
 
#include <SPI.h>              // include SPI, MP3 and SD libraries
#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_RESET  -1       // VS1053 reset pin (unused!)
#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);

int currfilenum = 0;

const int stepPin42 = 42; 
const int dirPin43 = 43; 

const int stepPin44 = 44; 
const int dirPin45 = 45; 

const int stepPin46 = 46; 
const int dirPin47 = 47; 

const int stepPin48 = 48; 
const int dirPin49 = 49; 

void setup() {

  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");
  Serial.println("Three_Working_Steppers_Music_Shield");

  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"));
  
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);                        // don't do anything more
  }
  
  // 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



  pinMode(stepPin42,OUTPUT); 
  pinMode(dirPin43,OUTPUT);
  
  pinMode(stepPin44,OUTPUT); 
  pinMode(dirPin45,OUTPUT);
  
  pinMode(stepPin46,OUTPUT); 
  pinMode(dirPin47,OUTPUT);
  
  pinMode(stepPin48,OUTPUT); 
  pinMode(dirPin49,OUTPUT);
  
}

void loop() {

 if (musicPlayer.stopped()) {
    currfilenum = -1;
    Serial.println("Done playing music");
  }
 
 if (currfilenum != 0) {
    currfilenum = 0;
    musicPlayer.stopPlaying();
    musicPlayer.startPlayingFile("Andy.mp3"); 
  }

  digitalWrite(dirPin43,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(dirPin45,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(dirPin47,HIGH); // Enables the motor to move in a particular direction
  digitalWrite(dirPin49,HIGH); // Enables the motor to move in a particular direction
 
  // Makes 200 pulses for making one full cycle rotation
  // increase x to do more rotations
  // increase delay microseconds to decrease speed
  
  for(int x = 0; x < 400; x++) {
    
    digitalWrite(stepPin42,HIGH);
    digitalWrite(stepPin44,HIGH);  
    digitalWrite(stepPin46,HIGH);  
    digitalWrite(stepPin48,HIGH);  
    delayMicroseconds(2000); 
    digitalWrite(stepPin42,LOW);
    digitalWrite(stepPin44,LOW); 
    digitalWrite(stepPin46,LOW); 
    digitalWrite(stepPin48,LOW); 
    delayMicroseconds(2000);               
  }
  delay(1000); // One second delay
  
  digitalWrite(dirPin43,LOW); //Changes the rotations direction
  digitalWrite(dirPin45,LOW); //Changes the rotations direction
  digitalWrite(dirPin47,LOW); //Changes the rotations direction
  digitalWrite(dirPin49,LOW); //Changes the rotations direction
  
  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin42,HIGH); 
    digitalWrite(stepPin44,HIGH);   
    digitalWrite(stepPin46,HIGH);   
    digitalWrite(stepPin48,HIGH);   
    delayMicroseconds(2000);
    digitalWrite(stepPin42,LOW); 
    digitalWrite(stepPin44,LOW); 
    digitalWrite(stepPin46,LOW); 
    digitalWrite(stepPin48,LOW);  
    delayMicroseconds(2000);
  }
  delay(1000);
}]
Attachments
Musicmaker.jpg
Musicmaker.jpg (945.64 KiB) Viewed 724 times
Last edited by adafruit_support_bill on Sun Jan 07, 2018 4:03 pm, edited 1 time in total.
Reason: Please use [code] tags when posting code to the forums.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by adafruit_support_bill »

When I press down with my fingers on the shield it might or might not start playing again. I've checked and nothing is loose. It is very arbitrary when it stops and starts playing.
Thet generally indicates an intermittent connection of some sort. Please post some photo clearly showing all your soldering to the shield.

User avatar
Reyce
 
Posts: 45
Joined: Tue Apr 26, 2016 1:16 pm

Re: Attaching a Music Maker Shield to an Arduino Mega

Post by Reyce »

Hi,
I have checked all the soldering and it seems okay. The strange thing is, the music plays when I attach a head phone to the shield but it won't play when only the speakers are attached.
I really appreciate your help!
Reyce
Attachments
IMG_1025.jpg
IMG_1025.jpg (807.81 KiB) Viewed 710 times
IMG_1024.jpg
IMG_1024.jpg (896.3 KiB) Viewed 710 times

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

Return to “Arduino Shields from Adafruit”