Archive for October, 2009

ICM Midterm Project

For my ICM midterm project I want the user to choose a series of of websites that they identify with and using rss feeds compose a text-ural representation of themselves. To view the actual processing app and code visit: http://www.zevenrodriguez.com/itp/icm/midterm/

This would be the first prompt

firstpage

After to press start it should either take a video capture or a image of you and create the display below

output

Lab 7 – Serial Communication 2 and Handshaking

For this lab we were doing more advanced serial communication with the arduino and processing. I used 2 pins of an accelerometer and a pot. The hardest part of this lab is the handshaking aspect. The reason it is tricky is because the different types, punctuation and handshaking. The handshaking makes sure that the information does not get backed up in the buffer.

This arduino code sends the information in this format 0,0,0. The punctuation method would just be the code with out this function establishContact(); and this if(Serial.available()>0) . With these 2 parts, we establish the handshake method between the arduino and processing. When the “hello” is sent from the arduino code, the processing code picks it up and sends back a character. This enables processing to get information when it needs it.

Arduino Code

int analogOne = 0; // analog input
int analogTwo = 1; // analog input
int analogThree = 2; // digital input

int sensorValue = 0; // reading from the sensor

void setup() {
// configure the serial connection:
Serial.begin(9600);
// configure the digital input:
// pinMode(digitalOne, INPUT);
establishContact();
}

void loop() {
if(Serial.available()>0){
// read the sensor:
sensorValue = analogRead(analogOne);
// print the results:
Serial.print(sensorValue, DEC);
Serial.print(“,”);

// read the sensor:
sensorValue = analogRead(analogTwo);
// print the results:
Serial.print(sensorValue, DEC);
Serial.print(“,”);

// read the sensor:
sensorValue = analogRead(analogThree);
// print the last sensor value with a println() so that
// each set of four readings prints on a line by itself:
Serial.println(sensorValue, DEC);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println(“hello”); // send a starting message
delay(300);
}
}

Processing Code
import processing.serial.*; // import the Processing serial library
Serial myPort; // The serial port

float bgcolor; // Background color
float fgcolor; // Fill color
float xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we’ve heard from the microcontroller

void setup() {
size(640,480);
background(255);
smooth();
// List all the available serial ports
println(Serial.list());

// I know that the first port in the serial list on my mac
// is always my Arduino module, so I open Serial.list()[0].
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[0], 9600);

// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil(‘\n’);

}

void draw() {

fill(random(255),fgcolor,random(255), random(255));
noStroke();
// Draw the shape
ellipse(xpos, ypos, 100, 100);
}

// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():

void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(‘\n’);
// if you got any bytes other than the linefeed:
if (myString != null) {

myString = trim(myString);

if (firstContact == false) {
if (myString.equals(“hello”)) {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you’ve had first contact from the microcontroller
myPort.write(‘A’); // ask for more
}
}

else{

// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ‘,’));

// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print(“Sensor ” + sensorNum + “: ” + sensors[sensorNum] + “\t”);
}
// add a linefeed after all the sensor values are printed:
println();
if (sensors.length > 1) {
xpos = map(sensors[0], 0,400,0,width/2);
ypos = map(sensors[1], 0,400,0,height/2);
fgcolor = sensors[2] / 4;
}

}
myPort.write(“A”);
}
}

Physcomp Lab7 – Serial Lab 2 from Zeven Rodriguez on Vimeo.

Observation: The Brita Filter

Observation. Pick a piece of interactive technology in public, used by multiple people. Write down your assumptions as to how it’s used, and describe the context in which it’s being used. Watch people use it, preferably without them knowing they’re being observed. Take notes on how they use it, what they do differently, what appear to be the difficulties, what appear to be the easiest parts. Record what takes the longest, what takes the least amount of time, and how long the whole transaction takes. Consider how the readings from Norman and Crawford reflect on what you see.

filter

Reaction

