250a Homemade Digital Musical Instrument

From CCRMA Wiki

(Difference between revisions)
Jump to: navigation, search
(Learning More)
 
(5 intermediate revisions not shown)
Line 1: Line 1:
-
<font size=5>Homemade Digital Musical Instrument</font><br>
 
Demo at the 159th Meeting of the Acoustical Society of America
Demo at the 159th Meeting of the Acoustical Society of America
For the Session Homemade Musical Instruments for Teaching Acoustics
For the Session Homemade Musical Instruments for Teaching Acoustics
by [http://ccrma.stanford.edu/~eberdahl Edgar Berdahl] and [http://www-cdr.stanford.edu/~wendyju/ Wendy Ju]
by [http://ccrma.stanford.edu/~eberdahl Edgar Berdahl] and [http://www-cdr.stanford.edu/~wendyju/ Wendy Ju]
-
 
'''This page can be reached on the WWW at [http://ccrma.stanford.edu/wiki/250a_Homemade_Digital_Musical_Instrument http://ccrma.stanford.edu/wiki/250a_Homemade_Digital_Musical_Instrument]'''
'''This page can be reached on the WWW at [http://ccrma.stanford.edu/wiki/250a_Homemade_Digital_Musical_Instrument http://ccrma.stanford.edu/wiki/250a_Homemade_Digital_Musical_Instrument]'''
 +
 +
== Setup ==
 +
Very broadly, a PID setup allows computers to react progammatically to events in the physical world.  Actions, events and states are detected by sensor circuits, which convey signals to an embedded microcontroller, which in turn addresses a computer program. The computer program can then respond by producing sound and graphics, or it can pass commands back to an embedded processor, which can effect action, sound, or display through the use of electronics.
 +
 +
[[Image: diagram1.png]]
 +
 +
For this tutorial, we will be using breadboards and [http://www.arduino.cc/en/Main/ArduinoBoardNano Arduino Nanos] running [http://firmata.org/wiki/Main_Page Firmata], as platforms for the sensor circuit and embedded microcontroller, respectively. On your computer, you will be using MAX/MSP or PD, graphical programming environments that use a patch-programming model and enable sound synthesis.
 +
 +
[[Image: diagram3.png]]
 +
Line 36: Line 44:
== Install Pure Data Onto Your Computer ==
== Install Pure Data Onto Your Computer ==
-
Install [http://puredata.info/downloads Pure Data Extended] onto your computer.
+
Install [http://puredata.info/downloads Pure Data Extended] (Pd) onto your computer.
* Do NOT install the vanilla version of Pd!
* Do NOT install the vanilla version of Pd!
* Mess around with Pd a little bit to get a feel for it.  Go through some of the tutorials in the Help|Brower menu.
* Mess around with Pd a little bit to get a feel for it.  Go through some of the tutorials in the Help|Brower menu.
* In order to use the bowed string instrument synthesizer called Bowed~, you will need to install [https://ccrma.stanford.edu/wiki/Stk2pd Stk2pd], which ports the Synthesis Toolkit to Pd.
* In order to use the bowed string instrument synthesizer called Bowed~, you will need to install [https://ccrma.stanford.edu/wiki/Stk2pd Stk2pd], which ports the Synthesis Toolkit to Pd.
-
* Search your hard disk for the file ''Bowed~-help.pd'' and open it.  See what it is like to employ a physical model to synthesize sound.
+
* Search your hard disk for the file ''Bowed~-help.pd'' and open it.  Experiment with what it is like to employ a physical model to synthesize sound.
Line 87: Line 95:
[[Image: Softpotcircuit.jpg]]
[[Image: Softpotcircuit.jpg]]
-
The final circuit is shown below.  A white wire connects the Softpot's center terminal to the Arduino's analog input A0 pin at row 60.  This row is also connected to the ground (0V) rail by way of a 100kOhm (yellow-black-brown) resistor, and it connects to D6 by way of row 57 on the opposite side of the Arduino board.  The Arduino's D5 pin at row 56 connects to the leftmost terminal of the Softpot via a black wire running underneath the board (not shown).  Finally, the rightmost terminal of the Softpot connects to the ground (0V) rail by way of a short blue wire.
+
The final circuit is shown below.  A white wire connects the Softpot's center terminal to the Arduino's analog input A0 pin at row 60.  This row is also connected to the ground (0V) rail by way of a 100kOhm (yellow-black-brown) resistor, and it connects to D6 by way of row 57 on the opposite side of the Arduino board with a 1kOhm (brown-red-black) resistor.  The Arduino's D5 pin at row 56 connects to the leftmost terminal of the Softpot via a black wire running underneath the board (not shown).  Finally, the rightmost terminal of the Softpot connects to the ground (0V) rail by way of a short blue wire.
[[Image: Finalcircuit.jpg]]
[[Image: Finalcircuit.jpg]]
Line 93: Line 101:
== Run The Program  ==
== Run The Program  ==
-
Download [http://ccrma.stanford.edu/courses/250a/labs/extra/violin-demo.zip violin-demo.zip] and extract its contents.  '''*violin-demo.pd''' is the main patch.  Open it in Pd.  You will find that it is a version of '''Arduino-test.pd''' that has been adapted to control the '''Bowed~''' STK object.  If it does not choose the correct port, choose different serial port #'s until the Pd window says that it is connected to a tty usbserial device.
+
Download [http://ccrma.stanford.edu/courses/250a/labs/extra/violin-demo.zip violin-demo.zip] and extract its contents.  '''*violin-demo.pd''' is the main patch.  Open it in Pd.  You will find that it is a version of '''Arduino-test.pd''' that has been adapted to control the '''Bowed~''' STK object.  A compiled version of Bowed~ is included for Mac only in case you had any problems installing Stk2Pd.  If the Pd patch does not choose the correct port to communicate with the Arduino, choose different serial port #'s until the Pd window says that it is connected to a tty usbserial device.
To help make it more clear what is happening, open the '''handle-switching''' subpatch.  Every 50ms it switches back and forth between the two sensing modes described above for the Softpot.  The sensed position is shown with the horizontal slider, and the sensed position is shown with the vertical slider.  These raw inputs are passed out of this subpatch into another subpatch called '''pd synth-sound'''.
To help make it more clear what is happening, open the '''handle-switching''' subpatch.  Every 50ms it switches back and forth between the two sensing modes described above for the Softpot.  The sensed position is shown with the horizontal slider, and the sensed position is shown with the vertical slider.  These raw inputs are passed out of this subpatch into another subpatch called '''pd synth-sound'''.
Line 99: Line 107:
[[Image: Handleswitching.jpg]]
[[Image: Handleswitching.jpg]]
-
Enjoy playing the instrument!  If you don't like the note mappings, change the contents of '''pd handle-buttons''', or go create your own musical instrument!
+
Enjoy playing the instrument!  If you don't like the note mappings, change the contents of '''pd handle-buttons''', or go on to create your very own homemade, digital musical instrument!
Line 114: Line 122:
== Learning More ==
== Learning More ==
-
Come take our [https://ccrma.stanford.edu/workshops/new-music-controllers-nmc New Music Controllers] workshop!
+
Come take our [https://ccrma.stanford.edu/workshops/new-music-controllers-nmc New Music Controllers] workshop! For information about where to find additional parts, please see our [http://ccrma.stanford.edu/wiki/MaxLab#Supplies parts list].
<center>[[250a 2010]]</center>
<center>[[250a 2010]]</center>
[[Category:250a]][[Category:PID]]
[[Category:250a]][[Category:PID]]

Current revision as of 20:09, 16 April 2010

Demo at the 159th Meeting of the Acoustical Society of America For the Session Homemade Musical Instruments for Teaching Acoustics

by Edgar Berdahl and Wendy Ju

This page can be reached on the WWW at http://ccrma.stanford.edu/wiki/250a_Homemade_Digital_Musical_Instrument

Contents

Setup

Very broadly, a PID setup allows computers to react progammatically to events in the physical world. Actions, events and states are detected by sensor circuits, which convey signals to an embedded microcontroller, which in turn addresses a computer program. The computer program can then respond by producing sound and graphics, or it can pass commands back to an embedded processor, which can effect action, sound, or display through the use of electronics.

Image: diagram1.png

For this tutorial, we will be using breadboards and Arduino Nanos running Firmata, as platforms for the sensor circuit and embedded microcontroller, respectively. On your computer, you will be using MAX/MSP or PD, graphical programming environments that use a patch-programming model and enable sound synthesis.

Image: diagram3.png


Mount your Arduino Nano on your breadboard

We will be powering the Nano and the breadboard with current from the USB port, which is good for up to 500mA of 5 V±5%-- probably enough for most input circuits, although not enough if you plan to run a lot of LEDs or motors.

  • The Nano should sit at the bottom of the breadboard, so that the pins lie in rows 49-64 on either side.
  • Using jumper wires, connect the row 52 pin (GND) on the left side of the Nano to the blue ground (GND) rail.
  • Connect the row 52 pin (+5V) on the right side of the Nano to the red Power rail.
  • Use jumper wires to connect the power and GND rails on the left side of the breadboard to the right.

Image:Lab2-2.jpg


Install Firmata onto your Arduino Nano

  • Install the Arduino software
    • Unarchive the file, and move it to your applications folder.
    • Install the FTDI driver that comes with the Arduino software so that your computer will recognize the Arduino when it is plugged into the USB port.
  • Open the Arduino software.
  • Download the newest version of Pduino, unarchive it, and use the Arduino software program to open StandardFirmata.pde, which lies inside the folder Firmata-2.1:Firmata:examples:StandardFirmata.
  • Connect your Arduino Nano to your computer using a USB cable.
  • Use Tools->Board and Tools->Serial Port to select the Arduino Nano (Atmega 328) and USBserial tty port, then hit the Play button to verify and compile the program.
  • Upload the Firmata firmware to your Arduino Nano using upload button, the fourth square button from the left (the one with the sideways arrow).
  • Close the Arduino program. (This is important because it frees up the USB serial port so that Max/MSP or PD can talk to the Arduino board next.)


Install Pure Data Onto Your Computer

Install Pure Data Extended (Pd) onto your computer.

  • Do NOT install the vanilla version of Pd!
  • Mess around with Pd a little bit to get a feel for it. Go through some of the tutorials in the Help|Brower menu.
  • In order to use the bowed string instrument synthesizer called Bowed~, you will need to install Stk2pd, which ports the Synthesis Toolkit to Pd.
  • Search your hard disk for the file Bowed~-help.pd and open it. Experiment with what it is like to employ a physical model to synthesize sound.


Wire Up Some Switches To Your Board

Here is the schematic for each switch. Closing the switch pulls the input to the Arduino to 0V; otherwise, if the switch is open, the voltage is about 5V.

Image: switch.png

Take each of the switches that you see here,

Image: Switchuncut.jpg

and cut off the extra lead as shown to make it easier to mount into the protoboard.

Image: Switchcut.jpg


Wire up the first switch as shown below with the middle pin placed in row 42 and the end pin in row 41:

Image: Oneswitch.jpg

Connect a 220 Ohm (red-red-brown) resistor between row 42 and the supply voltage 5V (the red rail). Also connect row 42 to row 58, which connects to pin A2 of the Arduino. Finally connect row 41 to ground (0V).


Connect up the other switches in the same fashion to the analog input pins A3, A4, and A5 of the Arduino:

Image: Fourswitches.jpg

Open up the file arduino-test.pd in Pd to check that the switches work. You will have to go into the subpatch pd old analog/digital controls in order to enable ananlog inputs A2-A5. (We could have used digital inputs instead since we only care if the switches are on or off, but the wiring was more convenient this way.)


Wire Up The Force-Sensing Resistive Strip

For more info on more common force-sensing resistors and other sensors, see this page. Here we have the circuit for SoftPot force sensing resistive strip and we show how it corresponds to the package. It has three terminals like a normal potentiometer, but there is an additional (variable) resistor connected to the center terminal.

Image: Softpot.jpg


We connect it up to the Arduino using a special circuit so that it can be employed for both measuring position and pressure. When the Arduino's digital pin D5 is set to output HIGH, corresponding to about 5V, and when D6 is set to input, so it presents a high impedance, the circuit measures position like a normal potentiometer circuit. On the other hand, if D6 is set to output HIGH, corresponding to about 5V, and D5 is set to LOW (0V), then the circuit approximately measures pressure.

Image: Softpotcircuit.jpg

The final circuit is shown below. A white wire connects the Softpot's center terminal to the Arduino's analog input A0 pin at row 60. This row is also connected to the ground (0V) rail by way of a 100kOhm (yellow-black-brown) resistor, and it connects to D6 by way of row 57 on the opposite side of the Arduino board with a 1kOhm (brown-red-black) resistor. The Arduino's D5 pin at row 56 connects to the leftmost terminal of the Softpot via a black wire running underneath the board (not shown). Finally, the rightmost terminal of the Softpot connects to the ground (0V) rail by way of a short blue wire.

Image: Finalcircuit.jpg


Run The Program

Download violin-demo.zip and extract its contents. *violin-demo.pd is the main patch. Open it in Pd. You will find that it is a version of Arduino-test.pd that has been adapted to control the Bowed~ STK object. A compiled version of Bowed~ is included for Mac only in case you had any problems installing Stk2Pd. If the Pd patch does not choose the correct port to communicate with the Arduino, choose different serial port #'s until the Pd window says that it is connected to a tty usbserial device.

To help make it more clear what is happening, open the handle-switching subpatch. Every 50ms it switches back and forth between the two sensing modes described above for the Softpot. The sensed position is shown with the horizontal slider, and the sensed position is shown with the vertical slider. These raw inputs are passed out of this subpatch into another subpatch called pd synth-sound.

Image: Handleswitching.jpg

Enjoy playing the instrument! If you don't like the note mappings, change the contents of pd handle-buttons, or go on to create your very own homemade, digital musical instrument!


How To Play It

Image: Lefthand.jpg Image: Righthand.jpg Image: Bothhands.jpg

I don't know why I was in the holiday spirit, but anyway here are two sound examples:

violin1.wav

violin2.wav


Learning More

Come take our New Music Controllers workshop! For information about where to find additional parts, please see our parts list.


250a 2010
Personal tools