Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Tom Class

Class Notes: September 3, 2008

  • Transduction: the conversion of one type of energy into another
  • sensing the energy and inferring and converting into electrical energy and doing something useful with it
  • you can sense presence but you can't sense attention as easily
  • find another way to get them/user explicitly involved
  • Digital: measuring discrete units in binary (i.e. switches) Analogue: measuring a continuous wave (i.e. pentiometer)
  • Watts = Volts x Amps
  • Volts = Amps x Resistance
  • devices are designed to consume a specific amount (amps)
  • energy moves from highest to lowest energy
  • resistance eats up voltage
  • switch allows a circuit to be continuous or not
  • all the energy gets used up in a circuit
  • diodes control where energy is going.
  • pentiometer: variable resistor as analog sensor
  • photocell: variable resistor based on light
  • capacitor: store energy, act as surge suppressor, release it when they are turned off
  • LED (Light Emitting Diode): short leg - cathode / long leg - anode

Arduino: first king of Italy. c based syntax. tty: teletype, cu: unix type

methods and subroutines:

  • void setup(parameters) { }
  • void loop(parameters) { }
  • void means that this function doesn't return something
  • parameters are the modifiers of the command

Programming a Switch to turn an LED on/off:

void setup() {

  //tell the computer that pin 12 is an ouput
  pinMode(12, OUTPUT);
  //make pin 2 an input
  pinMode(2, INPUT);

}

void loop() {

  if (digitalRead(2) == HIGH) {
    //put 5V out of pin 12
    digitalWrite(12, HIGH);
  } 
  else {
    //put 0v out of pin 12
    digitalWrite(12, LOW);
  }

}


int switchPin = 2; int switchCounterVar = 0; int switchStateVar = 0; int lastSwitchStateVar = 0; long theTimer = 0; long theDifference = 0;

void setup() {

  pinMode(switchPin, INPUT);

}

void loop() {

  // read the switch
  switchStateVar = digitalRead(switchPin);
  // compare the switch to its previous state
  if (switchStateVar != lastSwitchStateVar) {
    // if the state has changed, increment the counter
    if (switchStateVar == HIGH) {
      // take note of when the button was pressed:
      theTimer = millis();     
    }
    // note how long the button was pressed for:
    if (switchStateVar == LOW) {
      theDifference = millis() - theTimer;
    }

    // save the current state as the last state,
    //for next time through the loop
    lastSwitchStateVar = switchStateVar;
  }

}

Class 2 Notes Mentioned that one week each person will enter their class notes to the class wiki.

Today: Analog input.

Note: Pins 0 and 1 on the Arduino are Tx and Rx for the Serial communication. Attached to the USB connection to upload/download the Arduino program. Using them may interfere with the communications.

Install FTDI drivers without the Arduino plugged in The USB ports will not show up unless the Arduino is plugged in Reinstall Arduino after installing a new driver. (did I hear this correctly?)

Encouraged enclosing lab projects in some way (a tissue box...etc) The placement of the buttons/enclosure will affect the user/human experience.

Switches wired with pull-down resistor (as shown in the Arduino documentation). When the switch is closed, the power can find ground, so the digital input reads LOW rather than HIGH in Tom’s example of a pull-up resistor.

Pull-up resistor schematic

Two-position switch. Middle is common ground and closes to either of the outside legs when the switch is in one of the positions. Multi-position switch (like John’s project)

Craig’s indicator lights: Conversation in interaction. The system tells you that it heard you. Get into the habit of building in some feedback so the user knows that the system is listening.

Use mechanical attachments when using fragile or large pieces of metal where soldering may not work. Conductive glue...or just shove them together somehow. Use female/male connectors with 0.1” spacing for some breadboard compatible components.

Making direct feedback makes the user more directly aware of their interaction rather than abstractions that have to be interpreted. Industrial designers can be lazy at times.

Using serial communication to speak to the Arduino:

void setup() {
	Serial.begin(9600);
}

void loop() {
	Serial.print(“Hello World”);
	delay(100);
}

Press “Serial Monitor” on the Arduino IDE toolbar

Tom presses the switch lead on the bottom of the Arduino. Without reference to power or ground, the input is “floating” - it’s acting as an antenna and picks up all stray electrical emissions...even those from your skin. Mentioned that it could be a good random number generator.

Resistors: How to determine the resistors. Determine the voltage a component needs, and how much you are providing to it and calculate the difference. Voltage is always measured as the difference between two points.

