Sparkfun MP3 Trigger and serial monitor

Just started using the Sparkfun MP3 Trigger. https://www.sparkfun.com/products/11029

Using .h file from here: GitHub - sansumbrella/MP3Trigger-for-Arduino: A simple Arduino interface for the SparkFun MP3 Trigger. Put it in a folder called "MP3Trigger" inside your Arduino/libraries folder

I've wired it up with RX to pin 2 on the Arduino and TX to pin 3

My basic test code:

#include <SoftwareSerial.h>
#include <MP3Trigger.h>

SoftwareSerial trigSerial = SoftwareSerial(2, 3);
MP3Trigger trigger;

void setup() {
  // Start serial communication with the trigger (over SoftwareSerial)
  trigger.setup(&trigSerial);
  trigSerial.begin( MP3Trigger::serialRate() );

}

void loop() {
  trigger.update();
  trigger.play(1);
  Serial.println("play track 1");
  delay(5000);
  trigger.play(2);
  Serial.println("play track 2");
  delay(2000);
  trigger.play(3);
  Serial.println("play track 3");
  delay(3000);
}

This works fine in terms of playing the MP3s but I'm not getting anything in the serial monitor. I have tried it with a Leonardo and an UNO. The Leonardo actually disconnects from USB when the software runs so I presume the code is somehow using the serial port. Is there a way around this. I don't need the serial port but it'll make debugging tricky without the serial monitor.

I only need to talk to the MP3 trigger and can live without listening to it if that helps.

you need to initialize the hardware serial like this...

Serial.begin(9600);

then your Serial Monitor will work.

I'm trying to run the same sort of code on an Arduino Mega. When I upload my sketch (below) the result is a random mp3 and then the app just hangs. I reupload and a new random mp3 plays, not the mp3 requested in the code, then hangs after playing the first mp3. I'm using ports 0 and 1 off the Mega and powering the Trigger board off of the 5v and gnd off of the Mega.

"t" - tells the trigger to play a track

Here is a link to the source for the 't' reference: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Widgets/MP3%20Trigger%20V2.5%20User%20Guide%202012-02-01.pdf

Am I the only one who has experienced this?

Here is the code I've written and based on the user guide should be working:

#include <SdFat.h>

#include <MP3Trigger.h>

MP3Trigger trigger;

void setup() {

Serial.begin(38400);
}

void loop() {

trigger.update();

Serial.write('t');
Serial.write(003);
Serial.print("\nThis is track003");
delay(5000);

Serial.write('t');
Serial.write(007);
Serial.print("\nThis is track007");
delay(5000);

Serial.write('t');
Serial.write(010);
Serial.print("\nThis is track010");
delay(5000);

Serial.write('t');
Serial.write(012);
Serial.print("\nThis is track012");
delay(5000);

Serial.write('t');
Serial.write(015);
Serial.print("\nThis is track015");
delay(5000);

Serial.write('t');
Serial.write(17);
Serial.print("\nThis is track017");
delay(5000);
}

In your code "Serial.write" and "Serial.print" are sending data to the same pin. So the mp3-trigger gets also all the "...this is track..." and tries to interprete this as commands. This may cause unexpected results... :wink:

skip (delete) all the lines Serial.print("\nThis is track0xx");
in your code and try again

I removed the "\n - lines. Still the same problem. It only plays one track and not any of the tracks listed in the sketch. The user guide says a binary representation of the track number is to be set after the 't' command. When they say binary, do they mean 1s and 0s? I'm a serious 'newb' and I have tried everything I can think of and reread the guide several times. I'm sure there is a major clue in the user guide that is evading me...that is why I'm asking for a second pair of eyes to have a look.

Serial.write('t'); //alerting the MP3trigger that a track call is about to follow
Serial.write('003'); //with single quotes? =random track plays
Serial.write(003); //no quotes? =random track plays
Serial.write('11'); //binary "3" =no track plays

I removed the Serial.write('t') completely and the sketch only runs one random track.

Is there a command structure such as, Serial.write('t', 003):? that I could use, ('t', 3), something? idk

This code works for my setup: Arduino UNO and mp3-trigger

//  function test:  mp3-trigger test with Arduino UNO
//  
//  connections UNO --- mp3trigger
//     0  RX  ---  TX
//     1  TX  ---  RX
//       GND  ---  GND


