Difference between revisions of "Hardware Lab 2"

From CCRMA Wiki
Jump to: navigation, search
(Buttons, Switches and LEDs)
(Install Firmata onto your Arduino Nano)
Line 5: Line 5:
  
 
== Install Firmata onto your Arduino Nano ==
 
== Install Firmata onto your Arduino Nano ==
 +
 +
* In the Arduino IDE, use File -> Open -> Examples > Library-Firmata > StandardFirmata to load the standard firmware.
 +
* Connect your Arduino Nano to your computer using a USB cable.
 +
* Use Tools->Board and Tools->Serial Port to select the Arduino Nano and USBserial tty port, then hit the Play button to verify and compile the program.
 +
*Upload the Firmata firmware to your Arduino Nano using the fourth square button from the left (the one with the sideways arrow).
  
 
== Download patches for Max/MSP or PD ==
 
== Download patches for Max/MSP or PD ==

Revision as of 14:33, 22 June 2009

Assigned Tuesday June 23
(back to PID2009 homepage)

For this lab you need your PID Kit, and Max/MSP or PD installed.

Install Firmata onto your Arduino Nano

  • In the Arduino IDE, use File -> Open -> Examples > Library-Firmata > StandardFirmata to load the standard firmware.
  • Connect your Arduino Nano to your computer using a USB cable.
  • Use Tools->Board and Tools->Serial Port to select the Arduino Nano and USBserial tty port, then hit the Play button to verify and compile the program.
  • Upload the Firmata firmware to your Arduino Nano using the fourth square button from the left (the one with the sideways arrow).

Download patches for Max/MSP or PD

  • The (patch) will turn your Arduino Nano into a rudimentary multimeter with two inputs. Use a jumper from the point at which you want to measure the voltage to A0 or A1 on the Nano. The voltages will be shown on the patch.
  • Note that the signals are numbered starting at zero (A0 - A7). The 8-bit analog to digital conversion gives 0..255.


Buttons, Switches and LEDs

  • Build the circuit that is detailed in the following figures. Use components and jumpers to construct your circuits on the solderless bread-board.

Breadboard.png

  • 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.

(If you don't know anything about circuits, Dan O'Sullivan's Physical Computing Circuits page is a fabulous introduction.)

3Buttons.gif

  • Try replacing the one button with two buttons in series or in parallel.

Hook-up Sensors to A0 or A1 and Watch the Voltage Change

  • potentiometer:

Pot.png

  • force-sensitive resistor (FSR):

FSR.png

Try both circuits. Test the resistance range of your sensor. If you want 2.5 volts to be the middle, make the comparison resistor (33k in the diagram) the "average" value of the FSR's resistance. Test this with a multimeter.

  • Bend Sensor

Bend sensor.png

  • photo-resistor:

Photo.png

  • Reflective Optical Sensor:

Optical.png

The Musical AVRmini

  • The program running on the AVR will beep at frequencies controlled by the voltages on A0 and A1 when you press buttons on S6 and S7 on the display. Wire up four buttons to each of the B4-7 pins (this are the pins B4, B5, B6 and B7 in PORT B) according to one of these two circuits. (The one on the left is recommended -- it is at 5v unless the button is pressed.) Check that you can read in the AVR display the buttons on port B4-7.

Read Sensor Values to PD

Using osctest.c (in the avrlib-demos):

                         ~> cd ~/pid2008/lab2
            ~/pid2008/lab2> cp -r ../avrlib-demos/osctest .
            ~/pid2008/lab2> cd osctest
    ~/pid2008/lab2/osctest> make load

and osctest.pd:

   ~/pid2008/lab2/osctest>  pd osctest.pd &

send data from your protoboard circuits (analog input on A0 and A1), and to PD.

  • Note: we use the Pd [serialIO] object to read OSC data from the serial port. When you open a patch containing a [serialIO] object, you must send it a [start] message in order to begin polling the USB port. If you want to reprogram your AVR, you should send [serialIO] a [close] message to release the port for the AVR downloader to use, then you can do a make load. When you want to resume using [serialIO], you should send it a message [open /dev/ttyUSB0] to reopen the port, followed by [start] to resume polling.
  • Let A0 "float" while A1 is tied to a potentiometer by removing the wire from its socket. What happens to A0's value when A1 is changed? Try the same experiment with the PORTB[4-7] buttons. Why does this happen? How can we prevent it?


Putting it all Together

  • Create a Pd patch to make sounds based on button and sensor values from the AVR. You can try to adapt your patch from Lab 1, or come up with a new patch. You can also use as a starting point the patch osctestsoundout.pd, located in the same folder.
  • Try to make a simple musical interaction. Think about music -
    • does it have dynamics?
    • can you turn the sound off?
    • can it be expressive?
  • You may need to make a copy of osctest and modify it to send the appropriate control signals.
PID 2008