V = C*R (voltage = current * resistance)

Simple resistor diagram

Rule of thumb: Start with a big resistor and work down until the LED lights up. Use smallest LED as prudent. With a switch, start with a big resistor. Use biggest resistor as prudent.

There wiggle room in electronics.

Power regulators: Often have an input range and will convert to a steady output voltage.

Analog sensors:

  • Soft pot (potentiometer)
  • Force Sensing Resistor (variable range of resistance as pressure increases)
  • Photocell (variable resistance with light)
  • Thermistor - variable resistance based on heat

Analog inputs take in a variable voltage and use an Analog-Digital Convertor (ADC) to return an integer between 0-1023 (10-bit sensor, 2^10).

Voltage divider: Two resistors in series will split the voltage between them (that’s where you place the lead to the analog input). Equal resistors will split the current equally. The ratio of the two resistors will determine the voltage between. Assuming that the two are nominally equal, if the variable resistor drops then the voltage will go up, if the variable resistor goes up the voltage goes down.

Voltage divider

Flex sensors...use hot glue as a strain relief and as an insulator.

Wire up the switch and test with a fairly large resistor (10 kOhm - brown, black, orange. Look up Resistulator - OS X program)

Demo:

// Analog input

int analogValue = 0;

void setup() {
 Serial.begin(9600); 
}

void loop() {
  analogValue = analogRead(0);
  Serial.println(analogValue,DEC); // output acsii encoded decimal
}

Values from demo program are reporting a range from about 20-400. This indicates that the variable resistor and 10k are about equal.

Try using a 1k resistor. Now the range is about 0-66. Indicates a smaller range coming in to the analog input.

So, we can assume that the flex sensor’s range is about 5k min - 10k max resistance.

With this circuit, we’ll never see the full range...so, how much range do we need? What can the person sense? What can your display use?

Also, think about the physical construction of your components - this may affect the project as much as the components and code.

Potentiometer - has three leads Most reliable analog sensor we’re going to get.

Center pin goes to analog input, other two leads go to power and ground (separately, of course).

Love-O-Meter assignment.

  • thermistor - good for close-up, against skin - not good for atmospheric changes
  • flex sensors - good for fingers
  • galvanic skin response - resistance across skin
  • FSR - weight, pushing against something

convert an analog AC voltage (sound -1V - +1v) to 0-5V for the Arduino Divide the voltage with two equal resistors, and then feed that to the Analog input.

Back to digital switches:

Debounce Within a set time period check to see if the switch has changed. Simple example, with delays:

if(digitalRead(2) == HIGH) {
	delay(10);
	if(digitalRead(2) == HIGH)
		//success
	}
}

State change Look on Tom’s blog for Edge Detection: http://www.tigoe.net/pcomp/code

Variable sizes int variable: 2 bytes long variable: 4 bytes

Timers: use millis() to determine the milliseconds elapsed since the program began. store the time at a particular event, then subtract that time from the current time to determine the difference in time, or the duration of an event.

Pseudo-code:

long theTimer = 0;
long theDifference = 0;

void loop() {
	if(digitalRead == HIGH){
		theTimer = millis();
	}
	if(digitalRead == LOW){
		theDifference = millis() - theTimer;
	}
}

Haptic feedback on Tom's blog - electric shock feedback.

Reading discussion: http://library.books24x7.com/book/id_4587/viewer.asp?bookid=4587&chunkid=0532801905 There is a scale of interactivity. Design for the audience.

What does the person want to know; what does the person need to know; what do they want to be engaged in?

Become and expert in how people act; don’t necessarily become an expert in microcontrollers


Class 3 - Sep. 17, 2008

Fabrication and construction techniques (Pong game from net objects class)

  • Tupperware container as box/container
  • Holes on side of box to connect sensors and cables
  • LEDs hot glued, using single ground wire
  • LEDs and switches all in sequence on board and connected via single set of headers