void setup(){
    Serial.begin(38400);    // standard for mp3trigger
}
 
  
void loop()
{
    // play track 1. name on sd-card: 001.mp3
    Serial.print("t");
    Serial.write(1);
    delay(5000);

    // play track 5. name on sd-card: 005.mp3
    Serial.print("t");
    Serial.write(5);
    delay(5000);

    // play track 77. name on sd-card: 077.mp3
    Serial.print("t");
    Serial.write(77);
    delay(5000);

    // play track 121. name on sd-card: 121.mp3
    Serial.print("t");
    Serial.write(121);
    delay(5000);
}

I have it booting up and playing track one as a boot-up sound so I know the MP3Trigger board is initialized.
Is there any way someone can help with this code to make the serial connection wait for a command from a tablet? I used some code from http://arduino.cc/en/Tutorial/TwoPortReceive. The plan is to attach a Bluetooth TTL or WiFi TTL (Sparkfun RN-XV WiFly or ESP8266) unit to the Uno so that commands from the tablet/phone can be sent through the UNO and be converted to the binary commands needed.
```
**//  Script Function:  RobertSonics mp3trigger (v2) paired with an Arduino UNO
//  
//  Jumper Connections:   UNO  ------  mp3trigger (v2)
//             (UNO RX)     0  ------  TX
//             (UNO TX)     1  ------  RX
//             (Ground)   GND  ------  GND
//           (+5 volts)    5v  ------  USBVCC

#include <SoftwareSerial.h>
// BT/WiFi software serial port #1: RX = digital pin 10, TX = digital pin 11
SoftwareSerial portOne(11,10);

void setup(){
   Serial.begin(38400);    // Standard for mp3trigger
   portOne.begin(38400);   // BT/WiFi
 
// Play boot-up initialization track, track 001
   Serial.print("p");
   Serial.write(1);
   delay(1000);
   
}

void loop()
{
// By default, the last intialized port is listening.
// When you want to listen on a port, explicitly select it:
  portOne.listen();
  // while there is data coming in, read it and send to the hardware serial port:
  while (portOne.available() > 0) {
   char inByte = portOne.read();
   Serial.print('p');
   Serial.write(inByte);
  }
}**
```

Does anyone know if this MP3 trigger writes any of the pins HIGH whilst a track is playing so I can remove the delay function in my code and use a while pin = high wait kind of a set up instead?

The delays in post #3 are for demonstration purposes only. It's not a good idea to use it in "productive code".

Mp3 trigger and microcontroller are "talking" to each other via serial connection.
To start a track playing (let's say track 25) µC talks to the mp3 trigger via serial connection like this:

Serial.print("t");
Serial.write(25);

The mp3 trigger sends an answer. This could be:
a) An error message, if track 25 does not exist on SD card, it sends character 'E' (this is ASCII 69).
b) Or, if track 25 exists, it sends character 'X' (this is ASCII 88) AFTER playback of desired track has finished.
While playing the track, mp3 trigger sends nothing on serial connection.

With code like this you could evaluate this answer:

if (Serial.available())
{   byte inbyte = Serial.read();
    if (inbyte == 69)           // 69='E' Error   
       {   // do what should be done on error
       }
    if (inbyte == 88)          // 88='X' Track has finished
       {   // do what should be done after track has finished
       }
}

I have used mp3 triggers in some of my projects in the past and the communication via serial always worked pretty well.

Other options:
If you are searching for some pin to go HIGH while a track is playing: there is a "status" LED which goes on while a track is playing and off when finished (I think it is like this, I have no mp3 trigger here at the moment to test it, but I'm pretty sure that I remember correct Edit: It is exactly like this, I'v checked it). There is no "direct pin" from this LED to plug in something. But you could solder a cable to the LED and read the voltage to find out whether the LED is on or off.
Note: This status LED is also used to display other things on startup like "SD card ist OK" and so on, by blinking, so it could be confusing to know exactly what's going on :slight_smile: .

You can find further information in the mp3 trigger manual: http://cdn.sparkfun.com/datasheets/Widgets/MP3%20Trigger%20V2.5%20User%20Guide%202012-02-01.pdf

When I'm using code like this to trigger my tracks:

trigger.setup(&trigSerial);
  trigSerial.begin( MP3Trigger::serialRate() );
trigger.update();
  trigger.play(4);
   delay(2500);

how would i set the volume?

Looks like you are using some kind of library.
Please provide some more information about the library (link)!
Without this information noone can really help you.

If I should guess...:
There might be a file "MP3Trigger.h" in the librarys folder.
If so, take a look at it, you might find the keyword "volume" or "setVolume" or something similar.

My second guess: trytrigger.setVolume(0);
It might be that lower figures set to hight volume (because this is written in mp3 trigger manual), so 0 is the highest volume and 255 the lowest.