Sunday 29 January 2012

1000th Visitor!!!

Notes and Volts has just received its 1000th visit!! That's about 950 more than I was expecting when I started this blog. The viewer was located in France and stopped by to read the new Arduino Midi post. So, to this person and all the folks who have checked out my little space on the web, I give my sincerest Thanks. My next milestone....have someone actually leave a comment... Dare to dream..

Dave.

Saturday 28 January 2012

Fun with Arduino - Midi Input Basics

Midi In - "Hello World!"

** This article has been updated! Check out the NEW IMPROVED VERSION. **

Check out this video for a detailed Analysis of the Midi Circuit.

For a real world look at this circuit in action, check out the NaV-1 Arduino synth construction series.


Have you ever been working on a Arduino project and suddenly thought 'This thing could really use a MIDI Input'! This exact thing just happened to me. Not wanting to re-invent the wheel, I began searching around for a Library that would help. I came across the Arduino Midi Library which seemed to fit the bill. It took me a while to actually get the thing going, so I thought I would write a quick post outlining the steps to get a simple test circuit working. The following program and circuit will simply Flash the LED connected to Pin 13 on the Arduino Board when you press a note on a Midi Keyboard. But, that's really all you really need to confirm that you are correctly receiving Midi commands with your Arduino.

The Midi In Circuit

Flashing LED means you Win!!

The Arduino Midi Library

First go to this Link and download the Arduino Midi Library files.

Unzip the downloaded folder. There are two folders inside. For Windows, copy the folder called "MIDI" and paste it into your Arduino "libraries" folder. Mine was located inside the "arduino-0022" folder. Quit and restart your Arduino IDE program. Go to the Menu and open Sketch > Import Library. You should see "MIDI" as one of the choices.

Copy and paste the code at the end of this article into a new Sketch. The code is commented, so give it a quick read through.

Here are some of the key commands:

MIDI.begin(MIDI_CHANNEL_OMNI);
This initializes the Midi Library. The MIDI_CHANNEL_OMNI parameter sets the library to listen to all Midi Channels. MIDI.begin(2) would set it to listen to Channel 2 only.

MDI.setHandleNoteOn(MyHandleNoteOn);
This is an import command! The Arduino Midi Library uses something called 'Callbacks'. When a Midi event occurs, the Library will Call a function to handle it. This command tells the Library to call the 'MyHandleNoteOn' function when a 'Note On' Midi event is detected. There are many callback functions in the Library to handle the many types of Midi events (Clock, Pitch Bend, Program Change, Etc..). Use the MIDI.set... command to point to the functions you require.
 
void MyHandleNoteOn(byte channel, byte pitch, byte velocity)
This is the function I created to be called when a Midi Note On event is detected. This is the 'meat' of your program.  In this test program, I just have it flash the LED on the Arduino board. But you could just as easily have it play a note on your home made Synth circuit, Flash a spotlight on your Midi controlled lighting rig, or even command your Midi controlled Robotic Gorilla to enter 'Rampage' Mode. The sky is the limit.

MIDI.read();
This is the only function in the main loop of the program. It just checks the input buffer for any received Midi commands and passes them to the correct function.


The Hardware

The MIDI standard spells out the circuit that should be used for a MIDI INPUT so lets look at that first.

Arduino Midi In Circuit Schematic

Midi In Circuit on the Breadboard
This very simple circuit uses a 6N138 optocoupler chip. This device basically electrically isolates your circuit from the incoming Midi signal. The 1N914 diode protects the chip from an incorrectly wired Midi cable. Plug the output of the optocoupler (Pin 6) into the RX (Pin 0) socket on your arduino board. Note: Be sure to correctly identify pin 4 and 5 on the Midi In Jack.

Also note that the RX/TX pins and the USB Port on the Arduino Board share the same signals. So, you will need temporarily remove the wire from the RX Pin 0 on the Arduino Board to upload a program. Then remove the USB Cable from the computer and replace the RX wire when you run the program with a Midi Input.

  
That's really all there is to it! Connect the Midi Out port on a Midi Keyboard to the Midi In Jack on your Arduino. If the little LED next to Pin 13 on the Arduino Board flashes when you hit a key, you are correctly recieving the Midi Data. Have fun!

For a real world look at this circuit in action, check out the NaV-1 Arduino synth construction series.

Copy the following code and paste into a new Arduino Sketch:

#include <MIDI.h>  // Add Midi Library

#define LED 13    // Arduino Board LED is on Pin 13

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
  digitalWrite(LED,HIGH);  //Turn LED on
  if (velocity == 0) {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
    digitalWrite(LED,LOW);//Turn LED off
  }
}

void setup() {
  pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
  MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to channel 2 notes only.
  MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
  // tells the Midi Library which function I want called when a Note ON command
  // is received. in this case it's "MyHandleNoteOn".
}

void loop() { // Main loop
  MIDI.read(); // Continually check what Midi Commands have been received.
}

Monday 16 January 2012

Chromatic Side-slipping with the Pentatonic Scale

An easy way to step 'Outside'

Over the years, I have come to terms with the fact that when it comes to guitar playing (and life in general), I'm pretty much a 'path of least resistance' kind of guy. That's why I love tricks that take a simple concept, and turn it into something cool. In this lesson, we are going to take a standard Pentatonic Minor Scale and take it 'outside'.
 
For those of you who aren't familiar with the idea of playing outside, it is the concept of playing notes over a chord that are traditionally considered to be 'wrong'. We will access these outside notes by 'side-slipping' the scale one semitone higher. It is also possible to move the scale down a semitone as well, but to my ears, moving up sounds nicer.

Am Pentatonic Scale. For Bbm, start pattern at 6th Fret

When you play an Am Pentatonic scale over an Am chord, you end up with the Root, flat 3rd, 4th, 5th, and flat 7th of the chord at your disposal. These are all very stable notes so you are almost guaranteed not to hit a clunker. But when you slip to Bbm, all bets are off! We are now playing the Major 3rd, flat 5th, Major 7th, flat 9, and 11th of our Am chord. These notes are interesting to say the least. Don't worry if these terms are unfamiliar. Just think, Am scale = Normal - Bbm scale = Outside.




In the above video, I attempt to improvise some lines over the Am backing track, dividing my phases into four bar chunks. I try to keep within the Am Pentatonic Scale for three and a half bars, then slip into the Bbm Pentatonic Scale for the last two beats of bar four. You can hear how the tones get much more interesting during the Bbm sections. But since the notes quickly resolve back to Am on beat one of the next bar, your ear doesn't really hear the notes as being 'wrong'. As an experiment, see how long you can stay on the Bbm scale before it starts sounding questionable.

It's really all about the attitude of your playing. If you do it half heatedly, it will just sound like a mistake. But if you confidently slip into those outside notes, then decisively resolve back like you meant to do it, people will think you are a genius! Have fun!

Download the practice backing track Here

Sunday 1 January 2012

Happy New Year from Notes and Volts

Happy New Year and a big thanks to all the folks who visited in 2011!

I've got a lot of new things in the works for 2012 including DIY Synth projects, some Arduino stuff, and tips on how not to electrocute yourself.

Notes and Volts is now on Twitter. Click on This Link or go to http://twitter.com/#!/NotesAndVolts to follow!

Have a great year!

Dave.