The piece of technology I chose was a very simple low tech water purifier that had a short life span on the ITP floor. The technology is called the Brita filter. At first, the Brita filter seems to be designed nicely. Its has a very round shape and its white which makes it seem clean and streamline. This I think is the biggest flaw with the Brita filter. It took me a second to figure out how to switch between purified water and tap water. The knob was tough to grab if your hands get wet and the knob seemed to spin continuously. The nail on the coffin for the Brita filter was when I observed some people not realizing that they were washing dishes with the filtered water. I think this happened because people are not invested in the technology. People tend to take for granted that things happen automatically.

I think the biggest problems with the Brita filter could be fixed some what easily. First would be a more visual indicator that you are using purified water (even if they come out of different orifices). The second would be a larger lever as the switch. The Brita filter helps with using countless water bottles. If you do not make it able to become second nature then the technology fails. Sadly, the filter is now gone.

Physcomp Lab6 – Serial Communication

Using Serial Communication with Arduino and Processing was not too bad.

The arduino code is simple. We are using a Pot put in pin0 and doing a basic analogread. The import things about this whole lab is that you make sure you always close the serial monitor, because only one application could read the serial stream.

int analogPin = 0;
 int analogValue = 0;

 void setup()
 {
   // start serial port at 9600 bps:
   Serial.begin(9600);
 }

 void loop()
 {
   // read analog input, divide by 4 to make the range 0-255:
   analogValue = analogRead(analogPin);
   analogValue = analogValue / 4;
   Serial.print(analogValue, BYTE);
   // pause for 10 milliseconds:
   delay(10);
 }

Once you upload close the Arduino application. So you avoid any serial issues. Open processing. I simply altered some code and made a sort of paint brush. Here is the code.
import processing.serial.*;

Serial myPort; // The serial port
int graphXPos = 1; // the horizontal position of the graph:
float randNum = 0;
void setup () {
size(640, 480); // window size

// List all the available serial ports
println(Serial.list());
// I know that the fisrt port in the serial list on my mac
// is usually my Arduino module, so I open Serial.list()[0].
// Open whatever port is the one you’re using.
myPort = new Serial(this, Serial.list()[0], 9600);

// set inital background:
background(255);
smooth();
}
void draw () {
// nothing happens in draw. It all happens in SerialEvent()
}

void serialEvent (Serial myPort) {
// get the byte:
int inByte = myPort.read();
randNum = random(255);
// print it:
println(inByte);
// set the drawing color. Pick a pretty color:
fill(randNum, randNum);
noStroke();
// draw the ellipse:
ellipse(graphXPos, inByte*2, 100, 100);

// at the edge of the screen, go back to the beginning:
if (graphXPos >= width) {
graphXPos = 0;

}
else {
// increment the horizontal position for the next reading:
graphXPos++;
}
}

Physcomp Lab6 – Serial Communication from Zeven Rodriguez on Vimeo.

ICM Week5 XML and Processing

This project was using Simplml and Processing to pull in the netflix top 100 and takes all of the titles and counts the amount of a specific letter there are in the titles. The image below shows the graphic representation of this. There are 26 boxes. The darker the box the lest amount of letters there are. The issue I current have is figuring out how to use PFont with objects.

week5

Here is the code

Main code

Letter Object

import simpleML.*;
letter[] table = new letter[26];
char[] rssTemp;
int rssLength = 0;
String[] headlines;
String headlinesTemp;
int row = 0;
int modInterval = 6;
int modNumber = 0;
int[] letterAmount = new int[26];
PFont f;
int letterPosX = 0;
int letterPosY = 0;