Feedback from observation assignment

  • Same sounds triggered at subway turnstiles for successful and unsuccessful swipes
    • Raises issue of "value engineering" - what is cost effective vs. what provides the best experience
  • ATM and credit card readers illustrate how the technology of money is changing - though people still don't seem to get that it is no longer tangible/material
  • Likewise, technologies of identity are changing (biometrics, etc.)
  • Changes in behavior driven by technology reveal inadequacies in architecture
    • E.g. - people creating bottlenecks by standing around outside subway entrances talking on cell phones. Can't use phone in subway, no space provided for people who are "hovering"
  • Phantom phone syndrome - like phantom limb - people who aren't carrying a phone think that they feel phone ring vibration
  • Perceived time vs. actual time people are willing to wait is usually very different (waiting for elevator)
    • Good to calculate actual time of actions/responses in observations - they tend to be shorter than what we would estimate
  • Example of 'Close Door' button in elevator demonstrates how we can leverage people's mental models about how elevators work
    • Even if the button is disabled (as many supposedly are), it aligns with the user's sense of how the systems should work, and provides them with a sense of agency, which may be comforting in a setting where they are in reality at the mercy of the technology/system.

Electricity

  • Voltage = electromotive force, pressure, level of electrical energy
    • Potential difference (Voltage is always a measure of difference in energy between two points)
  • AC to DC converter
    • Polarity displayed in diagram on back
    • Most are 'center positive' - inside positive, outside/sleeve ground
    • Most electronics run on DC (using AC/DC converter)
  • Alternating current (AC) - electrical energy in circuit is switching polarity (direction of flow)
    • U.S. - 120 volts (polarity switching 60 times/sec)
    • More efficient to transfer over longer distances, less voltage3 drop over longer distances
  • Multimeter
    • Need to set to range you think you're going to measure
    • If DC adapter puts out 12 v, set to 20 v
    • 10ADC - jack used for measuring large amounts of amerage
    • VOLTS, OHMS, MILIAMPS - jack used for measuring most things
      • Red lead goes here
    • Com = common
      • Black lead goes here
    • Continuity
      • Used to determine if two things are connected to each other (i.e. - form a circuit)
  • Converting 12v into 5v
  • Arduino power selection switch
    • Can plug 12 v DC converter (or batteries) directly into jack, which gets converted to 5 v by onboard voltage regulator
  • Bookstore kits include 7805 voltage regulator (Not to be confused with TIP120 transistor) which fits into breadboard
    • Pin configuration - From L to R: Input, Ground, Output (IGOe)
    • Not ALL voltage regulators have this configuration. If uncertain, look up data sheet.
  • Can measure continuity to determine which part of the jack connects to power pin and which to ground pin
  • Ohm's law - describes relationship between voltage (V), current (I) and resistance (R)
    • Voltage = Current x Resistance (V = IR)
    • If we double voltage, halve resistance with same current
  • When resistors are in series, voltage drops across each resistor, and total R = sum of all resistors
    • Current across all three is constant
    • Total R = R1 + R2 + R3
  • Resistors in parallel
    • Voltage across them is constant (assuming they are of equal value)
    • Current is divided across each resistor, but total current (sum of all three) remains constant
    • 1/Total R = 1/R1 + 1/R2 + 1/R3

Class notes for Sept 24 remember to duplicate this on the itp help page.

Analog Output and Intro Servomotors.

This is an attempt at a transcipt of the class notes for PComp on 9.24.08. Please edit this if I misrepresented you or someone else, or you just really wish you would have said something at a specific time.

Begin class with Class Questions.

  • Bryan: Would a flickering LCD TV be appropriate for the junk pile.
  • Tom: Mostly it would be better to properly dispose of it, or get it repaired. Many disposal sites will not accept an incomplete device.
  • Robert: How do you determine the starting resistor value?
  • Tom: Ohm's law v=i*r.
  • Robert: in the context of a resistor ladder...?
  • Tom: When in parallel, use resistor calculators online. With LEDs, you can be a little more flexible as many resistors will light an LED.
  • Robert: I found I was getting about 1/2 the mA the LED was spec'd for...
  • Tom: you could 1/2 the resistors' value to make up the difference.

