Music Shield pins D0-D9 - How to use for my own application?

Hi!

The vision: Arduino project with buttons. When one of the buttons is pushed, music and LED lights play till another button is pushed.
I’d like to wire up 6-8 pins for these buttons using a switch (schematic here

On the Music Shield wiki, it says Arduino pins D0-D9 are available, but I can’t get the musicPlayAll example to work when using these pins for other things.

I’m using the Music Shield, through a Proto Shield, to an Arduino Uno. (Nevermind the red circle)

On my Proto Shield, I wired pins D2-D5 to HIGH/LOW based on switches - they pass through to the Music Shield

musicPlayAll doesn’t play when { Music Shield + Proto Shield (pins 2-5 connected to switches) + Arduino UNO }
musicPlayAll plays music when { Music Shield + Proto Shield (pins 2-5 desoldered) + Arduino UNO }
musicPlayAll plays music when { Music Shield + Arduino UNO }
Switch Program detects the switch states when { Proto Shield (soldered) + Arduino UNO }

I bought the Music Shield because it said I could use these other pins. How do I do it?

I can’t tell if this is a hardware or software issue. What program would I use as a basis for this?

Thanks!

From the Wiki: seeedstudio.com/wiki/Music_Shiel … on_Arduino
D0 - Unused.
D1 - Unused.
D2 - Used for receiving signal from iPod dock(could be used for your own application if iPod dock is not used).
D3 - Used for receiving signal from button for Volume Up(could be used for your own application if the switch is not used).
D4 - Used for receiving signal from switch for Next Song function(could be used for your own application if the switch is not used).
D5 - Used for receive signal from switch for Play&Stop and Record function(could be used for your own application if the switch is not used).
D6 - Used for receive signal from switch for Previous Song function(could be used for your own application if the switch is not used).
D7 - Used for receiving signal from button for Volume Down(could be used for your own application if the switch is not used).

D8 - Used for Green Led instructions(could be used for your own application if the switch is not used).
D9 - Used for Red Led instructions(could be used for your own application if the switch is not used).

Switch program:

[code]/*

  • Switch test program
    */

int switchPin = 2; // Switch connected to digital pin 2

void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(switchPin, INPUT); // sets the digital pin as input to read switch
}

void loop() // run over and over again
{
Serial.print(“Switch 2-5:”);
for (int i = 2; i<=5; i++)
{
Serial.print(digitalRead(i));
}
Serial.println();
delay(100);
}[/code]

Hi michaelcole:
I saw the picture,for the red circle,I think that is the problem.
Because the Music shield is using the SPI,so the res circle is the SPI connect,for this, I think you are not connect to the Music shield now.First you can test it with out the Proto shield,for the testing,you can set the pin(which you want to use) become INPUT mode.

