<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mat+Kotowsky</id>
	<title>Mech - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://hades.mech.northwestern.edu//api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Mat+Kotowsky"/>
	<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php/Special:Contributions/Mat_Kotowsky"/>
	<updated>2026-04-20T17:07:36Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.9</generator>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=13021</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=13021"/>
		<updated>2009-03-27T19:31:12Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Component Data Sheets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into semicircles and attached to the thumb and index fingertips of the glove with double-stick tape. Sections of hookup wire are soldered to these fingertip contacts and run through the fingers of the glove to the accelerometer. There, one fingertip contact is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  The code to operate the function generator is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in the [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|right|thumb|200px|Power connector reinforcement plate]]&lt;br /&gt;
On the left side of the box is a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12895</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12895"/>
		<updated>2009-03-20T06:45:13Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into semicircles and attached to the thumb and index fingertips of the glove with double-stick tape. Sections of hookup wire are soldered to these fingertip contacts and run through the fingers of the glove to the accelerometer. There, one fingertip contact is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  The code to operate the function generator is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in the [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|right|thumb|200px|Power connector reinforcement plate]]&lt;br /&gt;
On the left side of the box is a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12892</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12892"/>
		<updated>2009-03-20T06:44:25Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Function Generator */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into semicircles and attached to the thumb and index fingertips of the glove with double-stick tape. Sections of hookup wire are soldered to these fingertip contacts and run through the fingers of the glove to the accelerometer. There, one fingertip contact is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  The code to operate the function generator is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in the [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box is a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12887</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12887"/>
		<updated>2009-03-20T06:42:43Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Play Enable */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into semicircles and attached to the thumb and index fingertips of the glove with double-stick tape. Sections of hookup wire are soldered to these fingertip contacts and run through the fingers of the glove to the accelerometer. There, one fingertip contact is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in the [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box is a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12625</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12625"/>
		<updated>2009-03-20T03:22:31Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in the [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box is a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12619</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12619"/>
		<updated>2009-03-20T03:21:05Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* LCD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in the [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12605</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12605"/>
		<updated>2009-03-20T03:15:07Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Effect of Centripetal Acceleration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximately 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is less than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12587</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12587"/>
		<updated>2009-03-20T02:59:11Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12585</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12585"/>
		<updated>2009-03-20T02:56:52Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Mozart&amp;#039;s Right Hand */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|150px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Rock-Paper-Scissors]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12584</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12584"/>
		<updated>2009-03-20T02:56:32Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Mozart&amp;#039;s Right Hand */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|200px|Mozart&amp;#039;s Right Hand|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Rock-Paper-Scissors]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12582</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12582"/>
		<updated>2009-03-20T02:55:49Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Mozart&amp;#039;s Right Hand */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|100px|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Rock-Paper-Scissors]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12581</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12581"/>
		<updated>2009-03-20T02:55:13Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Mozart&amp;#039;s Right Hand */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&amp;#039;s Right Hand]] ===&lt;br /&gt;
[[Image:mrh_box.JPG|thumb|100px|Mozart&amp;#039;s Right Hand box|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Rock-Paper-Scissors]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12580</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12580"/>
		<updated>2009-03-20T02:54:46Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&amp;#039;s Right Hand]] ===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|100px|Mozart&amp;#039;s Right Hand box|right]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Rock-Paper-Scissors]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12576</id>
		<title>ME 333 final projects</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=ME_333_final_projects&amp;diff=12576"/>
		<updated>2009-03-20T02:53:56Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Mozart&amp;#039;s Right Hand */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See the &amp;#039;&amp;#039;&amp;#039;[[ME 333 end of course schedule]]&amp;#039;&amp;#039;&amp;#039;.  &lt;br /&gt;
&lt;br /&gt;
Final projects for ME 333 in years 2000-2007 can be found&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[http://lims.mech.northwestern.edu/~design/mechatronics/ here]&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2009 ==&lt;br /&gt;
&lt;br /&gt;
=== [[Mozart&amp;#039;s Right Hand]] ===&lt;br /&gt;
=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Persistence-of-Vision Display]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Rock-Paper-Scissors]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Three-speaker Chladni Patterns]] ===&lt;br /&gt;
[[Image:chladni_660hz|right|thumb|150px]]&lt;br /&gt;
This project uses three speakers to generate shapes on a circular aluminum plate depending on which frequency the speakers are playing at. Once the speakers hit a resonant frequency of the plate, salt migrates to the nodes (zero amplitude) regions of the plate to form distinct patterns.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Basketball]] ===&lt;br /&gt;
[[Image:Mechatronics2009Bball|right|thumb|150px]]&lt;br /&gt;
This project consists of a throwing arm propelled by a Pittman motor is mounted on a turntable and throws the ball into the &amp;quot;hoop.&amp;quot; The hoop is wrapped in reflective tape and an IR emitter, receiver pair is used to sense where the IR is reflected most (the hoop with highly reflective tape). An ultrasonic sensor then pings the hoop for the distance of the hoop. With this information, the arm is able to &amp;quot;make a basket.&amp;quot;&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Drummer]] ===&lt;br /&gt;
The Robot Drummer is a device that demonstrates high-speed motor control by being able to drum when given commands.  Through an RS232 cable, Matlab sends commands to a &amp;quot;master&amp;quot; PIC.  The master then sends the commands to two &amp;quot;slave&amp;quot; PICs through I2C communication.  The slaves take the commands and implement PID control of the motors.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Fish Refuge]] ===&lt;br /&gt;
[[Image:Entire Fish Refuge|right|thumb|200px]]&lt;br /&gt;
The automated fish refuge allows for the controlled movement of a fish refuge with the goal of recording specific behavior.  The mechanical design is completely adjustable and allows adjustable degrees of oscillating movement and orientation of the refuge.  The program is primarily in MATLAB for ease of use and the velocity profile can be a sine, square, triangle, or any function that the user inputs. [http://www.youtube.com/watch?v=wGOKujMhN88 Check out the video!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Marionette]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[Monkeybot]] ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
=== [[PPOD-mini:  6-DOF Shaker]] ===&lt;br /&gt;
[[Image:PPOD_mini.JPG|thumb|200x200 px|right|PPOD-mini 6-DOF Shaker]]&lt;br /&gt;
The PPOD-mini is a miniaturized version of the Programmable Part-feeding Oscillatory Device ([http://lims.mech.northwestern.edu/projects/frictioninducedforcefields/index.htm PPOD]) found in the Laboratory for Intelligent Mechanical Systems (LIMS) at Northwestern. The PPOD-mini utilizes six speakers that act like actuators. The speakers are connected to a acrylic plate via flexures of tygon and iron. In its current implementation, the phase of the speakers can be controlled independently, giving the device six degrees of freedom. The movement of objects placed on the acrylic plate can be controlled by changing the phases of the speakers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Automated Xylophone]] ===&lt;br /&gt;
[[Image:AutomatedXylophonePicture1.jpg|thumb|200x200 px|right|Automated Xylophone]]&lt;br /&gt;
The Automated Xylophone controls several solenoids which hit various pitches on an actual xylophone based on the note selected.  The device has two main modes: using the keypad, a user can choose to either play notes in real time or store songs to be played back later.  A video of the Automated Xylophone playing in real time mode can be found [http://www.youtube.com/watch?v=_ubpAEyq9kg here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vision-based Cannon]] ===&lt;br /&gt;
[[Image:SM_Gun_Camera_PIC_Setup.JPG|thumb|200x200 px|right|Vision-based Cannon]]&lt;br /&gt;
This project uses a webcam and Matlab to analyze an image and direct a modified USB Missile Launcher to fire at targets found in the image.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== ME 333 Final Projects 2008 ==&lt;br /&gt;
&lt;br /&gt;
=== [[IR Tracker]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:IR_Tracker_Main.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The IR Tracker (aka &amp;quot;Spot&amp;quot;) is a device that follows a moving infrared light. It continuously detects the position of an infrared emitter in two axes, and then tracks the emitter with a laser. [[Media:MT_MS_AZ_TrackerVideo.mp4|See Spot Run.]]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Chosen the OUTSTANDING PROJECT by the students of ME 333.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Robot Snake]] ===&lt;br /&gt;
[[Image:HLSSnakeMain.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This remote control robotic snake uses servo motors with a traveling sine wave motion profile to mimic serpentine motion.  The robotic snake is capable of moving forward, left, right and in reverse.   &lt;br /&gt;
[http://www.youtube.com/watch?v=r_GOOFLnI6w Video of the robot snake]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Programmable Stiffness Joint]] === &lt;br /&gt;
&lt;br /&gt;
[[Image:SteelToePic2.jpg|thumb|200px|The &amp;#039;Steel Toe&amp;#039; programmable stiffness joint|right]]&lt;br /&gt;
&lt;br /&gt;
The Programmable Stiffness Joint varies rotational stiffness as desired by the user.  It is the first step in modeling the mechanical impedance of the human ankle joint (both stiffness and damping) for the purpose of determining the respective breakdown of the two properties over the gait cycle.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Magnetic based sample purification]] ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== [[Continuously Variable Transmission]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:CVT_system.JPG|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This prototype is a proof of concept model of a variable ratio transmission to be implemented in the 2008-2009 Formula SAE competition vehicle.  The gear ratio is determined by the distances between the pulley halves which are controllable electronically.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Granular Flow Rotating Sphere]] ===&lt;br /&gt;
[[Image:Team-21-main-picture.JPG|right|thumb|200px]]&lt;br /&gt;
This device will be used to study the granular flow of particles within a rotating sphere. The sphere is filled with grains of varying size and then rotated about two different axes according to a series of position and angular velocity inputs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Vibratory Clock]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Vibratory_Clock.jpg|right|thumb|Vibratory Clock|200px]]&lt;br /&gt;
&lt;br /&gt;
The Vibratory Clock allows a small object to act as an hour &amp;quot;hand&amp;quot; on a horizontal circular platform that is actuated from underneath by three speakers.  The object slides around the circular platform, impelled by friction forces due to the vibration.  [http://www.youtube.com/watch?v=KhgTNCfdwZw Check it out!]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[WiiMouse]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:HPIM1027.jpg|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
The WiiMouse is a handheld remote that can be used to move a cursor on a windows-based PC, via accelerometer input captured through device movement.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Intelligent Oscillation Controller]] ===&lt;br /&gt;
&lt;br /&gt;
[[image:ME333_learning_oscillator.jpg|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
This device &amp;quot;learns&amp;quot; a forcing function that is applied to a spring and mass system to match an arbitrary, periodic acceleration profile.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Baseball]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Baseball_Playfield.jpg|Sweet Baseball Game|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive baseball game inspired by pinball, featuring pitching, batting, light up bases and a scoreboard to keep track of the game.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== [[Ball Balancing Challenge]] ===&lt;br /&gt;
&lt;br /&gt;
[[Image:Ballbalancechallenge.JPG|right|thumb|200px]]&lt;br /&gt;
&lt;br /&gt;
An interactive game involving ball balancing on a touchscreen with touchscreen feedback and joystick action. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12571</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12571"/>
		<updated>2009-03-20T02:48:21Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Creating the Signal */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12565</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12565"/>
		<updated>2009-03-20T02:44:57Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Further Reading and References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
==The Project==&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
&lt;br /&gt;
==Theory References==&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
&lt;br /&gt;
==Component Data Sheets==&lt;br /&gt;
*[[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;br /&gt;
&lt;br /&gt;
==Mechatronics References==&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12557</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12557"/>
		<updated>2009-03-20T02:39:31Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Frequency Code Discussion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25, 554.37, 587.33, 622.25, 659.26, 698.46, 739.99, 783.99, 830.61, 880, 932.33, 987.77, &lt;br /&gt;
   1046.5, 108.73, 1174.66, 1244.51, 1318.51, 1396.91, 1479.98, 1567.98, 1661.22, 1760, 1864.66, 1975.53, &lt;br /&gt;
   2093, 0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;, &amp;quot;C#5/Db5&amp;quot;, &amp;quot;D5&amp;quot;, &amp;quot;D#5/Eb5&amp;quot;, &amp;quot;E5&amp;quot;, &amp;quot;F5&amp;quot;, &amp;quot;F#5/Gb5&amp;quot;, &amp;quot;G5&amp;quot;, &amp;quot;G#5/Ab5&amp;quot;, &amp;quot;A5&amp;quot;, &amp;quot;A#5/Bb5&amp;quot;, &amp;quot;B5&amp;quot;, &lt;br /&gt;
   &amp;quot;C6&amp;quot;, &amp;quot;C#6/Db6&amp;quot;, &amp;quot;D6&amp;quot;, &amp;quot;D#6/Eb6&amp;quot;, &amp;quot;E6&amp;quot;, &amp;quot;F6&amp;quot;, &amp;quot;F#6/Gb6&amp;quot;, &amp;quot;G6&amp;quot;, &amp;quot;G#6/Ab6&amp;quot;, &amp;quot;A6&amp;quot;, &amp;quot;A#6/Bb6&amp;quot;, &amp;quot;B6&amp;quot;, &lt;br /&gt;
   &amp;quot;C7&amp;quot;, &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12550</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12550"/>
		<updated>2009-03-20T02:34:37Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|center]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12548</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12548"/>
		<updated>2009-03-20T02:34:10Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box|right]]&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12547</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12547"/>
		<updated>2009-03-20T02:33:32Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12543</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12543"/>
		<updated>2009-03-20T02:28:34Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|none|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|none|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12542</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12542"/>
		<updated>2009-03-20T02:27:06Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|none|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|none|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12541</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12541"/>
		<updated>2009-03-20T02:26:21Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12529</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12529"/>
		<updated>2009-03-20T02:05:38Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|right|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12526</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12526"/>
		<updated>2009-03-20T02:04:35Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12523</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12523"/>
		<updated>2009-03-20T02:03:47Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12522</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12522"/>
		<updated>2009-03-20T02:03:32Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12521</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12521"/>
		<updated>2009-03-20T02:02:39Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box]][[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12520</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12520"/>
		<updated>2009-03-20T02:02:11Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12519</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12519"/>
		<updated>2009-03-20T02:01:36Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12517</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12517"/>
		<updated>2009-03-20T02:01:04Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Left Side */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|left|thumb|200px|Left side of the desktop box]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|right|thumb|200px|Power supply reinforcement plate]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12516</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12516"/>
		<updated>2009-03-20T02:00:29Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Top */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12515</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12515"/>
		<updated>2009-03-20T02:00:16Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Top */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Mrh_box_left.JPG&amp;diff=12514</id>
		<title>File:Mrh box left.JPG</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Mrh_box_left.JPG&amp;diff=12514"/>
		<updated>2009-03-20T01:57:30Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Mrh_box_top.JPG&amp;diff=12510</id>
		<title>File:Mrh box top.JPG</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Mrh_box_top.JPG&amp;diff=12510"/>
		<updated>2009-03-20T01:56:19Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12509</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12509"/>
		<updated>2009-03-20T01:54:22Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Desktop Box */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|300px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12507</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12507"/>
		<updated>2009-03-20T01:54:01Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Desktop Box */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|center|thumb|200px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12506</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12506"/>
		<updated>2009-03-20T01:53:31Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Desktop Box */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12505</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12505"/>
		<updated>2009-03-20T01:52:11Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Glove */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12474</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=12474"/>
		<updated>2009-03-20T01:35:10Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