TALK ABOUT OBSERVATIONS and READINGS

  • Jeremiah: in design everyday things a material dictates its use. His last project was counterintuitive. The love-o-meter was a balsawood box that necessitated its smashing to trigger an led. Glass or brittle plastic may have been a better choice. subway car made of glass, replaced w wood they were carved; glass lends itself to smashing.
  • Tom: How can you encourage misuse?
  • Alex: (i missed hearing this statement).
  • Ted: Attatch implement for smashing?
  • Aly: Glowsitcks, break to activate.
  • Tom: Fear snapping glowstick when bending to actvivate it. Sonaar mass-emailed a haunted house collaborative project... surprise. How do you design surprise?
  • Robert: Create an expectation, and turn it on its head
  • Tom: For a large group?
  • Karla: lots of ideas
  • John: Create a diversion to the expectation.
  • Ted: With familiar signs you begin to recognize a pattern.
  • Tom: And to surprise you break a pattern. How do you watch another go through a surprising event and still be surprised yourself.
  • Karla: (missed this statement)
  • Ted: (missed this statement)
  • Karla: Timing
  • Ari: Create an entrance and an exit.
  • Brian: Have them turn a corner.
  • Robert: Have specific events.
  • Tom: Has anyone experienced an event where you see someone go through a surprise, but then were still surprised yourself?
  • Adam?: Rollercoaster?
  • Anthony: A spacial perception room in a funny house.
  • Patrick: A compelling illusion . perspective in manipulation. (elaborate please?)
  • Adam: misdirection
  • Alex: again, misdirection. looking around a corner.
  • Tom: Scaring uses randomness to break a pattern. how do you achieve sustained interaction in a haunted house?
  • Ted: create a variety in the experience.
  • Alex: Japanese horror movie practice, let the audience imagine the scare and never see it.
  • Ariel: Like the Janet Cardiff piece at SFMOMA that has you walk through familiar space watching a recording.
  • Bryan: Focussing on the narrative brings focus...
  • Tom: what is the narrative of the haunted house?
  • John: To get out.
  • Tom: In order to survive, you have to go through the whole thing. It has to be satisfying. Example; a bowl of jello... you can't see it but you have to reach in. It sets up a mental model that you have to claw through guts/brains to get a reward. Can you get someone to put their hand in again?
  • Many students: You previously chose the wrong key/ a combination lock requires going back for more.
  • Anthony: You can suggest by contrast. Placing a hot item near a cool item makes it seem colder than it is.
  • Tom: There's a tension of opposites.
  • Brian: Function n form. rhythm. example. art architecture. beauty overtakes function. Function comes first, no its about aesthetic too
  • Alex - I am reminded of the Gehry? dorm at MIT. Its odd angles and small windows gets in your head. Living in it gets to you.
  • Tom: This is also about surprise. It is pleasant as a first time visitor, I'm not sure how pleasant it is to live there. There is the ability to oversurprise, which takes us back to the haunted house.
  • Brian: ... What is the point of a steeple?
  • Ted: To be seen from afar.
  • Tom: To make you small in scale in comparison to god.
  • Anthony: It also symbolizes ascension to heaven.
  • Brian: ...Chedi? It is ironic that the ascension to god is so steep.
  • Tom: In the readings Norman touches on first mapping and feedback, and how those issues are addressed. Are there ways of setting alternative mappings that are easy to see?
  • Ted: 5 buttons... arranged to fingertips are mapped to intuitively use those fingers.
  • Alex- I bought an Arizona ice tea that had 4 finger grooves and one for the thumb satisfying, which was really satisfying when used correctly and a little awkward when used otherwise.
  • Patrick: With our relationship to controls... you guys talking more about constraints.
  • Robert: With a Stereo volume knob we learn that turning right raises the volume and left lowers, but an up and down slider would be more intuitive.
  • Patrick: On a stovetop, controls are mapped in the same configuration as the burners.
  • Tom: How could we use mapping to surprise? Pulleys; it's fun to watch their opposition. Different mapping dynamics affects how these things work out. A student had a project with a sensor and a light that she wanted a fade out rather than switch off. The floor sensor would not fade out as she wanted and she had to break connection to affect the light dimming.
  • Brian: How would that work in real life?
  • Craig: A piano?
  • Anthony: The piano strike is very complex.
  • Tom: The piano's hammer immediately lifts off to allow string to resonate,

leading us into...

analogWrite.

How you get a changing voltage output from microcontroller?

  • allows things like a fade out? *You can't generate a changing voltage from a microcontroller. *How do we do this?
  • Brian: Can you explain this?
  • Tom: IO pins are on and off. How do we make them fade something?
  • Karla: I did this for my love-o-meter. Depending on connections, with descending value. I don't think with the LED attached to an analog in
  • Tom: lets start with the usual setup.

void setup(){ pinMode (6, OUTPUT); }