void setup(){
size(635,480);
smooth();
background(255);
f = createFont( ” Arial ” ,3,true); // Loading font
for(int i = 0; i

if(i < 6){ row = 0; table[i] = new letter( i , row ,106,96); } if((i >=6) && (i<12)){ row = 96; modNumber = i%modInterval; table[i] = new letter( modNumber , row ,106,96); } if((i >=12) && (i<18)){ row = 192; modNumber = i%modInterval; table[i] = new letter( modNumber , row ,106,96); } if((i >=18) && (i<24)){ row = 288; modNumber = i%modInterval; table[i] = new letter( modNumber , row ,106,96); } if(i>=24){
row = 384;
modNumber = i%modInterval;
table[i] = new letter( modNumber , row ,106,96);
}

}

//end of array parsing
XMLRequest xreq = new XMLRequest(this,”http://rss.netflix.com/Top100RSS”);
xreq.makeRequest();

}

void draw(){
for(int i = 0; i
0){
for(int i =0; i< rssLength;i++){ char c = headlinesTemp.charAt(i); if (c >= 97 && c <= 122) {
letterAmount[c-97]++;
}
//println(c);
}// end of i for loop

}//end of b loop

for(int i = 0; i < letterAmount.length; i++){
//println((char) (z+97) + ” ” + letterAmount[z]);
table[i].setAmount(letterAmount[i]);

textFont(f,16);
textAlign(LEFT);
text(letterAmount[i],letterPosX + 10,letterPosY +10);
/*
if(i < 6){ letterPosY = 0; letterPosX = i*106; } if((i >=6) && (i<12)){ letterPosY = 96; letterPosX = ((i%modInterval)*106); } if((i >=12) && (i<18)){ letterPosY = 192; letterPosX = ((i%modInterval)*106); } if((i >=18) && (i<24)){ letterPosY = 288; letterPosX = ((i%modInterval)*106); } if(i>=24){
letterPosY = 384;
letterPosX = ((i%modInterval)*106);

}

*/

}

}

Letter Object

class letter{
float x;
float y;
float letterWidth;
float letterHeight;

int totalAmount = 0;

letter(float tempX, float tempY, float widthLetter, float heightLetter){

x = tempX;
y = tempY;
letterWidth = widthLetter;
letterHeight = heightLetter;

}

void display(){

fill(totalAmount);
noStroke();
rect(x*106,y,letterWidth,letterHeight);
}

/*
void letterdisplay(char letterBig){
//takes in a letter and displays it at the top right with a margin of 10
textFont(f,16);
textAlign(LEFT);
text(letterBig,x*106 + 10,y +10);

}*/
void setAmount(int tempAmount){

totalAmount = tempAmount;
/*
takes the total amount and displays it

*/

}

}

Stupid Pet Trick: The Nurse Station

The Nurse Station is a beer nursing meter. It goes placed on a bar counter and is used to measure if the person who places their beer on the coaster has left their beer too long on the counter.

Stupid Pet Trick: The Nurse Station from Zeven Rodriguez on Vimeo.

Stupid Pet Trick: Internals from Zeven Rodriguez on Vimeo.

Here is the code

#include <Servo.h>
Servo servoMotor;

int fsrPin = 0; // Analog input pin that the potentiometer is attached to
int fsrValue = 0; // value read from the pot
int fsrRef = 10; // value read from the pot
int redLed = 4;
int yellowLed = 3;
int greenLed = 2;
int servoPin = 8;
long time = 0;
long lastTime = 0;
boolean setTime=true;

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
//pinMode(speakerPin, OUTPUT);
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
// pulse = minPulse;
servoMotor.attach(servoPin);
//noiseMaker.begin(9);

}