&lt;br /&gt;
==Circuit Diagram==&lt;br /&gt;
[[Image:mozart_circuit.jpg|center|thumb|500px|Circuit Diagram]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it using an automatic milling machine.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11891</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11891"/>
		<updated>2009-03-19T17:22:57Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Further Reading and References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;br /&gt;
*[[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11890</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11890"/>
		<updated>2009-03-19T17:21:52Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.  The front of the box has cutouts for the speaker and the LCD which are both mounted with machine screws and nuts.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11889</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11889"/>
		<updated>2009-03-19T17:20:27Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11888</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11888"/>
		<updated>2009-03-19T17:20:14Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|200px|Mozart&amp;#039;s Right Hand box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11887</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11887"/>
		<updated>2009-03-19T17:19:58Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|100px|Mozart&amp;#039;s Right Hand box|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11886</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11886"/>
		<updated>2009-03-19T17:19:47Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11885</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11885"/>
		<updated>2009-03-19T17:18:53Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* Enclosure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
The enclosure for Mozart&amp;#039;s Right Hand is a Radio Shack [http://www.radioshack.com/product/index.jsp?productId=2062285 8&amp;quot;x6&amp;quot;x3&amp;quot;] project box with several customized ports cut into it.&lt;br /&gt;
===Top===&lt;br /&gt;
[[Image:mrh_box_top.JPG|center|thumb|200px|Top of the desktop box|right]]&lt;br /&gt;
On the top of the box, there is a large rocker switch for power.  This DPDT switch will break the supply of +12 and -12 volts coming from the power supply.  Also on the top of the box is a numbered knob to control volume.  This knob is a 100K-ohm potentiometer that scales the output of the function generator as it is going into the audio amplifier.  The knob is secured to the enclosure with epoxy.&lt;br /&gt;
===Left Side===&lt;br /&gt;
[[Image:mrh_box_left.JPG|center|thumb|200px|Left side of the desktop box|right]]&lt;br /&gt;
[[Image:mrh_box_plate.JPG|center|thumb|200px|Power supply reinforcement plate|right]]&lt;br /&gt;
On the left side of the box are a 5-pin circular DIN power connector that mates with the desktop power supply.  Because a significant amount of force is required to mate the power connector with the power supply, the connector is secured to the enclosure with a custom-machined metal plate.  Also on the left side of the box is the 10-pin rectangular plug that accepts the ribbon cable from the glove.  This header is keyed so that the ribbon cable cannot be inserted backwards.  It is secured to the enclosure with epoxy.&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11878</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11878"/>
		<updated>2009-03-19T17:05:33Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* LCD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs|LCD interfacing]] article on the Mechatronics Wiki.  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=File:Mrh_lcd.JPG&amp;diff=11875</id>
		<title>File:Mrh lcd.JPG</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=File:Mrh_lcd.JPG&amp;diff=11875"/>
		<updated>2009-03-19T17:04:20Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
	<entry>
		<id>https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11873</id>
		<title>Mozart&#039;s Right Hand</title>
		<link rel="alternate" type="text/html" href="https://hades.mech.northwestern.edu//index.php?title=Mozart%27s_Right_Hand&amp;diff=11873"/>
		<updated>2009-03-19T17:03:57Z</updated>

		<summary type="html">&lt;p&gt;Mat Kotowsky: /* LCD */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is a musical instrument capable of playing two full octaves of the [http://en.wikipedia.org/wiki/Diatonic_scale Diatonic Scale.]  The user wears a glove on his right hand and uses motions of the hand and fingers to create different notes that are played with a speaker.  The pitch of the note is controlled by the orientation of the user&amp;#039;s hand as he rotates it ether from the wrist, the elbow, or the shoulder.  The LCD on the front of the box tells the user the pitch that corresponds to his or her current hand orientation.  When the user touches together his thumb and index finger, the speaker plays the tone.  A [http://www.youtube.com/watch?v=vec-W4QeHQU video] of Mozart&amp;#039;s Right Hand in action is available on YouTube.&lt;br /&gt;
[[Image:mrh_box.JPG|center|thumb|300px|Mozart&amp;#039;s Right Hand box|left]]&lt;br /&gt;
[[Image:mrh_playing.JPG|center|thumb|550px|Mozart&amp;#039;s Right Hand in action|right]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Team==&lt;br /&gt;
[[Image:mrh_team.JPG|center|thumb|350px|Design Team (Left to Right: Sean, Mat, and Colleen)|right]]&lt;br /&gt;
*Colleen Fryer ( colleenfryer2008 at u dot northwestern dot edu ), Mechanical Engineering Graduate Student&lt;br /&gt;
*Sean Wood ( seanwood2010 at u dot northwestern dot edu ), Mechanical Engineering Junior&lt;br /&gt;
*Mat Kotowsky (kotowsky at northwestern dot edu), Civil Engineering Graduate Student&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Theory of Operation=&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays all of the notes, including sharps and flats, between and including C5 and C7 (where C4 is &amp;quot;Middle C&amp;quot;).  Each of these notes has a specific frequency associated with it; for example: C6 has a frequency of 1046.50 Hz.  Other notes&amp;#039; frequencies are available at [http://www.phy.mtu.edu/~suits/notefreqs.html http://www.phy.mtu.edu/~suits/notefreqs.html].  If signal whose voltage is a 1046.50 Hz sine wave is passed through a speaker, the speaker will play C6.  Increasing the frequency will raise the pitch, decreasing it will lower the pitch.  Increasing the amplitude will cause the volume of the note to go up, decreasing it will cause the volume to go down.&lt;br /&gt;
&lt;br /&gt;
==Orientation of the Hand Relative to Gravity==&lt;br /&gt;
[[Image:mrh_axes.JPG|center|thumb|200px|The axes of the accelerometer in relation to the glove|right]]&lt;br /&gt;
The pitch of a note is determined by measuring gravitational acceleration in two axes.  The Y-axis runs along the user&amp;#039;s arm with positive being toward the fingertips.  The X-axis is orthogonal to the Y axis and lies in the plane of the palm of the hand.  The pitch is decided by first measuring the gravitational acceleration in the Y direction.  If the Y acceleration is 0g, the palm is parallel to the floor.  If the Y acceleration is 1g, the palm is perpendicular to the floor with the fingertips pointing towards the floor.  If the Y acceleration is -1g, the plan is perpendicular to the floor with the fingertips pointed straight up.  When the fingertips are pointed straight down (1g), Mozart&amp;#039;s Right Hand produces its lowest possible note: C5.  When the fingertips are pointed straight out (0g), it produces its mid-rage note: C6.  When the fingertips are pointed straight up (-1g), it produces its highest possible note, C7.&lt;br /&gt;
&lt;br /&gt;
The X-axis is used to determine whether a note is sharp or flat.  If the X axis measures 0g, the note is played naturally with no sharps or flats.  If the X axis measures a positive gravitational acceleration, the user is tipping his hand to the right and the note is played sharp.  If the X axis measures a negative gravitational acceleration, the user is tipping his hand to the left and the note is played flat.&lt;br /&gt;
&lt;br /&gt;
For both the X and Y axes, the actual values used to determine the thresholds between notes were determined empirically.  They appear in the code below.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Effect of Centripetal Acceleration==&lt;br /&gt;
During typical use, the user&amp;#039;s hand remains stationary and the only effect on the pitch is the glove&amp;#039;s orientation with respect to gravity.  It is possible, however, that the user will want to play a note while simultaneously moving his hand.  The speaker will play different tones as the user moves his hand through the different orientations.  During this type of playing, the acceleration measured by the accelerometer is not only due to gravity but due to the effect of [http://en.wikipedia.org/wiki/Centripetal_force centripetal force] caused by the hands rotation about the user&amp;#039;s wrist, elbow, or shoulder.  If one assumes that such motion is uniform and circular about its center, then the acceleration measured during motion is a superposition of the acceleration due to gravity and the acceleration toward the center of rotation: [[Image:mrh_aequalsv2overr.jpg]].&lt;br /&gt;
&lt;br /&gt;
The average length of a human hand is approximate 180mm (from [http://en.wikipedia.org/wiki/Hand http://en.wikipedia.org/wiki/Hand]), so the distance between the accelerometer and the wrist is about half of that: 90mm.  If the fastest a user moved his hand from straight down to straight up is one second, its total distance traveled would be one half of the circumference of a circle with a radius of 90mm: approximately 280mm, for a velocity of about 280mm per second.  Therefore, the acceleration towards the wrist would be approximately 0.9 meters per second squared.  This is lest than one tenth of a g, so a user would not experience a significant change in note pitch due to centripetal acceleration while rotating at the wrist.&lt;br /&gt;
&lt;br /&gt;
The same calculation could be carried out for playing Mozart&amp;#039;s Right Hand by rotating through the elbow or the shoulder.&lt;br /&gt;
&lt;br /&gt;
=Hardware=&lt;br /&gt;
Mozart&amp;#039;s Right Hand is comprised of two main components: the input glove and the desktop box.  The glove carries the sensors that determine which note is played and when it is played.  The desktop box contains all of the intelligence to read the sensors, translate them into frequencies, and drive the speaker.  The glove is connected to the box by a 10-position ribbon cable.&lt;br /&gt;
==Glove==&lt;br /&gt;
[[Image:mrh_glove.JPG|center|thumb|600px|The Glove]]&lt;br /&gt;
[[Image:mrh_glove_circuit.JPG|right|thumb|200px|Circuit diagram of the glove]]&lt;br /&gt;
The glove contains a dual axis accelerometer and a set of fingertip contacts between the thumb and the forefinger.  These components are connected together via hookup wire that runs through the finger, thumb, and palm of the glove, then back to the desktop box via a 10-pin ribbon cable.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Accelerometer===&lt;br /&gt;
[[Image:mrh_accel.JPG|center|thumb|200px|[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer|right]]&lt;br /&gt;
The accelerometer is an [http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html ADXL-320] [http://en.wikipedia.org/wiki/MEMS MEMS] accelerometer configured for dual-axis use.  Though it has a range of +/-5g, it is only used in the +/-1g range.  The accelerometer has pins V+, GND, X, Y, and a test pin.  The test pin, though connected to the ribbon cable, is not used.  The X and Y pins provide ratiometric analog output.  V+ is connected to a 5 VDC output coming from a regulator inside of the desktop box.  The GND pin is connected to one end of the Play Enable switch closure and also to the digital ground inside of the desktop box.  The accelerometer is sewn to the top of the glove using the signal wires through the mounting holes on the carrier board.&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Play Enable===&lt;br /&gt;
[[Image:mrh_glove_contacts.JPG|center|thumb|200px|Play enable contacts on glove|right]]&lt;br /&gt;
The Play Enable functionality is implemented with two thin strips of aluminum that are shaped into a semicircle and attached to the thumb and index fingertips of the glove with double-stick tape.  Sections of hookup wire are soldered to the contacts and then run through the fingers of the glove to the accelerometer where one is attached to ground and the other runs through the ribbon cable to be connected to a digital input pin on the microcontroller.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Desktop Box==&lt;br /&gt;
[[Image:mrh_desktop_box_circuit.JPG|right|thumb|200px|The desktop box circuit diagram]]&lt;br /&gt;
[[Image:Mrh_box.JPG|left|thumb|200px|The desktop box]]&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
===Microcontroller and Protoboard===&lt;br /&gt;
Mozart&amp;#039;s Right Hand is built on the [http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC 18F4520].  The design uses a 40 MHz clock and takes advantage of the software-controlled [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI] interface to program the function generator, two ADC pins to read the accelerometer, one digital input pin to read the play enable contacts, and several digital output pins to drive the LCD.  The circuit board is powered using a [http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&amp;amp;langId=-1&amp;amp;productId=190960&amp;amp;catalogId=10001&amp;amp;freeText=190960+&amp;amp;storeId=10001&amp;amp;search_type=all&amp;amp;ddkey=http:StoreCatalogDrillDownView Meanwell desktop power supply] that produces +12, -12, and +5 volts DC with a total power output of 26 watts.  Mozart&amp;#039;s Right Hand makes use of the +/-12 volt power for its audio amplifier and uses the +12 volts to power a [http://hades.mech.northwestern.edu/wiki/images/6/6c/LM7805.pdf TO-220 7805 5V regulator].&lt;br /&gt;
[[Image:mrh_circuit_board.JPG|center|thumb|400px|Desktop box circuit board]]&lt;br /&gt;
&lt;br /&gt;
===Function Generator===&lt;br /&gt;
[[Image:mrh_function_generator.JPG|center|thumb|200px|[http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] programmable function generator with carrier board custom-designed in [http://lims.mech.northwestern.edu/ Northwestern University&amp;#039;s LIMS lab]|right]]&lt;br /&gt;
The [http://www.analog.com/en/rfif-components/direct-digital-synthesis-dds/ad9833/products/product.html AD9833] function generator is a small chip that can generate square waves, sine waves, and triangle waves of varying frequencies.  It communicates using a 16-bit version of [http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus SPI].  Our code is a re-use of the code from the [[Guitar_Tunning_Project#Programmable_Function_generator_.28Using_AD9833.29| Guitar Tuning Project]].  Mozart&amp;#039;s Right Hand uses a sine wave to drive its speaker.  When the AD9833 is configured to produce a sine wave output, instead of oscillating about zero, the sine wave oscillates around 0.3 volts with an amplitude of 0.3 volts.  The [http://lims.mech.northwestern.edu/ LIMS]-designed AD9833 carrier board uses an [http://www.national.com/mpf/LM/LM6132.html LM6132] operational amplifier to line-shift and amplify the signal such that it oscillates about 0 volts with an amplitude of 2 volts.  This signal is not strong enough to generate a suitable tone, so it is passed through another amplifier, as described below, before going to the speaker.&lt;br /&gt;
&lt;br /&gt;
The LIMS carrier board also includes various components that provide for signal conditioning, power regulation, and reverse- and short-current protection.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Amplifier and Speaker===&lt;br /&gt;
[[Image:mrh_amp_circuit_diagram.JPG|right|thumb|300px|TDA-2040 wiring diagram|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand plays its tones through a 4-inch 4-watt 4-ohm speaker.  The output of the function generator is not sufficient to drive this speaker at a reasonable volume.  To compensate for this, further audio amplification is necessary.  The design uses a [http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040] 20-watt amplification chip in a T-220 package.  Use of a heat sink is crucial as this chip can generate a great deal of heat even at low volumes.  The data sheet for the amplifier chip contains a diagram for a circuit to test the amplifier.  This test circuit proved to be adequate for the needs of the project and is implemented in the final design.&lt;br /&gt;
&lt;br /&gt;
In the wiring diagram pictured to the right, &amp;lt;math&amp;gt;V_i&amp;lt;/math&amp;gt; represents the input signal to the amplifier -- in this case, the output of the function generator after it has been passed through a 100K-ohm knob potentiometer for volume control.  &amp;lt;math&amp;gt;+V_s&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;-V_s&amp;lt;/math&amp;gt; represent the +12 and -12 volt input from the DC power supply.  &amp;lt;math&amp;gt;R_L&amp;lt;/math&amp;gt; represents the speaker.  Note that in this diagram, a capacitor with a white side is polarized with white denoting the positive terminal.&lt;br /&gt;
&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===LCD===&lt;br /&gt;
[[Image:mrh_lcd.JPG|right|thumb|300px|The LCD|right]]&lt;br /&gt;
Mozart&amp;#039;s Right Hand makes use of a 16 by 2 character LCD with a blue backlight.  This LCD is HD44780 compatible, as described in [[C_Example:_Parallel_Interfacing_with_LCDs]].  During operation of Mozart&amp;#039;s Right Hand, the LCD will, at all times, display the note that corresponds to the current orientation of the glove.  If the finger contacts are not touched together, the LCD will also display &amp;quot;Muted&amp;quot; to indicate that no sound should be coming out of the speaker.  When the finger contacts are touched together, the word &amp;quot;Muted&amp;quot; disappears and the speaker will play the note indicated.&lt;br /&gt;
&lt;br /&gt;
===Enclosure===&lt;br /&gt;
&lt;br /&gt;
=Software=&lt;br /&gt;
The software that powers Mozart&amp;#039;s Right Hand runs in an infinite loop in which it&lt;br /&gt;
*Determines the current orientation of the glove&lt;br /&gt;
*Maps the orientation of glove to a note&lt;br /&gt;
*Determines whether it should play the note or be silent&lt;br /&gt;
*Plays the note (if necessary)&lt;br /&gt;
&lt;br /&gt;
The [[Media:mrh_code.c| full code]] contains all of the hardware initializations and pin configurations.&lt;br /&gt;
==Frequency Code Discussion==&lt;br /&gt;
These comments in the code explain how the notes are mapped.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* Frequency Discussion&lt;br /&gt;
&lt;br /&gt;
See this page: http://www.phy.mtu.edu/~suits/notefreqs.html&lt;br /&gt;
&lt;br /&gt;
We want to have two octaves of usable notes.  Based on playing with the speaker&lt;br /&gt;
and a function generator, it would seem that our best octaves are going to be 5 and 6,&lt;br /&gt;
that is, C5 up through C7.&lt;br /&gt;
&lt;br /&gt;
C5 frequency is: 523.25 Hz&lt;br /&gt;
C7 frequency is: 2093.00 Hz&lt;br /&gt;
&lt;br /&gt;
Adjusting the orientation of the ADXL-320 yields maximum and minimum ADC values:&lt;br /&gt;
&lt;br /&gt;
Straight Up:   111   -&amp;gt; C7&lt;br /&gt;
Straight Out:  127   -&amp;gt; C6&lt;br /&gt;
Straight Down: 143   -&amp;gt; C5&lt;br /&gt;
&lt;br /&gt;
All of the notes:&lt;br /&gt;
&lt;br /&gt;
Note        Frequency (Hz)&lt;br /&gt;
C5          523.25&lt;br /&gt;
C#5/Db5     554.37&lt;br /&gt;
D5          587.33&lt;br /&gt;
D#5/Eb5     622.25&lt;br /&gt;
E5          69.26&lt;br /&gt;
F5          698.46&lt;br /&gt;
F#5/Gb5     739.99&lt;br /&gt;
G5          783.99&lt;br /&gt;
G#5/Ab5     830.61&lt;br /&gt;
A5          880&lt;br /&gt;
A#5/Bb5     932.33&lt;br /&gt;
B5          987.77&lt;br /&gt;
C6          1046.5&lt;br /&gt;
C#6/Db6     1108.73&lt;br /&gt;
D6          1174.66&lt;br /&gt;
D#6/Eb6     1244.51&lt;br /&gt;
E6          1318.51&lt;br /&gt;
F6          1396.91&lt;br /&gt;
F#6/Gb6     1479.98&lt;br /&gt;
G6          1567.98&lt;br /&gt;
G#6/Ab6     1661.22&lt;br /&gt;
A6          1760&lt;br /&gt;
A#6/Bb6     1864.66&lt;br /&gt;
B6          1975.53&lt;br /&gt;
C7          2093&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
float note_frequencies[26] = {&lt;br /&gt;
   523.25,&lt;br /&gt;
   554.37,&lt;br /&gt;
   587.33,&lt;br /&gt;
   622.25,&lt;br /&gt;
   659.26,&lt;br /&gt;
   698.46,&lt;br /&gt;
   739.99,&lt;br /&gt;
   783.99,&lt;br /&gt;
   830.61,&lt;br /&gt;
   880,&lt;br /&gt;
   932.33,&lt;br /&gt;
   987.77,&lt;br /&gt;
   1046.5,&lt;br /&gt;
   1108.73,&lt;br /&gt;
   1174.66,&lt;br /&gt;
   1244.51,&lt;br /&gt;
   1318.51,&lt;br /&gt;
   1396.91,&lt;br /&gt;
   1479.98,&lt;br /&gt;
   1567.98,&lt;br /&gt;
   1661.22,&lt;br /&gt;
   1760,&lt;br /&gt;
   1864.66,&lt;br /&gt;
   1975.53,&lt;br /&gt;
   2093,&lt;br /&gt;
   0&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
char note_names[26][26] = {&lt;br /&gt;
   &amp;quot;C5&amp;quot;,&lt;br /&gt;
   &amp;quot;C#5/Db5&amp;quot;,&lt;br /&gt;
   &amp;quot;D5&amp;quot;,&lt;br /&gt;
   &amp;quot;D#5/Eb5&amp;quot;,&lt;br /&gt;
   &amp;quot;E5&amp;quot;,&lt;br /&gt;
   &amp;quot;F5&amp;quot;,&lt;br /&gt;
   &amp;quot;F#5/Gb5&amp;quot;,&lt;br /&gt;
   &amp;quot;G5&amp;quot;,&lt;br /&gt;
   &amp;quot;G#5/Ab5&amp;quot;,&lt;br /&gt;
   &amp;quot;A5&amp;quot;,&lt;br /&gt;
   &amp;quot;A#5/Bb5&amp;quot;,&lt;br /&gt;
   &amp;quot;B5&amp;quot;,&lt;br /&gt;
   &amp;quot;C6&amp;quot;,&lt;br /&gt;
   &amp;quot;C#6/Db6&amp;quot;,&lt;br /&gt;
   &amp;quot;D6&amp;quot;,&lt;br /&gt;
   &amp;quot;D#6/Eb6&amp;quot;,&lt;br /&gt;
   &amp;quot;E6&amp;quot;,&lt;br /&gt;
   &amp;quot;F6&amp;quot;,&lt;br /&gt;
   &amp;quot;F#6/Gb6&amp;quot;,&lt;br /&gt;
   &amp;quot;G6&amp;quot;,&lt;br /&gt;
   &amp;quot;G#6/Ab6&amp;quot;,&lt;br /&gt;
   &amp;quot;A6&amp;quot;,&lt;br /&gt;
   &amp;quot;A#6/Bb6&amp;quot;,&lt;br /&gt;
   &amp;quot;B6&amp;quot;,&lt;br /&gt;
   &amp;quot;C7&amp;quot;,&lt;br /&gt;
   &amp;quot;Silence&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Reading the Accelerometer and Selecting the Note==&lt;br /&gt;
This block of code will read both axes of the accelerometer and map the results a note.  4096 samples are taken from the Y-axis and averaged.  This effectively creates a low-pass filter that eliminates noise from the accelerometer output.  The note selected will be an integer which is then used to index into arrays of note frequencies and names.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// This function will read the accelerometer then return the frequency&lt;br /&gt;
// that we should put out to the speaker&lt;br /&gt;
int8 get_note(void)&lt;br /&gt;
{&lt;br /&gt;
   int32 i;&lt;br /&gt;
   int32 adc_value;&lt;br /&gt;
   int8 note;&lt;br /&gt;
   float adc_value_float;     // How Hungarian!&lt;br /&gt;
 &lt;br /&gt;
   set_adc_channel(0);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   &lt;br /&gt;
   // Take 4096 samples of ADC and average them&lt;br /&gt;
   adc_value = 0;&lt;br /&gt;
   for(i=0; i&amp;lt;4096; i++)&lt;br /&gt;
   {&lt;br /&gt;
      adc_value += read_adc();&lt;br /&gt;
   } &lt;br /&gt;
   &lt;br /&gt;
   adc_value_float = (float) adc_value / 4096;&lt;br /&gt;
&lt;br /&gt;
   //This is a big if/else block to decide which note to play and spit out on the LCD&lt;br /&gt;
   if(adc_value_float &amp;lt; 113.5)&lt;br /&gt;
      note = 24;   // C7&lt;br /&gt;
   else if(adc_value_float &amp;lt; 115)&lt;br /&gt;
      note = 23;   // B6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 117)&lt;br /&gt;
      note = 21;   // A6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 119)&lt;br /&gt;
      note = 19;   // G6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 121)&lt;br /&gt;
      note = 17;   // F6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 123)&lt;br /&gt;
      note = 16;   // E6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 125)&lt;br /&gt;
      note = 14;  // D6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 127)&lt;br /&gt;
      note = 12;  // C6&lt;br /&gt;
   else if(adc_value_float &amp;lt; 131)&lt;br /&gt;
      note = 11;  // B5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 133)&lt;br /&gt;
      note = 9;  // A5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 135)&lt;br /&gt;
      note = 7;  // G5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 137)&lt;br /&gt;
      note = 5;  // F5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 139)&lt;br /&gt;
      note = 4;  // E5&lt;br /&gt;
   else if(adc_value_float &amp;lt; 141)&lt;br /&gt;
      note = 2;  // D5&lt;br /&gt;
   else&lt;br /&gt;
      note = 0;  // C5&lt;br /&gt;
   &lt;br /&gt;
   // Determine if note should be sharp or flat&lt;br /&gt;
   &lt;br /&gt;
   set_adc_channel(1);&lt;br /&gt;
   delay_us(10);           // give ADC time to switch to new channel&lt;br /&gt;
   adc_value = read_adc();    &lt;br /&gt;
   &lt;br /&gt;
   if (adc_value &amp;gt;= 135)   // Right is sharp&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;lt; 24) // Don&amp;#039;t go above C7&lt;br /&gt;
         note++;&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   else if (adc_value &amp;lt;= 127) // Left is flat&lt;br /&gt;
   {&lt;br /&gt;
      if (note &amp;gt; 0) // Don&amp;#039;t go below C5)&lt;br /&gt;
         note--;&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
   return note;&lt;br /&gt;
}   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating the Signal==&lt;br /&gt;
This function instructs the AD9833 function generator to put out a sine wave of the appropriate frequency.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void set_frequency(float freq)&lt;br /&gt;
{&lt;br /&gt;
   // Based on the code from the Guitar Tuning Project:&lt;br /&gt;
   // http://hades.mech.northwestern.edu/wiki/index.php/Guitar_Tunning_Project&lt;br /&gt;
   &lt;br /&gt;
   int32 conv_freq;&lt;br /&gt;
   int16 lsb, msb;&lt;br /&gt;
   &lt;br /&gt;
   conv_freq = (int32)(freq*6.7108864);               // 2^28/CLOCK = (2^28)/(40*10^6) = 6.7108864&lt;br /&gt;
   lsb= (int16)(conv_freq)&amp;amp;(0b0011111111111111);      //(Get the lowest 14 bits of conv_freq)&lt;br /&gt;
   msb= (int16)(conv_freq&amp;gt;&amp;gt;14)&amp;amp;(0b0011111111111111);   //(get the 14 most significant bits out of 28 bits conv_freq)&lt;br /&gt;
&lt;br /&gt;
   spi_xfer(0x2100);       // reset, tell it to expect two writes-*&lt;br /&gt;
   spi_xfer(0x4000 | lsb); // lsb in freq0&lt;br /&gt;
   spi_xfer(0x4000 | msb); // msb in freq0&lt;br /&gt;
   spi_xfer(0x0000);       // unreset, set up write&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Playing Notes==&lt;br /&gt;
This code is the main program loop.  The program will not instruct the AD9833 to change frequencies unless either the hand orientation has changed or if the fingers have been opened or closed.  If the frequency is allowed to be reset every time the sensor input is polled, the speaker makes will make repeating clicking noises.  The LCD is updated every polling interval regardless of whether the note has changed or the fingers have opened or closed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
   // Main Program Loop&lt;br /&gt;
   while(TRUE)&lt;br /&gt;
   {&lt;br /&gt;
      playDisabled = input(PIN_C2);&lt;br /&gt;
      note = get_note();&lt;br /&gt;
      printf(&amp;quot;Note: %s\t&amp;quot;,note_names[note]);&lt;br /&gt;
      printf(lcd_putc, &amp;quot;\fNote: %s\n&amp;quot;,note_names[note]);&lt;br /&gt;
      if(playDisabled)&lt;br /&gt;
      {&lt;br /&gt;
         printf(&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         printf(lcd_putc,&amp;quot;Muted&amp;quot;);&lt;br /&gt;
         if(!oldPlayDisabled) // Don&amp;#039;t do this if we&amp;#039;re not changing from un-muted to muted.&lt;br /&gt;
            set_frequency(0);&lt;br /&gt;
&lt;br /&gt;
      }&lt;br /&gt;
      else&lt;br /&gt;
      {&lt;br /&gt;
         if ((note != old_note) || (playDisabled != oldPlayDisabled))  // Don&amp;#039;t do this unless we&amp;#039;re changing notes.&lt;br /&gt;
            set_frequency(note_frequencies[note]);&lt;br /&gt;
      }&lt;br /&gt;
      &lt;br /&gt;
      old_note = note;&lt;br /&gt;
      oldPlayDisabled = playDisabled;&lt;br /&gt;
      &lt;br /&gt;
      printf(&amp;quot;\n\r&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Further Reading and References=&lt;br /&gt;
*Full Mozart&amp;#039;s Right Hand Code: [[Media:mrh_code.c| mrh_code.c]]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Diatonic_scale Notes and frequencies of the diatonic scale]&lt;br /&gt;
*[http://www.youtube.com/watch?v=vec-W4QeHQU YouTube video of Mozart&amp;#039;s Right Hand in action]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Centripetal_force Wikipedia: Centripetal Force]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Hand Wikipedia: The Hand]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus Wikipedia: Serial Peripheral Interface (SPI) bus)]&lt;br /&gt;
*[http://www.analog.com/en/mems-and-sensors/imems-accelerometers/adxl320/products/product.html AD9833 data sheet]&lt;br /&gt;
*The [http://lims.mech.northwestern.edu/ LIMS Laboratory] at [http://www.northwestern.edu Northwestern University]&lt;br /&gt;
*[http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010297 Microchip PIC18F4520]&lt;br /&gt;
*[[Guitar Tuning Project]]&lt;br /&gt;
*[http://www.datasheetcatalog.com/datasheets_pdf/T/D/A/2/TDA2040H.shtml TDA-2040 20-watt amplifier]&lt;/div&gt;</summary>
		<author><name>Mat Kotowsky</name></author>
	</entry>
</feed>