Monday, February 02, 2009

Dealing with MMC Sysex Messages in Arduino

Someone has recently asked me whether it is possible to deal with MMC messages in Arduino. In particular, an output pin should be high after the Arduino has received a PLAY message, and low after a STOP message. There should also be an inverted pin that does the opposite logic (low upon PLAY, high upon STOP).

MMC Play and Stop Commands
Let's have a look at the MMC commands for play and stop. Each MMC message takes the form of:

F0 7F deviceID 06 command F7

where deviceID is a number between 0 and 127 (with 127 being a blanket call ID) and command relating to a byte from the following list. This fifth byte determines which command it is that is being received.

Command byte:
01 Stop
02 Play
03 Deferred Play
04 Fast Forward
05 Rewind
06 Record Strobe (Punch In)
07 Record Exit (Punch out)
08 Record Ready
09 Pause
0A Eject
0B Chase
0F MMC Reset
40 Write
44 Locate/Go to
47 Shuttle

So, in other words, if the Arduino receives the byte sequence: F0 7F 00 06 02 F7, then this indicates an MMC play command. If the 02 is 01, the command is stop.

Arduino Hardware

You will need:
• 1 x 220Ω resistor
• 1 x 110kΩ resistor
• 1 x 3.3kΩ resistor
• 1 x 1n4148 diode
• 1 x 4n25 optocoupler
• 1 x Arduino board or Freeduino (et al) equivalent
• 1 x 5 pin din MIDI connector

Connect pin 4 of the MIDI connector to one end of the 220Ω resistor. Connector the other end of the 220Ω resistor to pin 1 of the 4n25. Connect pin 5 of the MIDI connector to pin 2 of the 4n25. Connect the 1n4148 diode between pins 1 and 2 of the 4n25, with the marking going towards pin 1. Connect pin 6 of the 4n25 to ground via the 110kΩ resistor. Connect pin 5 of the 4n25 to 5V via the 3.3kΩ resistor. Connect pin 4 of the 4n25 to ground. Connect Arduino RX (pin 0) to 4n25 pin 5.

A few notes:
• MIDI pin 4 might be MIDI pin 5 and vice versa, I can't remember.
• You might like to add a 10uF and a 0.1uF capacitor between ground and 5V
• You might not need the 220Ω resistor.
• Arduino Pin 2 is the normal output pin
• Arduino Pin 3 is the inverted logic output pin

Arduino Code
The Arduino code has not been tested, but should work (maybe?). I am not currently in a position to be able to test this code, but I will do so once I get a chance.

Download it here:


dwan said...

You're right about the midi pins :
Midi pin 4 to 220R to opto pin 1
Midi pin 5 to opto pin 2.

I'll only add that i never got this circuit to work until I removed the 1OOk-ish resistor going from opto's pin 6 to ground.

Sebastian Tomczak said...

Hi Dwan, hmm interesting. I have never needed to remove the 110k resistor but I have had to remove the 220Ω one before... also I know that there are a number of people that have had lots of luck with this circuit, and some that haven't...

RAs B said...

well question now...How would it be to send this same data through midi( implement basic transport control into old mixers, for example_?
Id appreciate if u could let me know, or give me an idea at least !!