Lab 3: Circuits & Sensors

If you need more time to finish this lab you can come use the CCRMA facilities any time.

For this lab you need a Protoboard, Power Supply, Jumpers, Resistors, Sensors and one LED from the MaxLab.
Sensors: 2-buttons, 2-potentiometers, FSR, photo-resistor, IR Emitter-Detectors.

1. Flash AVRmini with meter.c.

a. Delete your existing avrlib/ and avrlib-demos directorys (after first making sure all the code you wrote yesterday is copied into your lab folder).

cd ~
rm -r avrlib
rm -r avrlib-demos

b. Re-run the setup file to update your avrlib and avr folders:

cd ~
/usr/ccrma/web/html/workshops/mid2005/setup

c. Create a lab3 folder in your MID folder. Copy avrlib-demos/meter there.

cd MID/
mkdir lab3
cd lab3
cp -r avrlib-demos/meter .

d. Flash AVRmini with meter.c.

This will turn your AVRmini 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 AVRmini. The voltages will be shown on the LCD.

IMPORTANT: use the set of pins on the 16-pin socket (shown in the diagram below) that are further from the AVR chip itself. As the diagram shows, there is a 100 Ohm resistor between each of the "inner" and "outer" pins; that resistor will prevent you from destroying the AVR chip unless you do something spectacularly wrong. Don't ever wire anything to the unprotected "inner" pins unless you know what you are doing.


Note that the signals are numbered starting at zero (A0 - A7) while the pins on the header that carry those signals are numbered starting at one (1 - 8).

2. Build sensor circuits.

Use components and jumpers to construct your circuits on the solderless bread-board.

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

a. Build the button and LED circuit.


On the left is the circuit, on the right, the diagram.
Try replacing the one button with two buttons in series or in parallel.

b. Hook-up sensors to A0 or A1 and watch the voltage change.

potentiometer:


force-sensitive resistor (FSR). Try both circuits.


photo-resistor (try a 1 megaohm resistor):

c. 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 B0 and B1. Wire up two buttons to B0 and B1 according to one of these two circuits. (The one on the left is recommended -- it is at 5v unless the button is pressed.)

Find a combination of buttons and sensors for playing a tune. Practice playing so you have something to demo in class tomorrow morning.

3. Read sensor values to PD.

Using osctest.c (in the avrlib-demos) and osctest.pd, send data from your protoboard circuits (analog input on A0 and A1), and to PD. Note: we use the Pd dumpOSCSerial object to read OSC data from the serial port. When you open a patch containing a dumpOSCSerial object, that object takes over the serial port, so that uisp can no longer dowload new programs to the AVR chip while the patch is open. In other words, you must close osctest.pd whenever you do a make load.

Let A0 "float" while A1 is tied to a potentiometer by removing the wire from its socket. What happens to A0's value when A1is changed? Try the same experiment with the PORTB[4-7] buttons. Why does this happen? How can we prevent it?

OPTIONAL: Encoders

Try wiring up an encoder to use with encoder.c. Use the following circuit diagram.

 

Read encoderconf.h to figure out which pins on the AVRmini to wire the encoder to!

Thanks to Bill Verplank for his wonderful lab sketches!