void loop(){ int sensor = analogRead (0); analogWrite (6, sensor/4); //to compensate for bit depth }

with the LED connected to pin 6 and to ground the potentiometer connected to analog pin 0

The slide pot now dims the LED.

SIDENOTE: 269 Electronics on Canal St. is really worth checking out for components.

Tom: Now let's introduce a switch

A 10kOhm switch circuit into pin 2

//when we switch from off to on LED on then fades. //search codeblog for "edge detection"

int lastState = 0; int currentState = 0;

void setup(){ pinMode (2, INPUT); pinMode (6, OUTPUT); }

void loop(){ currentState = digitalRead(2);

if (currentState != lastState) { if (currentState == 1) { //Set the LED level//

ledLevel = 255; Serial.PrintIn("turned on"); }

lastState = currentState;

} turn on or off the LED analogWrite (6, ledLevel);

//fade the LED level; if (ledLevel >0) { ledLevel --; }

//serial monitor shows "turned on"//

Tom: Read the switch and compare to the previous reading. If not equal and current state is 1 take action. Regardless of on or off, we want to save that the current state equals last state. The Left side is the container, the Right is what you are putting into it.

On the video camera we see the LED doing a quick fade.

The baseline should be at 0, though analogWrite never truly goes to 0, when LED 0, can do a digitalWrite to get to 0.

  • Brian: Why 255?
  • Tom: AnalogWrite max bite is 255.
  • Brian: Why 9600 baud?
  • Tom: That happens to be a default of serial communications. OK

int lastState = 0; int currentState = 0;

void setup(){ pinMode (2, INPUT); pinMode (6, OUTPUT); }

void loop(){ currentState = digitalRead(2);

if (currentState != lastState) { if (currentState == 1) { //Set the LED level//

ledLevel = 255; Serial.PrintIn("turned on"); }

lastState = currentState;

} turn on or off the LED analogWrite (6, ledLevel);

//fade the LED level; if (ledLevel >0) { ledLevel --; else { //turn the LED off; digitalWrite (6,LOW); } }

Tom: The LED blinked, why?

turn on or off the LED analogWrite (6, ledLevel);

//fade the LED level; if (ledLevel >0) { turn on or off the LED analogWrite (6, ledLevel);

ledLevel --; } else { //turn the LED off; digitalWrite (6,LOW); }

}

Pulse Width Modulation, or PWM.

  • Robert: How is this set?
  • Tom: we want to get the frequency high enoght to fool the eye. Setting it depends on the application. If the LED can turn off in 5 microseconds, we want the PWM much faster than that.
  • Robert: Is it locked into that rate?
  • Tom: You could change the wiring, or C file if you wanted to, but arduino's frequency was designed for flexibiity.
  • Ted: Can we use a built in digital 0

missed information

  • Tom: It fades so fast that we can't see it fading how can we fade it slower?
  • Craig: Introduce a delay?
  • Jeremiah: Have a degredation every second loop; setup counter modulation
  • Tom: Counter and Decrement...
  • Tom: We are going to use the millis...

if (millis() - lastFadeTime >10){ //fade the LED level if (ledLevel >0) { turn on or off the LED analogWrite (6, ledLevel);

ledLevel --; } else { //turn the LED off; digitalWrite (6,LOW); } lastFadeTime = millis(); } }

  • Tom: this is a technique called time stamping.
  • Brian: why choose millis
  • Tom: I like millis. Previously we would have used a loop counter, but it's nice to know standard measurement of time.
  • Ted: What if long integer overflows?
  • Tom: on the 50th day it would overflow.
  • Tom: In any variable there is a maximum size. Enter 256 in a 255 value max, in our case 256 rolls over into 0. Most processors and compilers will roll value over to extreme value. This can be used to your advantage in the case of loop counter
  • Tom: what is the experiential efect of having LED and switch separated?
  • Adam: It makes you wait.
  • Ted: Instant fade does not.
  • Patrick: Web apps use fadeouts instead of a confirmation screen, they just fade out a message.

NOW code switched so that (currentState==1) switch release now activiates LED

  • Robert: The release now activates event.
  • Ted: ?
  • Tom: The reversed conditioned response is not an intuitive event. We are changing it's mapping. This can make people feel diffferent (spongy, sticky) about the event based on mapped actions.

This will be saved on the wiki as "fade_switch"

  • Tom: bri quest touch sensor. when event touch sensor
  • Robert: When the value decays
  • Tom: Yes. Peak detection.

set ledLevel to peak number, ex. 25

analogWrite can only be used on pins with PWM 3,5,6,9, 10, 11

NOW SERVOMOTORS!

RC servomotor or hobby servo motor. only turns 180deg, but can position precisely within those. Any motor will draw more current than the pins can provide. one servo maybe on usb power, but more than that is too much.

Arduino 12 has a simple servo library now. One limitation is that it can only run servo on PWM pins.

Tom: let's start with new way and work back to this.

in order to use the library, you have to import it. sketchbook\examples\library servo

Servo myservo; int potpin = 0; //

val = analogRead potpin)

map is neat function

floats take a lot of memory, don't use them here.

  • Aly: Seems like there are lots of applications for a haunted house here.
  • Ted: ?
  • Leon: How would you apply it to a haunted house?
  • Alex: Motors could move spiders up and down.
  • Leon: would a person have to move more than that to make it go up n down?
  • Tom: Imagine a piece of wire going up n down.
  • Aly: You could have it sense motion when someone comes by.
  • Robert: You could use it to open panels.
  • Tom: Opening and closing is clear, how do we use it to sense something is moving in the jello?...

There are many ways to do this; to have a person doing an action and creating an unexpected response.

Tom: There are many other types of motors.

  • DC motors, stepper motors, etc.
  • They use bigger controllable motors, use it yourself. ex. run motors from RC (Radio Controlled) cars.
  • Alex: What if you take out delay entirely?
  • Tom: Let's see...Not much different.
  • Brian: Are there servos that don't turn, but drag in a line?
  • Tom: flying-pig.co.uk has a whole section, under finding out, on mechanisms.
  • ex. irregular motion, cam shaft.

Don't forget, tips and tricks on laser cutter this friday.

1 millisecond is one extreme, 2 milliseconds is the other extreme, pulse every 20mS no matter what.

lets look at the code, also has instruction on map function

minPulse and maxPulse

lastPulse refreshTime

analog value for reading this ex can use any digital IO pins

turning pin on , delaying a couple microseconds, turning pin off

  • Brian: What is long?
  • Tom: long is long integer, ~16million and -16million
  • Ted: can make an un?
  • Tom: yes
  • Tom: All we are doing is declaring it to be a value.
  • Brian: What is the pulse?
  • Tom: Pulsetime is an electrical signal.

this method is in its delay.

the PWM that analogWrite uses has an independent piece of hardware that sets n forgets the thing.

  • Brian: What is refresh time?
  • Tom: Always 20 as set by servo manufacturer.
  • Tom: Using a device using pulsewidth, What can we do with pulse?

dim, sound,

  • There is no simple sound library for arduino yet, but there is a simple sound func.
  • Ted: How would you use that?
  • Tom: The Arduino playMelody example.
  • Tom: Speaker tone a pretty low because we cannot get a lot of volume out of the speaker. Lets take a listen.
  • Leon: What does "beats" control?
  • Tom: I'm faking it a little. "Beats" controls pauses between vibrations in the speaker. In code, PWM tells the speaker to play, pause, then play the next tone. Similar with millis, "rest" says do nothing for that duration. Clay looked at the code, and clay felt compelled to comment in.
  • Brian: Why is "R" listed for rest and "j" for rest later.
  • Tom: j gives the value of 0.
  • Brian: It's easier for me to understand music than other code.
  • Tom: Look for apps that are easier to understand.
  • Ted: Is it 8 bit on and off?
  • Tom: It can produce an 8 bit pulse.
  • Brian: How would you use it for a real piano sound?
  • Tom: Generating overtones is very complex. playnote generates a single tone. There's a buzzy sound because it's a square wave and not a sine.
  • Robert: Could you introduce a capacitor to round it out? digital out... can we input a table for analog input?
  • Tom: In theory . The capacitor does not change anything perceptibly.
  • This can produce a cute sound, not a very good sound. Think about the right tool for the job, what the tool you are using is good for, and how to use the tool for what it is good for.
  • if you want sound, get at it some richer way.
  • Anthony: Could you build your own ...
  • Tom: Juan Pablo Villamil did something with a digital pot.
  • Tom: Next week we'll talk about serial communication. This week during the lab, think about building something out. Think about the mapping to give a different quality to the interaction. When you start to control those things, you'll realize you have a really powerful toolbox.

TRANSISTORS...

as mentioned many times, arduino can only output a small amount of current. A transistor, consisting of a base, a collector and an emitter. TIP 120 better for motors and such. can use an NPN2222 transistor, which is better for general switching.

  • Ted: What is the maximum current output from the arduino?
  • Tom: 10-15 milliamps per output.
  • Ted: What are the requirements of the speaker? 8 ohms 25w.

so...

5v w=v*a

25w = 5v *

5=8ohms*current 5/8 of an amp (625mA)

/*reading for next week User Illusion. Attend a safety session or we will be shut down*/

How to look at datasheets for npn2222. digikey supplies datasheets. We notice there are many different models. TO-92 or TO-220 form factor? I am still looking for good site to explain electronic packages. ours is a PNPN2222a

Jeremiah: how did you determine that?

Tom: NPN PNP one is p-dote one is n-dote? The middle layer is where the base is, the middle layer changes the PNP voltage and makes it turn off; NPN makes it turn on. diodes are 1n, like the 1n4004 (Check out Mims', Getting Started in Electronics for an illustrated explanation of this)

The datasheet shows volt maxes at each pin. 6v max works fine for us working at 5v. Use transistors to control a awhole bunch of LEDs.

Robert: Would we need external power?

  • Tom: It's the only way to do it.

Tom: This is one way to get 12v through arduino.

  • Robert: switch jumper.

Alex: Since power is the same, why is it louder?

  • Tom: We've bypassed the minimal on-board power available from the arduino.

LED fading from a switch code from class today


October 8 code:

Arduino:

void setup() {
  Serial.begin(9600); 
  while (Serial.available() <= 0 ) {
   Serial.println("hello"); 
   delay(300);
  }
}

void loop() {
  if (Serial.available() > 0) {
    int inByte = Serial.read();

  int mySwitch = digitalRead(2);
  int x = analogRead(0);
  int y = analogRead(1);

  Serial.print(x, DEC);
  Serial.print(",");
  Serial.print(y, DEC);
  Serial.print(",");
  Serial.println(mySwitch, DEC);
  }
}

Processing:


import processing.serial.*;

Serial myPort;
boolean firstContact = false;

float xPos = 0.0;
float yPos = 0.0;
float visible = 0.0;

void setup() {
  size(600, 400);
  String portName = Serial.list()[0]; 
  println(portName);
  myPort = new Serial(this, portName, 9600);
  myPort.bufferUntil('\n');
}

void draw() {
  background(0);
  fill(visible);
  ellipse(xPos, yPos, 20, 20);
}

void serialEvent(Serial myPort) {
  String inputString = myPort.readStringUntil('\n');
  if (inputString != null) {
    inputString = trim(inputString);

    if (firstContact == false) {
      if (inputString.equals("hello")) {
        myPort.write("\n");
        myPort.clear();
        firstContact = true; 
      }
    } 
    else  {
      // println(inputString);
      int[] numbers = int(split(inputString, ","));

      for (int thisNum = 0; thisNum < numbers.length; thisNum++) {
        print(numbers[thisNum] + "\t"); 
      }
      println();

      // make sure you have enough numbers:
      if (numbers.length > 2) {
        xPos = map(numbers[0], 400, 600, 0, width);
        yPos = map(numbers[1], 400, 600, 0, height);
        visible = numbers[2] * 255;
      }
      myPort.write("\n");
    }
  }
}






October 26


Class begins by going over the schedule for the rest of the semester. Now that mid term projects are completed, we’ll be spending a lot of our time working through final projects. There will be specialized lessons being taught, however, classes will be less structured in terms of assigned labs.

Alex showcased his piece that involves using fans to ‘blow apart’ an image. The class spent time devising ways to construct a physical interface to manipulate the image in a myriad of ways. Some suggestions include: using a wiimote, a fan, IR light, conductive fabric, LED circular ring, etc.

Anthony asks about a q-prox(?) sensor to detect presence. Tom suggests using a capacitive touch sensor senses the capacitive field using an antenna. It can tell if someone is close to it (an inch or so). Anthony wants to work with electromagnetism in some way – he’s not entirely sure what he wants to do with it yet. Tom asks, “Are you trying to showcase a sensor? Or show how that sensor effects something else? Try to do the latter.” He also explains that multi-touch is difficult because of interference and insists of trying to use a sensor that ‘does it all’, find one that is the best one (or multiple sensors) for the job.

Jeremiah wants to improve the Arduino sound capabilities and enhance midi functionality. It’s a great idea and we discussed the feasibility and advantages of creating this (using a shield). The biggest advantage would be the portability (wearable) factor. However, there is a disadvantage in computing this kind of data on an arduino because its computer is small it could be inefficient – it might be better to simply transmit the midi data to a computer (which is much more powerful) via radio, especially if you will be amplifying sound using an external source. So, it’s something to consider – it all comes back to the same questions: “What is it’s intended use? How will you use it? And where will you be using it?” Many times it is beneficial to use existing protocols (ex: midi or serial), rather than developing your own because existing protocols often speak to multiple programming languages. This makes things much easier.

Another project idea has to do with ‘a history chair’, that records who has spent time sitting in the chair. While it displays images or video of people who have spent time sitting in the chair, it records you as well. It’s almost like a mirror. However, this may need to be expanded slightly because all of the videos will display people watching other people watching. So, the details will make this project work – you remember the details. Does the recording happen immediately when the user sits? Can lighting effect or invoke a response? Is this a gallery space, a school principal’s office, a bar stool or something else? Is a message being displayed that the user is supposed to react to? Maybe we could use a movie theater chair or try to find a way to create the illusion that other people are around you. These are important things to consider before you being working. The idea is to show that the user feels a sense that they are part of a larger audience.

Another project has to do with creating anti-paparazzi devices. For instance, a celebrity could rotate a purse (when a paparazzi dude appears) that would trigger an invisible flash located on a celebrities clothing that would ruin a photographer’s photographs. Perhaps it could use infrared LEDs that only the camera would pickup.

Next we switched gears and began talking about advanced serial processing.

What is important when considering using another protocol (such as midi) 1. How much data can I send? 2. How do we communicate with the protocol 3. How responsive is it

Asynchronous has two independent clocks and they sync up Synchronous is one clock that simply pulses and gets what it can.

Wiichuck uses synchronous serial.

Then we spoke about XBee. A modem converts data into a series of pulses or tones. A receiver can decode these tones back into serial data. The XBee works this way as well via radio. The protocol is 802.15.4 (XBee commands scheme).

Tom is showing how to communicate to an LCD screen using the XBee controller wirelessly from the desktop. Look ma, no wires!

The program that is on the arduino is simple. It simply pulses data to the XBee. We need a serial term to write to this. Tom is using ZTerm because of the way that the protocol is structured. There are two modes: Data mode and command mode. Data mode talks to the radio. Command mode speaks through the radio.

An AT command always starts with ‘AT’. For instance, ATDL sets the destination address. ATMY gets my address. ATID gets area networked identifier. ATID prohibits interference. The point is that we are configuring them so that we can communicate.

Bookstore sells XBee Explorer (about 20 bucks) as a receiver for your laptop that works with the XBee transmitter.

When typing in Zterm, everything is on one line, but you can changed this in ‘settings’ located in the menu bar of the program.

You can broadcast from one transmitter to multiple receivers.

XBee radios run on 3.3 volts. It’s best to use the breakout board for use with a breadboard.

The terminal will revert to data mode after 3 seconds, so it’s important to type ‘+++’ to return to command mode.

Typed into Zterm:

+++ AT101066 ATDL3 ATMY1 ATWR (writes it to chips permanent memory)

In processing, we can debug our circuit:


Import. Precessing.serial.*;

Serial myPort;

String myString;

Void setup()
{ 
   println(Serial.list());
   myPort = new Serial(this, Serial.list()[0], 9600)
}

void keyRelease()
{
   if(key == ‘ ‘)
   {
      myPort.write(myString + “\n”);
      myString = “”;
   } else {
     myString += key;
   }
}

code from 10/29/08

import processing.serial.*;


Serial myPort;
String myString;

void setup() {
  println(Serial.list() );
  myPort = new Serial(this, Serial.list()[0], 9600);
  myString = "";
}

void draw() {

}

// this part sends a string whenever you hit return.
// any other keys will be added to a string


void keyReleased() {
  if ((key == ENTER)|| (key == RETURN)) {
    // send the string
    myPort.write(myString + "\n");
    // clear my string:
    myString = "";

  } 
  else {
    myString += key;
  }
}

// this part is untested!!!!! It should change the addresss on the fly


void changeTheAddress(String newAddress) {
  String message = "";

  // send +++
  message += "+++";
  myPort.write(message +"\r");
  // wait a sec until it says OK
  while (inString != "OK") {
    // wait for incoming OK 
  }
  // send ATDL + address
  message += "ATDL";
  // send ATWR
  // Send ATCN

  myPort.write(message + newAddress + ",WR,CN" + "\r");


}










  Edit | View | History | Print | Recent Changes | Search Page last modified on October 29, 2008, at 06:02 PM