Midi Controllers

Introduction

MIDI is a standard protocol that in this project is going to be used for controlling a set of music parameters in a musical software application, e.g., using Pure Data or Ableton LIVE.

In this project the students will learn how to create a wireless MIDI controller using a microcontroller like arduino, and a communication device based on XBee S2.

Materials

The basic necessary hardware for Option 1

  • microcontroller arduino FIO, or arduino UNO.
  • communicator via Bluetooth,
  • communicator via ZigBee, XBee S2
  • Xbee explorer, that sends serial messages via USB port to the computer.
  • accelerometer, ADXL of two axis (X and Y).
  • piezoelectric sensor, as the used in Knock example.
  • switches and push buttons for detecting when the dancer pushes the sensor.

This is the basic necessary sotfware:

  • arduino IDE, for programming arduino FIO.
  • XCtung, for configurating Xbee S2 modules (Windows and MAC only; LINIX would have to use Wine).
  • Hairless Serial to MIDI converter, for connecting serial MIDI messages to MIDI inside the computer.

How To

The process has three main steps: hardware configuration, software programing and control configuration.

Hardware Configuration

Getting used with Arduino and Sensors.

As a beginning, you should learn how to connect different sensor to any arduino controller and how to read the values of each sensor. We are going to work with these sensors:

The student must test all of these sensors and print in the Serial Console the range of each sensor (maximum and minimum values).

The case of Arduino FIO with an accelerometer

Arduino FIO allows to connect the XBee module directly as it comes with a Xbee slot.

For powering the microcontroller an external battery has to be used. Be careful of the input voltage of the battery. A standard voltage is around 3.3V. The accelerometer could be powered with such voltage, even though its nominal voltage is 5V. The only limitation would be in the accuracy of the sensor.

Notice also that there is a battery holes that are parallel to the power slot of the board. Powering has to be connected in such holes.

The accelerometer has 5 pins:

  • Vcc has to be connected to 3.3V output from the arduinoFIO board.
  • GND has to be connected to GND in the arduinoFIO board.
  • X, Y and (if 3-axis acc) Z, would be connected to Analogous inputs: A1, A2 and A3.

X, Y and, if the accelerometer is kind of 3-axis, Z give a signal whose voltage is inside the range [GND+3%, Vcc-3%] and it is analogous to the movement in the respective axis.

Software Programming. Sensor reading and MIDI writing

Software has two different sections: sensor reading and MIDI messages delivery.

Input: Sensor Reading

Sensors reading would use the function analogRead. This function gives digital values between 0 and 1023 that are analog to voltage inputs between [0, VREF]. Therefore readings for X and Y axis would be as follows:

//  readSensors:
long int accX = 0;
long int accY = 0;
accX = analogRead( X_ACC_PIN ); // 0 - 1023
accY = analogRead( Y_ACC_PIN ); // 0 - 1023

However, the readings are not calibrated and each sensor can give different values for the same angles. Also readings have to be adapted to the range of the output of the signal. Therefore first of all, it is necessary to measure the range the accelerometer is giving. This type of debugging is made using serial writings:

Serial.print( "X = " );
Serial.print( accX );
Serial.print( "   Y = " );
Serial.println( accY );

When executed, in a serial monitor it is possible to see the values of the accelerometer readings. Move the accelerometer along its angle range and take note for the minimum and maximum values the accelerometer gives. These values would be used to "remap" the readings from one range to the output range. For instance if the minimum (when axis is vertical looking down) is 453 and the maximum (when axis is vertical looking up) is 574 the input range is [453, 574].

Output: MIDI writing

There are many MIDI possible messages the controller can send. It depends on the purpose of the program what message to send. MIDI can send a noteOn, noteOff, a Control Change for a continuous controller (CC) or a Program Change (PC), a BPM clock setting, and so.

This simple example shows how to do a CC on channel 1 using the values of the accelerometers. Following the MIDI protocol specification CC values are in the range [0, 127], therefore it is necessary to adapt the measured values from the accelerometers to such values. This is made using the map function as follows:

accX = map(accX, 453, 574, 0, 127);  // re-scale accelerometer 453-574 to 0-127

MIDI messages are just written through the serial port as bytes packages. The MIDI CC message is implemented in this function:

void controlChange( int controller, int value ) {
  Serial.write( 0xB0 ); // channel 1
  Serial.write( controller );
  Serial.write( value );
}

Communication via Zigbee Series 2

Introduction to Zigbee Modules

The purpose of the controller is to be wireless. As explained in this guide by sparkfun shop, Xbee modules are mainly of two types: S1 and S2. Xbee S1 modules, or just Xbee, are the oldest ones and are quite easy to configure. In the other side, they do not allow to configure complex sensor nets as it does Xbee S2 modules.

Xbee S2 configuration

Xbee S2 are more complex in the configuration, and it is less easy to find examples of using them with arduino boards, but they allow complex net configurations and are cheaper than Xbee (S1). In the official ardunio website it is possible to find instructions on how to configure Xbee S2 using X-CTU in windows for a Xbee on an arduino UNO.

There is also another clear example here

In the Digi website there are basic examples for getting started.

Xbee S2 are designed to form networks with star, cluster tree or a mesh topologies. It depend how you configure each Xbee S2. The roles of a XBee are: coordinator, router or endpoint. In all types of nets it has to be one and only one coordinator.

Radios which share the same PAN ID can communicate each other.

In our project, there are two Xbee S2 modules: one in the arduino FIO, and another in a Xbee-explorer board that is connected to the computer.

Each Xbee has to be configured separately using XCTung software. The net we want to configure has only two nodes: a Controller and a Router.

Control Configuration

There are two types of control appropriate for a MIDI controller. First is based on a Combinational System, where the outputs just depends from the inputs. Second is based on a Sequential System, where the outputs depends from the inputs and the state of the system.

The most simple control configuration is to do a Continuous Controller (CC) based on the values of the accelerometer. This case is very similar to any standard MIDI controller based on a keyboard with knobs. Here, the knobs are replaced by the accelerometer.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License