Using MP3 trigger with Picaxe

temple

New Member
I am trying to use an MP3 Trigger device for a project I'm building.

https://learn.sparkfun.com/tutorials/mp3-trigger-hookup-guide-v24?

I can activate a limited number of sounds using individual pins. However, I would like to use the serial option to use as many mp3 sound clips as I want.

I am stuck w.r.t communication between the picaxe and the mp3 trigger device.

Any help would be greatly appreciated
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,

That link is broken for me, perhaps due to missing characters in the middle. :(

In what way are you "stuck" (with serial communication between the PICaxe and the MP3 player)? Perhaps if you specify/link the particular PICaxe/MP3 player and/or the project board that you're using, then we may be able to help more.

Cheers, Alan.
 

temple

New Member
Thanks, Alan

I'm a total newb when it comes to using serial protocols.

I found an example of some code used for the VMusic2 Player (which is no longer available).

I don't know if I can use an adaption of this with the MP3 Trigger from https://learn.sparkfun.com/tutorials/mp3-trigger-hookup-guide-v24?

Example

init: high b.6 ; initialise for t9600 protocol
pause 500 ; allow 500ms to wake-up

main:
if pinc.0 = 1 then do_play ; play switch pushed
if pinc.1 = 1 then do_stop ; stop switch pushed
goto main

do_play:
pause 10 ; short debounce time
if pinc.0 = 1 then do_play ; wait until switch released
serout b.6,t9600,("vpf 1.mp3",CR) ; send play 1.mp3
goto main

do_stop:
pause 10 ; short debounce time
if pinc.1 = 1 then do_stop ; wait until switch released
serout b.6,t9600,("vst",CR) ; send stop command
goto main
 

inglewoodpete

Senior Member
I think you need to re-read the section "Serial Control Protocol". It indicates the default baud rate is 38.4kbps and the command protocol is quite different to what you have posted above.
 

Jeff Haas

Senior Member
Here's a page with Arduino code (in C++) that explains it in brief, a bit clearer than the earlier linked page.

Looks pretty simple!
 

AllyCat

Senior Member
Hi,

Yes, the kit linked by Techical would be a much easier (and probably cheaper) way to proceed. It seems that you already have the "MP3 trigger" board, but if you don't already have the PICaxe, then I would certainly recommend that kit.

However, if you are already committed to the hardware, then the starting point from the Sparkfun information is:

"Serial Control Protocol

The MP3 Trigger comes with a full duplex 3.3-5V serial TTL interface that allows for control of all the MP3 tracks (up to 256) on the microSD card as well as volume, and for monitoring input trigger activity. You can use an FTDI Basic or connect to any serial interface that uses the format: 8-bits, 1-start, 1-stop, no parity, flow control = none. The serial port baud rate defaults to 38.4kbps, but can be changed using the initialization file. All commands to the MP3 Trigger are 1 or 2 bytes in length.

1-byte commands are upper case ASCII characters. 2-byte commands start with an ASCII character. Those starting with an upper case character use an ASCII value (‘0’–‘9’) as the second byte. (These commands can be typed on a keyboard.) 2-byte commands starting with a lower case character require a binary value (0 – 255) as the second byte."


Basically, that says you will need to either reduce the baud rate to (say) 2400 baud using an "initialisation file", OR run the PICaxe at a higher frequency. For the latter case, I believe you will either need to use a SETFREQ M32 and then SEROUT commands with a T38400_32 mode parameter, OR use the HSEROUT command (for the appropriate pin). You don't need the "FTDI accessory" to connect it to a PICaxe.

Cheers, Alan.
 
Last edited:

afb

Member
Hi Temple

I did a mp3 Trigger project in 2012 using a PICAXE 08M2 communicating by serial. I've copied the initial part of the code which gives some good pointers as to what is necessary to get it to work and operating considerations to take on board in developing your project.

The magic lines of code to communicate look like this:- in my case 'kount' is a variable which determines which track is needed to play

select case kount
case 1
serout C.2,T2400,("t",1) 'track 001
case 2
serout C.2,T2400,("t",2) 'track 002

etc

end select

mp3 trigger.jpg


'======================================================================================
'
' S I X T E E N C H A N N E L M P 3 T R I G G E R
'
'======================================================================================
' version 1.0 5th November 2012 © A.F.Bond 2012
'======================================================================================
' This program drives a Sparkfun MP3 TRIGGER v2 module to produce any one of sixteen
' sounds, arranged in two banks of eight on opposite throws of the transmitter joystick.
'
' Selection occurs by the user repeatedly 'jabbing' the joystick in the appropriate
' direction - three times for sound three, five times for sound five etc. On the chosen
' jab the user holds the joystick pressed to assert the sound. When the sound is heard
' to begin to play the joystick can be released. However, if the joystick is found to
' still be held when the sound has finished playing, the sound will be repeated - so
' for example, three blasts of a horn could be accomplished this way.
'
' The transmitter frame rate is used to time the joystick excursions and determine
' whether they are 'jabs' or a 'hold'. When a 'hold' is detected, the state of the jab
' counter determines which of the eight sounds related to that direction of jab is
' required. The jab counter is reset whenever a sound has been asserted or if the
' joystick has been in the centre position for more than a second (which far exceeds
' the regular jabbing rhythm pauses). The transmitter frame rate is measured during the
' start-up sequence and the jab/hold timing intervals adjusted accordingly.
'
'
' Users should arrange the sounds to be accessed in order of importance - for example a
' horn sound (when used for warning of imminent collision) should be activated by a
' single 'jab' rather than for example 7 'jabs'. Also consider assigning one sound to
' be a short period of silence, the effect of which is to act as a 'cancel' command for
' any long duration sound (such as background ambience) that is currently playing.
'
' The user may also set the volume level of the device duration normal operation by
' giving nine 'jabs' and a 'hold' which selects a seventeenth track (which ideally
' will last for 10 seconds or more) and all the time the 'hold' is maintained the
' volume gradually increases or decreases depending on the direction the joystick was
' operated. The joystick is released when the desired volume is attained and this
' setting is stored in EEPROM.
'
' The MP3 TRIGGER module is controlled by using its serial port at 2400 baud and this
' condition should be set up in an initialisation file named MP3TRIGR.INI which must be
' located in the root directory of the micro SD card. In the absence of this INI file
' the unit defaults to 38400 baud. The INI file contents must be as follows:-
'
' #BAUD 2400
' #STAT 1
'
' The latter command (#STAT1) configures the TRIG18 connection to become a status
' output rather than a trigger input and this status tells the micro-controller
' when a sound has finished playing (so that in the case that a repeat is required it
' can be re-triggered). If this command is not present in the INI file, then TRIG18
' will default to an input and deprived of status feedback the micro-controller may
' not function correctly.

' The firmware of the MP3TRIGGER should also be upgraded to the latest version (v2.53
' at the time of writing) which can be downloaded from http://makerjam.com/support.
' You may have only just bought the unit but how long has it been in stock with an
' earlier firmware version installed? Amongst other things the latest version
' (reportedly) fixes a bug whereby occasionally at start-up, although tracks can
' be triggered, they play at zero volume, requiring a power cycle to correct the
' situation.
'
' From v2.4 onwards the file naming convention also changed to a more user friendly
' format, so again a firmware upgrade is recommended to ensure the information on
' file naming given below will work with your unit.
'
' File names must begin with a three digit number (using leading zeros) relating to
' the trigger channel required. Whilst numbers 001 to 255 are valid, in this 16
' channel implementation, users must employ numbers 001 to 016. The remainder of the
' filename can be anything (dots excluded). For example the following are both
' valid filenames for trigger channel 14 "014TRACK.MP3" and "014 Dive Alarm.mp3"
'
' There are two more special cases :- a file name beginning 255 will play immediately
' after power-up to signify that the unit is ready for use. A file name beginning 254
' should be assigned to a longish sound sample that is to be used for setting the
' volume.
'
' If files in the range 017 to 253 are loaded, they may be accessed manually by using
' the MP3 TRIGGER's 'jog' switch. The current design *could* be extended to access all
' 256 available sounds by the jab/hold technique, but it was felt that counting much
' beyond 8 jabs either way gets rather impractical.
'
' Even numbered files are accessed from jabs in one direction of the joystick and odd
' numbered files from jabs in the opposite direction.

' Note that if users have "hide known file extensions" option turned on in their file
' manager then typing in the following to rename a file "001 6 inch gun.mp3" will
' actually result in a file named "001 6 inch gun.mp3.mp3" which will not play!
' In this case just type "001 6 inch gun" and the original mp3 file extension will be
' appended automatically.
'
' mp3 tracks should be recorded at 128kbps or less (some reported playback issues at the
' specified max rate of 192kbps)
'
' Note the "earthy" side of the audio o/p jack socket sits at 1.25v DC and connecting
' directly to an amp whose 0v is common with the RC system's 0v will short the audio
' biasing and no sound will be heard. In this case use a 47uF capacitor in the 0v feed to
' the 3.5mm jack plug (+ve end to the mp3 trigger)

'======================================================================================
'


'======================================================================================
' PICAXE 08M2 CONNECTIONS
' leg 01 (Vdd) +5v
' leg 02 (serial in) connect to 0v
' leg 03 (IN C.4) rx input
' leg 04 (IN C.3) TRIG18 - configured as play status by ini file
' leg 05 (OUT C.2) serial out to RX of MP3TRIGGER
' leg 06 (C.1) unused
' leg 07 (OUT C.0) LED drive
' leg 08 (Vss) 0v
'======================================================================================
 

afb

Member
DOH ! How stupid can I get ! However when kount gets to my volume setting option it DOES need a special case - having started the volume adjust track playing all the time the joystick remains asserted, at quarter second intervals I send

serout C.2,T2400,("v",volume) ;

with limits of 30 max and 4 min for the volume variable. 30 is spec max, low level of 4 rather than 0 so the user can't convince himself it isn't working.
 
Top