void loop() {

fsrValue = analogRead(fsrPin); // read the pot value
Serial.println(fsrValue);
if(fsrValue < 60){
digitalWrite(redLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(greenLed, LOW);
// Serial.println(“this is when the fsr is not pressed”);
//Serial.println(time);
servoMotor.write(0);
setTime=true;
// Serial.println(lastTime);

}

if(fsrValue > 60 && setTime == true){
lastTime= millis();
//Serial.println(“START TIMER”);
setTime=false;
//Serial.println(lastTime);
}

if(fsrValue > 60) {
if(millis() – lastTime < 5000){
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
digitalWrite(yellowLed, LOW);
servoMotor.write(27);

}
if((millis() – lastTime >= 5000) && (millis() – lastTime <10000)){

digitalWrite(greenLed, LOW);
digitalWrite(redLed, LOW);
digitalWrite(yellowLed, HIGH);
servoMotor.write(50);
// Serial.println(“TEN SECOND LOOP”);
//Serial.println(lastTime);
}

if (millis() – lastTime >= 10000 ){
//Serial.println(“20 SECOND LOOP”);

digitalWrite(yellowLed, LOW);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
servoMotor.write(75);
//Serial.println(lastTime);
}
delay(100);
}

//Serial.println(lastTime);
}

The next step is to re-implement the code not using the Servo.h library so I could add tone. Because tone and servo libraries use the internal timers of the arduino it makes the servo movement erratic. Also I could like to make a more mobile unit.

Lab 4 Servo and Tone

The breadboard is wired with 2 photocells in series go to pin 0. The photocells give an average range in the resistance. Depending which photocell you choose it pushes the resistance either towards the ends of the range. They make sure that all the voltage does not reach the arduino. The speaker goes to pin 8. It does not go to the Pulse Width Modulation because PWM changes the volume of the speaker.

Physcomp Lab4 – Photocell tone from Zeven Rodriguez on Vimeo.

This code is to check the range of the photocells

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

 void loop() {
   int sensorValue = analogRead(0);
   Serial.println(sensorValue, DEC);
 }

This code uses the 2 photocells to make a thermin
/*
   Theremin
  
  Plays tones based on a sensor reading
  uses Tone library by Brett Hagman
  http://code.google.com/p/arduino-tone/
  
  circuit:
  * photoresistor from +5V to analog in 0
  * photoresistor from analog pin 0 to ground
  * 8-ohm speaker on digital pin 8
  
  created 10 Sep 2009
  by Tom Igoe 
  */

 #include <Tone.h>
 Tone noiseMaker;    // instance of the tone library

 void setup() {
   // start the music:
   noiseMaker.begin(8);
 }

 void loop() {
   // get a sensor reading:
   int sensorReading = analogRead(0);
   // map the results from the sensor reading's range
   // to the desired pitch range:
   int pitch = map(sensorReading, 200, 900, 100, 1000);
   // change the pitch:
   noiseMaker.play(pitch);
 }

This video shows using 3 analog resistors to make a make-shift instrument

Phsycomp Lab4 - Three analog inputs from Zeven Rodriguez on Vimeo.
Here is the code

 /*
  
  circuit:
  * 3 force-sensing resistors from +5V to analog in 0 through 5
  * 3 10K resistors from analog in 0 through 5 to ground
  * 8-ohm speaker on digital pin 8
  
  */

 #include <Tone.h>
 Tone noiseMaker;    // instance of the tone library
 const int threshold = 10;    // minimum reading of the sensors that generates a note

 // notes to play, corresponding to the 3 sensors:
 int notes[] = {
   NOTE_A4, NOTE_B4,NOTE_C4 };

 void setup() {
   // start the music:
   noiseMaker.begin(8);
 }

 void loop() {
   for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
     // get a sensor reading:
     int sensorReading = analogRead(thisSensor);
     // if the sensor is pressed hard enough:
     if (sensorReading > threshold) {
       // play the note corresponding to this sensor:
       noiseMaker.play(notes[thisSensor]);
     }
     else {
       // stop playing:
       noiseMaker.stop();
     }
   }
 }

Finally I made an instrument

Physcomp Lab4 - Musical Instrument from Zeven Rodriguez on Vimeo.
#include <Tone.h>
Tone noiseMaker; // instance of the tone library
int notes[] = {
NOTE_D4, NOTE_E4,NOTE_C4,NOTE_C3 };
int durations[] = {
100, 100, 100, 100, 100};
void setup() {
// start the music:
noiseMaker.begin(8);
Serial.begin(9600);
}
void loop() {
int pot = analogRead(5);
pot = pot/4;
Serial.println(pot);
//depending on were the pot is play series of tones at differnt pitches
if(pot > 204){
for (int thisNote = 0; thisNote < 5; thisNote ++) {
// change the pitch:
noiseMaker.play(notes[0]);
delay(durations[thisNote]);
// stop for the next note:
noiseMaker.stop();
}
}
else if((pot < 204) && (pot > 153)){
for (int thisNote = 0; thisNote < 5; thisNote ++) {
// change the pitch:
noiseMaker.play(notes[1]);
delay(durations[thisNote]);
// stop for the next note:
noiseMaker.stop();
}
// hold before repeating:
}
else if((pot < 153) && (pot > 102)){
for (int thisNote = 0; thisNote < 5; thisNote ++) {
// change the pitch:
noiseMaker.play(notes[2]);
delay(durations[thisNote]);
// stop for the next note:
noiseMaker.stop();
}
// hold before repeating:
}
else if((pot < 102) && (pot > 51)){
for (int thisNote = 0; thisNote < 5; thisNote ++) {
// change the pitch:
noiseMaker.play(notes[3]);
delay(durations[thisNote]);
// stop for the next note:
noiseMaker.stop();
}
// hold before repeating:
}
else if((pot < 51) && (pot >= 0)){
for (int thisNote = 0; thisNote < 5; thisNote ++) {
// change the pitch:
noiseMaker.play(notes[4]);
delay(durations[thisNote]);
// stop for the next note:
noiseMaker.stop();
}
// hold before repeating:
}
}