Hi Tobe, good idea! Based on some excellent advice I soldiered 3 wires to the top of the Music Shield so it can pass through to Arduino. (That was in my notes too :slight_smile:

The problem now is how to use some of pins D0-D9 for other things.

I’m using 0 and 1 for Serial. The Music Shield either doesn’t play, or plays then volumes all the way down, when pins 2-5 are connected to switches. This even happens when I bend out the pins of the Proto Shield so they don’t go into Arduino.

How do I use these pins for other parts of my project?

Thanks!

Mike

Hi~ Mike:
In the code,you can fine some function on the “void setup()” function:
InitIOForKeys();
InitIOForLEDs();
The Real code of this two function is in the “config.cpp”
So go to the “config.cpp” file,We can find something like this:

void InitIOForKeys()
{
#if defined(AVR_ATmega1280)|| defined(AVR_ATmega2560)
DDRH &= ~(1<<VD);
DDRH &= ~(1<<BK);
DDRE &= ~(1<<PS);
DDRG &= ~(1<<VU);
DDRE &= ~(1<<NT);
//internal pull-high
PORTH |= (1<<VD | 1<<BK);
PORTE |= (1<<PS | 1<<NT);
PORTG |= 1<<VU ;

#else
DDRD &= ~(1<<VD);
DDRD &= ~(1<<BK);
DDRD &= ~(1<<PS);
DDRD &= ~(1<<VU);
DDRD &= ~(1<<NT);
    //internal pull-high
PORTD |= (1<<VD | 1<<BK | 1<<PS | 1<<VU | 1<<NT);
#endif

}

//Initialize IO control ports of LEDS
void InitIOForLEDs()
{
LED_DDR |= (1<<RED_LED);
LED_DDR |= (1<<GREEN_LED);

RED_LED_OFF();
GREEN_LED_ON();

}

So if you want to use the other key,you can change something into here.
For the D2,it is use to the SoftSerial for the Ipod_connecter.
So if you Do not want to use the hard ware key,you can delete this two function like this
//InitIOForKeys();
//InitIOForLEDs();
and define all the key you want.

Hi, when I comment out InitIOForLEDs(), this approach works.

Card found, starting... Ok.

Sectors per Cluster: 64
FAT Start sector: 142
Root start sector: 608
Data start sector: 512
ClockF:B800


Found file name is 2GUNS   MP3
File size: 4554880bytes. 

When I comment out InitIOForKeys(), this does not work. Music doesn’t play and I get this:

Card found, starting... Ok.

Sectors per Cluster: 64
FAT Start sector: 142
Root start sector: 608
Data start sector: 512
ClockF:B800

Did you try this and get a different result?

I don’t understand this code well enough to modify it to do something different:

void InitIOForKeys()
{
	#if defined(__AVR_ATmega1280__)|| defined(__AVR_ATmega2560__)
	DDRH &= ~(1<<VD);
	DDRH &= ~(1<<BK);
	DDRE &= ~(1<<PS);
	DDRG &= ~(1<<VU);
	DDRE &= ~(1<<NT);
        //internal pull-high
	PORTH |= (1<<VD | 1<<BK);
	PORTE |= (1<<PS | 1<<NT);
	PORTG |= 1<<VU ;

	#else
	DDRD &= ~(1<<VD);
	DDRD &= ~(1<<BK);
	DDRD &= ~(1<<PS);
	DDRD &= ~(1<<VU);
	DDRD &= ~(1<<NT);
        //internal pull-high
	PORTD |= (1<<VD | 1<<BK | 1<<PS | 1<<VU | 1<<NT);
	#endif
}

When I copy and commend the code for InitIOForKeys() to InitIOForKeysCustom() like below, music plays briefly as the volume turns all the way down. As if the volume down button was pressed.

[code]// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include <avr/io.h>
#include “config.h”
#include “filesys.h”
#include “player.h”
#include “vs10xx.h”
#include “record.h”
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);//pin2-Rx,pin3-Tx(note: pin3 is actually later used as volume down input)

//Initialize IO control ports of KEYS
void InitIOForKeysCustom()
{
// DDRD &= ~(1<<VD);
DDRD &= ~(1<<BK);
DDRD &= ~(1<<PS);
DDRD &= ~(1<<VU);
DDRD &= ~(1<<NT);
//internal pull-high
PORTD |= (
// 1<<VD |
1<<BK | 1<<PS | 1<<VU | 1<<NT);
}

void setup()
{
Serial.begin(9600);
//Serial.println(“Hello test!”);
mySerial.begin(19200);// used for receiving command data from the iPod dock.

InitSPI();

InitIOForVs10xx();

InitIOForKeysCustom();

//InitIOForLEDs();

InitFileSystem();

//VsSineTest();

Mp3Reset();

}

void loop()
{
#if defined(AVR_ATmega1280)|| defined(AVR_ATmega2560)
// If play/stop button is pressed during boot, enter recording.
if (0== PSKey)
{
delay(20);
while(0 == PSKey);
delay(20);
Record();
}
#endif

Play();
while(1);
}

[/code]

Hi~
Because there has a function to check for the key,so there is the problem.
You can fine the void AvailableProcessorTime() funtion in the player.cpp,and there has the CheckKey();funtion,what should we do is Note it,just like this:

[code]void AvailableProcessorTime()
{

do
{
	//CheckKey();

	 IPODCommandProcess();
	 
	if(0 == playStop)
	{
		GREEN_LED_ON();
	}	
}while(0 == playStop);

//do other things
ControlLed();

}[/code]

so now,you can use the pin by your own.

Hi All,

I wanna ask in website seeedstudio.com/wiki/Music_Shield_V1.0
i read to record sound with music shield is like this :

Record music:(Only support ATmega1280 and ATmega2560 based board)

  1. Press play/stop knob before pressing the RESET button of Arduino.
  2. Release RESET button for a second and then release play/stop knob. When the music shield is beginning to record, the green and red LEDs will blink synchronous.
    3.Press play/stop knob will stop recording.

is that any coding on that program? or just plug that music shield into mega 2560 and we can record?
so confuse :open_mouth:

https://mp3tomato.com/ This is where I find music the fastest and easiest way!

test