Go Down

Topic: Sparkfun MP3 Trigger and serial monitor (Read 324 times) previous topic - next topic

nickjb

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

Using .h file from here: https://github.com/sansumbrella/MP3Trigger-for-Arduino

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

My basic test code:
Code: [Select]
#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.

borland

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

Code: [Select]
Serial.begin(9600);

then your Serial Monitor will work.

K3vin

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);
}

uxomm

#3
Nov 28, 2014, 11:03 pm Last Edit: Nov 29, 2014, 01:40 am by uxomm
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...  ;-)

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

K3vin

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


uxomm

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

Code: [Select]

//  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);
}



Go Up