Now using the servo

The servo is connected directly to 5v rail on the breadboard. The servo goes to pin 2. The force sensor goes to analog in.

Physcomp Lab4 – Using Pulse code from Zeven Rodriguez on Vimeo.

This code does not use the arduino servo library

 /*
  Servo control from an analog input

 The minimum (minPulse) and maxiumum (maxPulse) values
 will be different depending on your specific servo motor.
 Ideally, it should be between 1 and 2 milliseconds, but in practice,
 0.5 - 2.5 milliseconds works well for me.
 Try different values to see what numbers are best for you.

 This program uses the millis() function to keep track of when the servo was
 last pulsed.  millis() produces an overflow error (i.e. generates a number
 that's too big to fit in a long variable) after about 5 days. if you're
 making a program that has to run for more than 5 days, you may need to
 account for this.

 by Tom Igoe
 additions by Carlyn Maw & Rob Faludi
 Created 28 Jan. 2006
 Updated 10 Jun. 2008
 */

 int servoPin = 2;     // Control pin for servo motor
 int minPulse = 500;   // Minimum servo position
 int maxPulse = 2500;  // Maximum servo position
 int pulse = 0;        // Amount to pulse the servo

 long lastPulse = 0;    // the time in milliseconds of the last pulse
 int refreshTime = 20; // the time needed in between pulses

 int analogValue = 0;  // the value returned from the analog sensor
 int analogPin = 0;    // the analog pin that the sensor's on

 void setup() {
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulse = minPulse;           // Set the motor position value to the minimum
  Serial.begin(9600);
 }

 void loop() {
  analogValue = analogRead(analogPin);      // read the analog input
  pulse = map(analogValue,0,1023,minPulse,maxPulse);    // convert the analog value
                                                        // to a range between minPulse
                                                        // and maxPulse.

  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulse);       // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }
 }

This is servo part is using the Servo.h library
Physcomp Lab4 - Using Servo Library from Zeven Rodriguez on Vimeo.
 /*
 Servo control from an analog input using the Arduino Servo library

 This example code uses the Arduino Servo library which comes packaged with the Arduino software.

 In order to make this work, you must include the Servo.h library file, create an instance of the Servo object. 
 attach a pin to the Servo object, and then write an analog value to the Servo object to set its 
 position.

 The difference between using the Servo library and the older method of pulsing a digital pin is that the library
 handles a lot of the work for you. You no longer need to figure out the translation between pulse length and position. 
 You now can simply specify the angle you'd like your servo to be at and it will turn to that position.

 Updated 08 Sep 2009
 by Rory Nugent
 Created 20 Jan 2009
 by Tom Igoe
 */

 #include <Servo.h>      // include the servo library

 Servo servoMotor;       // creates an instance of the servo object to control a servo

 int analogPin = 0;      // the analog pin that the sensor is on
 int analogValue = 0;    // the value returned from the analog sensor

 int servoPin = 2;       // Control pin for servo motor, may only be pin 9 or 10

 void setup() {
   servoMotor.attach(servoPin);  // attaches the servo on pin 2 to the servo object
 }

 void loop()
 {
   analogValue = analogRead(analogPin);                 // read the analog input (value between 0 and 1023)
   analogValue = map(analogValue, 0, 1023, 0, 179);     // map the analog value (0 - 1023) to the angle of the servo (0 - 179)
   servoMotor.write(analogValue);                       // write the new mapped analog value to set the position of the servo
   delay(15);                                           // waits for the servo to get there 
 }