Stompbox Real Sensors

From CCRMA Wiki
Revision as of 04:24, 18 May 2011 by Eberdahl (Talk | contribs) (Using Analog Sensors)

Jump to: navigation, search

Lab 2: Controlling an Effect with Real Sensors
Due on Wednesday, July 20th at 9AM




* hook up button
* hook up pots
* hook up LED
* change to ring modulator





Download software

  • Make a Lab2/ folder for this lab.
  • Download the following:
    • Arduino Software
      • If you have never used an Arduino with your computer before, you need to install the FTDI driver that comes with the Arduino software; this enables your computer to recognize the USB serial communication chip on the Arduino.
    • Firmata firmware (use firmata2.0beta3.zip)
    • Either Maxuino or Pduino.

Power Connections

  • In order to run circuits on the breadboard, you need to get power to it. The Arduino gets 5V from the USB connection, so in this section you will make the 5V accessible to the breadboard.
  • Make sure that your Arduino is mounted at the very end of the breadboard with the higher-numbered rows, as shown in the following picture. In that case, the GND and 5V pins will end up in the 19th row. (Otherwise if your Arduino isn't mounted this way, you simply won't be able to rely on the row numbers, but you can still figure out how to wire things up!)
  • Recall first that that holes in the solderless bread board are wired together as shown:

Breadboard.png

  • Using short jumpers, connect the GND row to the blue "GND" bus on the breadboard, and connect the 5V row to the red "power" bus on the breadboard.
  • Connect the "GND" and "power" busses from both sides of the breadboard together as shown.

Circuit0-big.jpg


Viewed from further away, your breadboard should now look like the following:

Circuit0.jpg

First Circuit: Potentiometer

Now you will build the following voltage divider circuit, to connect one potentiometer to analog input A0.

Pot-A0.jpg

For some help on placing the wires, please see the following picture. In order to ensure the correct orientation, ensure that the text on the potentiometer is facing *away* from the Arduino (see also oblique picture in next section). Circuit2.jpg

Add A Second Potentiometer

Now connect a second potentiometer to analog input A3 using the same voltage divider circuit.

SBcircuit3-direct.jpg


Again, ensure that the text on the potentiometer is facing *away* from the Arduino (see the red boxes in the following figure):

SBcircuit3.jpg

Add A Button

Most stomp boxes have a button, so we include that as well according to the following circuit:

SBbutton-circuit.jpg

The corresponding picture of the bread board is shown below:

SBcircuit5.jpg

Buttons, Switches and LEDs

  • Here's how to wire a simple 2-resistor circuit on the solderless bread-board (for example R1 = 10K, R2 = 10K):

Jumper.png

What will A0 read?

(How do you know what resistor you have? Use the resistor calculator!)


Build the Button and LED Circuit

We'll start our tutorial with three simple light circuits.

  • In the first one, the LED is permanently on.
  • In the second, the LED only lights up when a button is pressed and a circuit is completed.
  • In the third example, we'll replace the manual switch with an Arduino pin (set to output mode), so we can control the LED from our program.

3Buttons.gif

Power a LED (always on)

Lab2-3.jpg

Build the following circuit on your breadboard. Use a 220Ohm resistor (red red brown gold).

Because the LED is a diode, it has a set voltage drop across the leads; exceeding this causes heat to build up and the LED to fail prematurely. So! It is always important to have a resistor in series with the LED.

Also, another consequence of the LED being a diode is that it has directionality. The longer lead, the anode, should be connected towards power; the shorter, cathode, should be connected towards ground. (In the photo, the longer lead has a bent "knee.")

Make a light switch

Next, we'll insert a switch into the circuit. The momentary switches in your kit are "normal open", meaning that the circuit is interrupted in the idle state, when the switch is not pressed. Pressing the switch closes the circuit until you let go again.

Lab2-4.jpg

Use a multimeter to see what happens to the voltage on either side of the LED when you press the switch.

Toggling LED with PD or Max

Lab2-5.jpg

In the third example, we'll replace the manual switch with an Arduino pin (set to output mode), so we can control the LED from our program. The safe way to do this is to let the Arduino pin sink current - if we toggle the pin low, it acts as ground and current flows through the resistor and the LED as it did in the previous examples. When we take the pin high, to 5V, there is no potential difference and no current flows - the LED stays off.

  • In the ArduinoLab patch, press the "toggling LED with software" button in the upper right to preset the outputs properly. The patch expects you to connect the LED to digital pin 2 (D2).


Optional: Try changing your patch so the light stays on when you press the mouse button, and stays off when you press it again. After that, change your patch so the light blinks on/off. Then, have your patch button switch the light between on and blinking.

Sensing buttons in software

We've used code to trigger output - what about the other direction, sensing physical input in code? Just as easy. Here is a simple switch circuit:

Switch.png Lab2-6.jpg

When the switch is open, the Arduino pin (set to input mode) is pulled to 5V - in software, we'll read Arduino.HIGH. When the switch is closed, the voltage at the Arduino pin falls to 0V - in software, we'll read Arduino.LOW. The pull-up resistor is used to limit the current going through the circuit. In software, we can check the value of the pin and switch between graphics accordingly.

  • In the ArduinoLab patch, press the "sensing buttons in software" button to preset the outputs properly. The patch expects you to connect the switch to digital pin 4 (D4).

Fading LEDs (optional)

What about those "breathing" LEDs on Mac Powerbooks? The fading from bright to dim and back is done using pulse-width modulation (PWM). In essence, the LED is toggled on and off rapidly, say 1000 times a second, faster than your eye can follow. The percentage of time the LED is on (the duty) controls the perceived brightness. To control an LED using PWM, you'll have to connect it to one of the pins that support PWM output - 9, 10 or 11 on the Arduino. Then write a patch that cycles the PWM values.

  • In the ArduinoLab patch, press the "Fading LEDs" button to preset the outputs properly. The patch expects you to connect the LED to digital pins 9-11 (D9-11).
  • In your Arduino Kit, you have a RGB LED which has four leads (it's white when not lit); it's basically like 3 LEDs sharing the same ground. Use PWM and this [pin out information] to make the LED cycle through a rainbow of colors.

Lab2-7.jpg


  • Connect the middle pin of the potentiometer to analog input 0, the other two to +5V and ground.
  • Through a 220Ohm resistor, connect an LED to pin 9(anode or long side to resistor, cathode to pin 9)
  • In the ArduinoLab patch, press the "Light Dimmer" button to preset the outputs properly. The patch expects you to connect the LED to digital pin 9 (D9) and the potentiometer to analog pin 0 (A0). Use the PWM controls under output controls in the ArduinoLab patch to control the lightness and dimness of the LED.

Putting it all Together

  • Create a patch to make sounds based on button and sensor values from the Arduino. You can try to adapt your patches from Lab 1, or come up with a new patch.
  • Try to make a simple musical interaction. Think about music -
    • does it have dynamics?
    • can you turn the sound off?
    • can it be expressive?




Appendix: 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.
  • Unarchive the Firmata firmware that you downloaded previously.
  • Connect your Arduino Nano to your computer using a USB cable.
  • Open StandardFirmata the Arduino software pull-down menus Examples|Firmata.
  • 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 or PD can talk to the Arduino board next.)


250a 2009