MP3 Trigger Documentation

The Robertsonics MP3 Trigger from SparkFun is a nice device, I think a better design than the Adafruit WaveShield.


(from SparkFun.com)

The MP3 Trigger plays MP3 encoded sounds, up to 255 of them, and has software volume control … and doesn’t cover up your Arduino (and therefore should work with a Mega or other non-standard size board).  An added bonus is the simple wire up mode: the seven pin pairs on the left can be either shorted or have 5VDC applied across them to trigger tracks 1..7, or serial control up to 255 tracks+volume control.  As a drawback, it doesn’t have much of an amplifier–(the Waveshield looks like it can drive more current, but that may not be the case in actuality.

I had a problem with my first board, which Sparkfun kindly exchanged for a brand new one.  Thanks!

MP3 Trigger control blocks

use as you like!

void playTrack(int track)
{
  if (isPlaying == 0) // check to see if a track is playing (would be 1 if playing)
  {  
     isPlaying = true; // set isPlaying to 1 (true)
     stopLatch = false; // open interlock
     Serial1.print(‘t’, BYTE); // track signal
     Serial1.print(track, BYTE);
     Serial.println("playing");
  }
}

void stopTrack()
{
  if (isPlaying == true && stopLatch == false) // if
  {
    do
    {
        Serial1.print(‘O’, BYTE);
        delay (10);
      Serial.print("stop signal");
      stopLatch = true;
    }
    while (Serial1.available() > 0);
    if (stopLatch = true)
   {
    Serial.println("stopLatch");
   }
 }
}

—- in your main loop you need to include the code below to call the recycle() block below—-

 inByte = Serial1.read();
 if (inByte == ‘X’ or inByte == ‘x’)
 {
  recycle();
}

void recycle()  // recycle isPlaying when track ends
{
    {
      isPlaying = false;  // set isPlaying interlock
      Serial.print("ACK ");  // print ackgnowledgement for debugging purposes
      Serial1.flush();  // Note Serial1 for Arduino Mega
      digitalWrite(playLight, LOW); // turn off playing light
      delay(20);
    }
}

Arduino code sample:

 

// MP3 Trigger test program.

//int volume;
char inByte=0; // initialize storage variable for serial read (receives X [ASCII 88] or x [ASCII 120] decimal)
boolean playBit; // flip bit for not playing/playing
boolean stopLatch;  // flip bit for stop interlock

int track = 0;

int volumePot = 2; // pot for volume control
int volume = 250; // volume control, default to most of the way up (0..255)

void setup()
{
  pinMode(40, INPUT);
  Serial.begin(38400);  // MP3 trigger communicates at 38400 b/s
  playBit = 0; // bit to flip while playing :: 0 for not playing, 1 for playing
}

void loop()
{

 //volume control
  volume = analogRead(volumePot);  // read potentiometer for volume control
  volume = map(volume, 0, 1023, 0 ,255);
  Serial.print(‘v’, BYTE);
  Serial.print(volume, BYTE);

 

//play track 2 if switch closed — NB: the documentation where it says to send messages like "002" will result in an error message!
  if (digitalRead(40) == HIGH)
  {
    playTrack (2);
  }
 }
else
{
 stopTrack();
}

 

 

void playTrack(int track)
{
  if (isPlaying == 0) // check to see if a track is playing (would be 1 if playing)
  {  
     isPlaying = true; // set isPlaying to 1 (true)
     stopLatch = false; // open interlock
     Serial1.print(‘t’, BYTE); // track signal
     Serial1.print(track, BYTE);
     Serial.println("playing");
  }
}

void stopTrack()
{
  if (isPlaying == true && stopLatch == false) // if
  {
    do    // do-while loop tests condition at the end, this way it does it at least once
    {
        Serial1.print(‘O’, BYTE); // send start-stop signal to MP3 trigger
        delay (10);
      Serial.print("stop signal");
      stopLatch = true;  // set interlock bit
    }
    while (Serial1.available() > 0);  // check fo see if it ackgnowledged the signal
    if (stopLatch = true)
   {
    Serial.println("stopLatch");    // for debugging purposes
   }
 }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s