Saturday, March 10, 2012

Midi controller: Phase 1

This little project has been on the sidelines for awhile, and I'm slowly picking it up. Idea is to build a Wind MIDI controller to play/record sampled flutes, trumpets etc. First up, is to actually get the midi working between the physical buttons and the synth.

For a midi interface, I bought one of those uber cheap midi in/out usb cables off ebay, £5 I think. Sweet little class compliant device that provides midi input and output via DIN5 connectors.

On the arduino's hardware side, I got a female DIN5 connector, and wired it up per the website. The test code worked right off, and I continued work on getting input with buttons - which was uber straight forward. Active high switches were simply wired in to 3 digital inputs, easily accessed via digitalRead()

Software wise, there is a nifty MIDI Library for the arduino that sets up all the serial comms necessary, and abstracts much of the note sending functionality required.

Code wise, after the initial "sending several thousand note-on commands to the synth" and getting some nice machine gun piano sounds, I figured out that the input data had to be sent once while the key is pressed down, and then a note off sent when it is released.


int val=0; // used to store state of switches.  
int isNoteOn[3] = {0,0,0}; // Used to keep track of whether notes are currently being pressed down.

void setup() {
  // put your setup code here, to run once:


void loop() {
  // Step one, sample all the inputs
  // Step two, check to see switch is active and not playing, then switch them on.
  for (int i=0; i<3; i++)
    val = digitalRead(i+8);    

    if (val==1 && isNoteOn[i] ==0)
        isNoteOn[i] = 1;
    if (val == 0 && isNoteOn[i] == 1)
        MIDI.sendNoteOff(i+60,0,1) ;
        isNoteOn[i] = 0;

The next stage is to include the pressure sensor (MPXM2010GS) data to control the note on/off events, as well as to use the pressure detected as the velocity for the note - at the moment the buttons all send a value of 63, which is a fixed midway velocity.

Sadly, this will actually take a little bit more effort on my part - the sensor actually delivers data at 25mV at full scale - the arduino's ADC is 10bit over 5 volts, which gives 4.9mV resolution steps. I really need to read the data sheets more carefully. Hence, I need an amplifier with a gain of roughly 200 to bring Vfss from 25mv to 5v.

The sensor also requires Vcc 10-16v, so... a small step up voltage regulator will probably be required to power it.

Also, the output from the pressure sensor is a V+/V- output, so I'll need a differential amplifier. Probably something like a TLC272 op-amp, which supposedly works well with single rail supplies - I could take it directly off the Arduino's board. I do not want to mess about with dual rail power supplies!

There are also the physical aspects of getting silicone tubing, hose clips, Y connectors etc. Hopefully another week or two and I'll get a prototype wind controller working.

No comments: