Monday, July 18, 2016

Filled Under: , ,

MIDI Note Player

Arduino Arduino UNO R3 library

This tutorial shows how to send MIDI notes from an Arduino to a MIDI instrument connected through the standard 5 poles DIN cable.

MIDI, the Musical Instrument Digital Interface, is a useful protocol for controlling synthesizers, sequencers, and other musical devices. MIDI devices are generally grouped in to two broad classes: controllers (i.e. devices that generate MIDI signals based on human actions) and synthesizers (including samplers, sequencers, and so forth). The latter take MIDI data in and make sound, light, or some other effect.

MIDI is a serial protocol that operates at 31,250 bits per second. The board built-in serial port (all of them on the Mega as well) can send data at that rate.

MIDI bytes are divided into two types: command bytes and data bytes. Command bytes are always 128 or greater, or 0x80 to 0xFF in hexadecimal. Data bytes are always less than 127, or 0x00 to 0x7F in hex. Commands include things such as note on, note off, pitch bend, and so forth. Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, amount of pitch bend and so forth. For more details, see the MIDI specification or one of the many MIDI Protocol Guides on the Web.

MIDI data is usually notated in hexadecimal because MIDI banks and instruments are grouped in groups of 16.

For more see this introduction to MIDI or this example.


Step 1: What You Need?

1 x Arduino Board ( Arduino UNO R3 used in this tutorial.)
2 x 220 Ohm Resistor 
1 x Female MIDI Jack
1 x USB Type B cable 
Male-to-Male Jumper Wires


Optional 
MIDI Enabled Device (For Testing)


You can buy Arduino Compatible UNO Ultimate Starter Kit / Learning Kit at here.

Don't have components? Don't worry. Just click the component's name. 


Step 2: Build Your Circuit.

All MIDI connectors are female, by definition of the MIDI spec. Here's how to wire the connector to the board:

  • MIDI jack pin 5 connected to Digital pin 1 through a 220 ohm resistor
  • MIDI jack pin 2 connected to ground
  • MIDI jack pin 4 connected to +5V through a 220 ohm resistor







Step 3: Upload The Code.

1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.

2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.

Select the right port: Tools >> Port >> Select the port number.

3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 04.Communication >> Midi


Click press the "upload" button (see the button with right arrow mark).

Attention If you're using a board with ATmega32U4 like DUE or Leonardo, please replace Serial with Serial1 in the sketch below.


Unknown

Author & Editor

My Robot Education Sdn. Bhd. (Robotedu.my) was founded in 2015 as the first robotics education centre in Malaysia to provide Arduino-based robotics courses for youths. Our vision is to be able to provide robotics education to every youth in Malaysia.

0 comments:

Post a Comment

 

  • Copyright © Arduino Tutorial ™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.