Skip navigation

Monthly Archives: May 2012

With the program now written and working is was now time to compete the final circuit and housing for the interface.  This will be done with Vera-borad and a sturdy plastic box.

It had been decied that an over-sized plastic box would be used as this would give me plenty of room to work with and would also mean that there would be enough room to connect the Arduino to the USB cable to allow for re-programming in the future.

Advertisements

Below is the program i have written to convert voltage readings into MIDI data.

The brief and general nature of the program is as follows:

The Arduino checks the current state of each flex sensor when initialised

The Adruino then checks the state of the flex sensors on a contunious loop

If the state of the flex sensors has changed (becomes bent) then the Arduino will send the intended MIDI note

There is a short delay before the Note-off command is sent

The duration of the note (or length of delay) is dependant on the Y axis of the Accelerometer

The pitch of the note is dependant on the X axis of the Accelerometer

(it is worth noting that the very last lines of the program are an essential part of the program however i’m not entirely sure what it does but the program does not work without it!)

 

Arduino Program

// Program to read analog inputs and convert this to MIDI data before sending to DAW via USB

// Name PINS

int F1 = A0;

int F2 = A1;

int F3 = A2;

int F4 = A3;

int AX = A4;

int AY = A5;

// Names for Actions

int flex1;

int flex2;

int flex3;

int flex4;

int accelx;

int accely;

int flexState1;

int flexState2;

int flexState3;

int flexState4;

int accelStatex;

int accelStatey;

// Runs once when initialised

void setup() {

Serial.begin(31250); // MIDI runs at this rate (31250)

pinMode(A0, INPUT); // Designating PINS as INPUTS

pinMode(A1, INPUT);

pinMode(A2, INPUT);

pinMode(A3, INPUT);

pinMode(A4, INPUT);

pinMode(A5, INPUT);

flexState1 = analogRead(F1); // read the initial state

flexState2 = analogRead(F2);

flexState3 = analogRead(F3);

flexState4 = analogRead(F4);

accelStatex = analogRead(AX);

accelStatey = analogRead(AY);

}

void loop(){

flex1 = analogRead(F1);   // read input value and store it

accelStatex = analogRead(AX);// read input from x axis

accelStatey = analogRead(AY); // read input from y axis

int mapped = map(accelStatex,600,200,60,127); // map x reading to between 60 – 127

int Ymapped = map(accelStatey,600,200,250,1000); // map y reading to between 250 – 1000 (1/4 sec – 1 sec)

if (flex1 < flexState1) {          // the flex state has changed?

if (flex1 < 395) {      // check if the flex sensor is bent

SendMidi (0x90, mapped, 120);// then send Note-on (Note-on, Note, Velocity)

}

delay(Ymapped); //hold note duration by y mapped (250-1000)

{

SendMidi (0x80, mapped, 120); // send Note-off

}

}

// Repeat will all flex sensors…..

flex2 = analogRead(F2);

accelStatex = analogRead(AX);

accelStatey = analogRead(AY);

int mappedF2 = map(accelStatex,600,200,60,127);

int XmappedF2 = map(accelStatey,600,200,60,127);

if (flex2 < flexState2) {

if (flex2 < 395) {

SendMidi (0x90, mapped +1, 120); // +1 to give a range of notes

}

delay(Ymapped);

{

SendMidi (0x80, mapped +1, 120);

}

}

flex3 = analogRead(F3);

accelStatex = analogRead(AX);

accelStatey = analogRead(AY);

int mappedF3 = map(accelStatex,600,200,60,127);

int XmappedF3 = map(accelStatey,600,200,60,127);

if (flex3 < flexState3) {

if (flex3 < 395) {

SendMidi (0x90, mappedF3 +2, 120);

}

delay(Ymapped);

{

SendMidi (0x80, mappedF3 +2, 120);

}

}

flex4 = analogRead(F4);

accelStatex = analogRead(AX);

accelStatey = analogRead(AY);

int mappedF4 = map(accelStatex,600,200,60,127);

int XmappedF4 = map(accelStatey,600,200,60,127);

if (flex4 < flexState4) {

if (flex4 < 395) {

SendMidi (0x90, mappedF4 +3, 120);

}

delay(Ymapped);

{

SendMidi (0x80, mappedF4 +3, 120);

}

}

// delay(5);

flexState1 = flex1;

flexState2 = flex2;

flexState3 = flex3;

flexState4 = flex4;

accelStatex = accelx;

accelStatey = accely;

}

void SendMidi (int cmd, int value, int vel) {

Serial.write (cmd);

Serial.write (value);

Serial.write (vel);

}

Once i had established the Note-On and Note-Off commands i now need to understad the MIDI note values.  Below is a link to a webpage that has the details of all MIDI note numbers that helped with this.

http://www.phys.unsw.edu.au/jw/notes.html

As i was developing the program it became aparent that i would need to undersatand some basics about the MIDI Protocol, the code that would be needed to send the apropriate Note-On and Note-Off commands.  Below is a link to a web page that helped me with the basics, however the protocols i required were Note-On (0x90) and Note-off (0x80)

http://hummer.stanford.edu/museinfo/doc/formats/midi/

Now that it is possible for Ableton Live to detect my interface as a MIDI Input i could begin to write the program for the Arduino Programming environment that would convert the voltage data into MIDI data.  The following webpages gave me some ideas that i developed and built on.

http://arduino.cc/en/Tutorial/Midi

http://arduino.cc/playground/Main/MIDILibrary

http://itp.nyu.edu/physcomp/Labs/MIDIOutput

In one of my previous posts i mentioned that i could not get my Digital Workstation to recognise my interface as a MIDI Input.  This turned out to be the fact that my Lap-top does not like having both the Arduino’s and the MIDI’s USB cable connected at the same time.  This lead to the need for an external power supply.

After consideration it was decided that a 9v battery would be used, this meant the addition of a power supply and a rocker switch to isolate the battery.  With this addition it was now possible to identify my interface as a MIDI Input.

 

Its been a while since my last post so i’ve got a lot of info to update.

The last post outlined my attempts to transfer data from my glove to a Digital Workstation.  Since then i have had a great deal of success and now have a working interface.

Previuosly i had been thinking about either using MaxMSP or using the Arduino Programming environment to convert voltage data into MIDI data.  After a great deal of experimentation and a fair deal of help from my fellow students i have now chosen to use the Arduino to convert the data before sending this to Ableton Live.