Академический Документы
Профессиональный Документы
Культура Документы
Air Piano
Professor
Sang-Hoon Lee
Students
1
Table of Contents
Introduction................................................................................................................ 3
Methodology - Hardware............................................................................................ 4
Microcontroller Module............................................................................................ 4
Keyboard Module..................................................................................................... 5
Control Module........................................................................................................ 6
Prototype Costs....................................................................................................... 8
Methodology - Software.............................................................................................. 9
MIDI Protocol........................................................................................................... 9
MIDI Messages......................................................................................................... 9
MIDI Digital Audio Workstation (DAW)...................................................................11
Code...................................................................................................................... 11
Results...................................................................................................................... 15
Conclusion................................................................................................................ 16
Bibliography............................................................................................................. 17
2
Introduction
3
Methodology - Hardware
Microcontroller Module
4
Microcontroller ATmega32u4
Operating Voltage 5V
PWM Channels 7
EEPROM 1 KB (ATmega32u4)
Keyboard Module
Figure 3 - keyboard
5
Figure 4 - photoresistor circuit
Figure 5 - photoresistor
Control Module
6
Figure 6 - control module
Figure 7 - accelerometer
7
The ultrasonic sensor used in this prototype was the PING by parallax.
It is a simple pulse in/pulse out device that measures distance on a range of
2 cm to 3 m, without contact. Its convenience also resides in the fact that it
doesnt require special light conditions and that it uses only one I/O digital
pin port on the microprocessor. Attached on the control module, the sensor
can be used by pointing it to a flat surface and bringing the module nearer or
farther away from it.
8
Figure 8 - ultrasonic sensor
Prototype Costs
We estimated the components cost as shown in Table 2.
9
Methodology - Software
MIDI Protocol
Before the creation of MIDI protocol, many other proprietary standards
were used to interface between different digital instruments. They allowed
the communication and the exchange of messages between two instruments
of the same brand, but failed to do that when is dealing with devices that
used different protocols.
MIDI Messages
MIDI messages are delivered through serial port, and are 8 bit (1 byte)
long. There are two types of message: status messages and data messages.
The MSB (most significant bit) of the status messages is 1. The next 3
bits are the command and the last 4 is the channel the message is being
sent to. Depending on the status message, 0 to 3 data bytes are expected to
follow it.
The MSB of the data messages is 0. The next 7 bits are the data value
for the message. You can send 128 different values using one data message.
10
Figure 9
The two status messages used by the system are the note on and the
control change message. They are sent on the channel 1 (for example) and
you can see their structure in Table 3.
11
MIDI Digital Audio Workstation (DAW)
Since the MIDI messages dont carry any sound information, in order to
test and play music, a MIDI instrument is needed. For this project, the
Hairless MIDI to Serial Bridge [10] computer driver was used to interpret the
MIDI messages received through the serial port and send it to Reason [11], a
DAW, for the messages to be played in one of its MIDI software instruments.
Code
The Arduino Micro is programmed using the C language.
The photoresistor ports are the 12 analog ports of the microcontroller. The
initial values for the sensor measurements are zero.
// Photoresistor ports
int light[] = {A6, A7, A8, A9, A10, A11, A5, A4, A3, A2, A1, A0};
int lightValue[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
The MIDI protocol uses natural numbers from 0 to 127 to represent each note,
so that one unit stands for one semitone. The central piano C note number is
60. The array noteValue stores the current state of each note, pressed (1) or
not pressed (0).
// Ultrasonic sensor
int ultra = 7, ultraValue = 0x45, duration, velocity;
// Accelerometer
int accelX = 5, accelY = 3, valueX = 0, valueY = 0, pulseX, pulseY;
12
We read the accelerometer and ultrasonic sensors once every 100 iterations
to decrease lag when transmitting the signals though the serial port.
// Photoresistor calibration
int calibrated = 0;
void setup() {
Serial.begin(31250); // MIDI protocol baud rate
}
void loop() {
if (calibrated == 0) calibrate();
i = 0;
}
i++;
The functions sendNote and sendControl implement the MIDI messages and
the serial communication to turn on or off a note and send a control message
(which can be used for several purposes, in particular we will use it to
produce sound effects).
13
}
// Photoresistors setup
void calibrate() {
while (!Serial.available());
int incoming = Serial.read();
Serial.println("Calibration starting. Leave all holes open and press any key.");
while (!Serial.available());
incoming = Serial.read();
Serial.println("Values for threshold off will be: ");
for (int i = 0; i < 12; ++i) {
noteThresholdOff[i] = analogRead(light[i]) + 30;
Serial.print(noteThresholdOff[i]);
Serial.print(" ");
}
Serial.println(" ");
Serial.println("Close all the holes and press any key.");
while (!Serial.available());
incoming = Serial.read();
Serial.println("Values for threshold on will be: ");
for (int i = 0; i < 12; ++i) {
noteThresholdOn[i] = analogRead(light[i]) - 20;
Serial.print(noteThresholdOn[i]);
Serial.print(" ");
}
Serial.println(" ");
calibrated = 1;
}
The ultrasonic distance sensor works by sending one input pulse and
measuring the time for the echo pulse to arrive. The function
microsecondsToVelocity is used to convert this waiting time to a number from
0 to 127, which will be the MIDI velocity (volume).
// The ultrasonic sensor is used for measuring the velocity (volume) of the notes
played.
void readUltrasonic() {
// The PING sensor is triggered by a HIGH pulse of 2 or more microseconds.
// We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
pinMode(ultra, OUTPUT);
digitalWrite(ultra, LOW);
delayMicroseconds(2);
digitalWrite(ultra, HIGH);
delayMicroseconds(5);
14
digitalWrite(ultra, LOW);
// The same pin is used to read the signal from the PING: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(ultra, INPUT);
duration = pulseIn(ultra, HIGH);
// Velocity (intensity or volume) in MIDI goes from 0 to 127, and we measured the
// minimum distance being 30cm and the maximum being 145cm
if (cm >= 60) return 127;
else if (cm <= 3) return 0;
else return (127 * cm - 3 * 127) / 57;
}
valueX = abs(valueX);
valueY = abs(valueY);
15
Results
16
Conclusion
The device built shows that motion sensing does not necessarily need
expensive sensors and complicated architectures. It is a perfect
demonstration of the creative potential of the technology on music, and it
brings a new way to create and perform music on live or on studio. An
improved version could be sold as a DJ equipment, toy or video game. The
involved gesture sensing technologies could also be used for other
applications, for example: socially assistive robots, remote controllers and
alternative computer interfaces.
17
Bibliography
http://www.midi.org/aboutmidi/products.php
18