Making Things Interactive

March 10, 2008

Physical Pixel Representation – Bridging the gap between my Computer and the Physical World

Filed under: 5: Making Motion,Joshua Smith — jssmith44 @ 3:05 pm

For this project, I wanted to investigate bridging the gap between my computer and the physical world. I split my computer screen into 6 white squares ( a 3 x 2 matrix). I then created a physical representation of these squares with a 3 x 2 matrix of Red Led’s.  The physical matrix represents which square my mouse is within the screen. As the mouse moves into a new square, that square turns red on the screen and the corresponding LED turns on. This system consisted of a Processing Application to determine where the mouse was on the screen, run the screen display, and pass that location on to the Arduino Program using serial communication. The Arduino program then controlled the physical pixel matrix. Video is below: (Video Here) Processing Code:  

import processing.serial.*;

Serial port;
String colorO = “#FFFFFF”;
String colorC = “#FF0000”;

void setup()
{
size(900, 600);
noStroke();
frameRate(10);

// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
println(Serial.list());

// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}

// function to test if mouse is over square
boolean mouseOverRectA()
{
return ((mouseX >= 0)&&(mouseX = 0)&(mouseY = 301)&&(mouseX = 0)&(mouseY = 601)&&(mouseX = 0)&(mouseY = 0)&&(mouseX = 301)&(mouseY = 301)&&(mouseX = 301)&(mouseY = 601)&&(mouseX = 301)&(mouseY <= 600)); } void draw() { background(#FFFFFF); stroke(255); line(0, 295, 700, 295); strokeWeight(2); if(mouseOverRectA()) // if mouse is over square { fill(#FF0000); // change color port.write('A'); // send an 'H' to indicate mouse is over square } else { fill(#FFFFFF); // change color port.write('B'); // send an 'L' otherwise } rect(0, 0, 300, 300); // draw square if(mouseOverRectB()) // if mouse is over square { fill(#FF0000); // change color port.write('C'); // send an 'H' to indicate mouse is over square } else { fill(#FFFFFF); // change color port.write('D'); // send an 'L' otherwise } rect(300, 0, 300, 300); // draw square if(mouseOverRectC()) // if mouse is over square { fill(#FF0000); // change color port.write('E'); // send an 'H' to indicate mouse is over square } else { fill(#FFFFFF); // change color port.write('F'); // send an 'L' otherwise } rect(600, 0, 300, 300); // draw square if(mouseOverRectD()) // if mouse is over square { fill(#FF0000); // change color port.write('G'); // send an 'H' to indicate mouse is over square } else { fill(#FFFFFF); // change color port.write('H'); // send an 'L' otherwise } rect(0, 300, 300, 300); // draw square if(mouseOverRectE()) // if mouse is over square { fill(#FF0000); // change color port.write('I'); // send an 'H' to indicate mouse is over square } else { fill(#FFFFFF); // change color port.write('J'); // send an 'L' otherwise } rect(300, 300, 300, 300); // draw square if(mouseOverRectF()) // if mouse is over square { fill(#FF0000); // change color port.write('K'); // send an 'H' to indicate mouse is over square } else { fill(#FFFFFF); // change color port.write('L'); // send an 'L' otherwise } rect(600, 300, 300, 300); // draw square }[/sourcecode] Arduino Code [sourcecode language='cpp'] int outputPin = 13; int val; void setup() { Serial.begin(9600); pinMode(outputPin, OUTPUT); } void loop() { if (Serial.available()) { val = Serial.read(); if (val == 'A') { digitalWrite(2, HIGH); } if (val == 'B') { digitalWrite(2, LOW); } if (val == 'C') { digitalWrite(3, HIGH); } if (val == 'D') { digitalWrite(3, LOW); } if (val == 'E') { digitalWrite(4, HIGH); } if (val == 'F') { digitalWrite(4, LOW); } if (val == 'G') { digitalWrite(5, HIGH); } if (val == 'H') { digitalWrite(5, LOW); } if (val == 'I') { digitalWrite(6, HIGH); } if (val == 'J') { digitalWrite(6, LOW); } } } [/sourcecode] Hardware: Each LED is directly connected to Digital Pins 1-6 and Ground.

Advertisements

February 24, 2008

Godzilla Puncher v3 (servo no work proper)

Filed under: 5: Making Motion,Gaku Sato — ponkotsu @ 3:43 am

So as it turns out, the first set of transistors I tried were inadequate in handling the current load required to activate a solenoid, as they’re only rated for low-power use like logic circuitry.  After being advised to try a power transistor, those were replaced with a 90W TIP3055, apparently used in applications like audio amplification.  This could handle the current loads and the solenoid would make a semi-audible clicking sound, but no activation.  After much confusion and some mysterious smoky smell (which was later identified as Jet’s wristwatch), we found that the transistor/solenoid circuit worked with either the TIP120 transistor or with no resistance on the input signal (to base).  It was determined that the solenoid input voltage was less than the required trip voltage due to the characteristics of the “better” TIP3055.  Since it is used for highly sensitive applications, the input-to-output voltage relation is more linear, thus resulting in an insufficient output voltage with the 1K resistor on the transistor input signal (to base).  This also explains why it worked when we piped 5V straight to base, and why even with the resistor, it worked with the TIP120, which has a more steep non-linear input-to-output curve.  Once we figured that out, the rig was tested with Godzilla in place, who was, alas, punched square in the face.

Radioshack seems to be completely out of TIP120s so my new wiring’s just waiting on that piece.  That is, at least for the solenoid portion…

My other problem was servo control.  I was only succeeding at making an unreliably twitchy speed-controlled rig.  Chris told me he was able to get position control by using the 5V power from the Arduino and sending analogWrites to the control pin.  So I thought perhaps the 9V input was excessive?  Anyways I tried that technique, but still nothing.  I tried Servo.write(angle) with <Servo.h> as well as analogWrite(various 0~255) and it’s always speed control.  I’ve yet been able to get the servo (Tower Hobbies TS-53) to go to any position and stop before it pins itself one way or the other.

At this point, I’m just going to move onto assignment 6 and hope I can get the servo to respond well in that rig.  Then hopefully I’ll successfully be able to even have a midterm project proposal, since otherwise without proper servo control, my small-scale accurate actuation is limited.  LIMITED!  And my project would require this.  I’m afraid even if I went with a linear actuator that I’d have the same problem.

Anyways more debugging Tuesday…

#include

int PotPin = 2; // input pin – potentiometer
int PhotoPin = 3; // input pin – photoresistor
int ServoPin = 11; // output pin – servo
int SolePin = 5; // output pin – solenoid

Servo Ultraman; // set servo
long angle = 0; // 95 to stop…

int punch = 0;
int msecond = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(PotPin, INPUT); // 0~1005
  pinMode(PhotoPin, INPUT); // 750+
  pinMode(ServoPin, OUTPUT);
  pinMode(SolePin, OUTPUT);
  analogWrite(ServoPin, 0);
  digitalWrite(SolePin, LOW);

Ultraman.attach(ServoPin);
  Ultraman.setMaximumPulse(2400); // 2400 default
  Ultraman.setMinimumPulse(544); // 544 default

Ultraman.write(0);
}

void loop()
{
  angle = analogRead(PotPin);
  angle = angle*180/1005;
  Ultraman.write(angle);
  msecond = millis()/1000;
  if(millis()-msecond*1000 == 0) // display every second
  {
  Serial.print(“pot”);
  Serial.print(analogRead(PotPin)); // potentiometer reading
  Serial.print(“:angle”);
  Serial.print(angle); // calculated angle
  Serial.print(” photo”);
  Serial.println(analogRead(PhotoPin)); // photoresistor reading
  }
  if(analogRead(PhotoPin) > 750 && punch == 0)
  {
  Serial.print(“punch!”);
  punch = 1;
  digitalWrite(SolePin, HIGH);
  delay(500);
  digitalWrite(SolePin, LOW);
  }
  if(analogRead(PhotoPin) < 750) {punch = 0;}   Servo::refresh(); }[/sourcecode]

February 21, 2008

assignment 5: solenoid & servo

Filed under: 5: Making Motion,Assignments,Gee Kim — gskim @ 6:11 pm

img_0533.jpg

I simply got my motors to work separately with two different sensors, but with one program.

The solenoid has a digital input from a photo sensor. The solenoid turns on and off depending on if it is dark or light.

The servo has a analog input from a potentiometer. The servo turns in ratio to the potentiometer.

here’s the code:


int servoPin = 3;     // connect servo to pin 3
int sensorPin = 2;    // connect potentiometer to pin 2
int solePin = 12;     // connect solenoid to pin 12
int photoPin = 4;     // connect photosensor to pin4

void setup ()
{
  beginSerial (9600);            //
  pinMode (servoPin, OUTPUT);    // set servo as analog output
  pinMode (sensorPin, INPUT);    // set potentiometer as analog input
  pinMode (solePin, OUTPUT);     // set solenoid as digital output
  pinMode (photoPin, INPUT);     // set photosensor as digital input
}

void loop ()
{
   int val = analogRead(sensorPin) / 11;    // set "val" equal to the analog read of the sensor divided by 11
   Serial.println(val);                     // print the value of "val" on the serial monitor
   analogWrite(servoPin, val);              // as the value of the sensor changes, the servo should spin according to "val"

   if (digitalRead(photoPin == HIGH))       // if digital read of photosensor is bright
   { digitalWrite(solePin, HIGH);}          // then turn solenoid on
   else                                     // otherwise
   { digitalWrite(solePin, LOW);}           // turn solenoid off
}

here’s the circuit diagram:circuit1.jpg

February 20, 2008

Assignment 5, 6: Solar Power

Filed under: 5: Making Motion,6: More Motion,Assignments,Thomas Hendrickson — tphendrickson @ 7:52 pm

So after a ton of trying, troubleshooting, finding help from friends, I finally got a transistor connection to work and got two DC motors running together off of a code. One motor spins a sun and after it powers up the plants (a 6 second delay from a incremented counter), the flowers spin on the other motor.

here is the code:


int sunPin = 7;        //sun motor pin
int flowerPin = 5;     //flower motor pin
int ledPin = 13;       //led runs as a check
int counter = 0;       //counts how long program has been running</code>

void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(sunPin, OUTPUT);
pinMode(flowerPin, OUTPUT);

}

void loop()
{

digitalWrite(sunPin, HIGH);    //turns on sun immediately

if (counter == 6)              //checks counter value
{
digitalWrite(flowerPin, HIGH);  //if counter high enough, turns on led and flower
digitalWrite(ledPin, HIGH);
}

else
{
counter++;      //if not long enough, counter is incremented
delay(1000);    //1 second delay
}

}

February 19, 2008

Godzilla Puncher v2

Filed under: 5: Making Motion,Gaku Sato — ponkotsu @ 7:43 am

So my rig still doesn’t work.  I had the solenoid problem last time where the transistor circuit works, the solenoid itself works, but the solenoid/transistor circuit does not work.  We concluded in class that the small transistor I had wasn’t transmitting enough power.  So I figured with my new 90W TIP3055 and trusty 9V batt that I would get some solenoid action but of course, nothing.  I saw Lingshui and Chris had problems with their solenoids, and I’m wondering how anyone got theirs working…

Also, I posted a question regarding servo position control on Sunday that I got no feedback on : (  I’m using #including <Servo.h> but it’s still acting like it’s speed control, just now it’s even more touchy than before.  Input 94deg or 96deg results in the motor rotating in either direction til it pins itself, and 95 gets it to stop.

And my punch-once-only code isn’t working either.  I thought I had it set so that once the photoresistor input exceeds a threshold, the solenoid would activate once, then wouldn’t activate again til the photoresistor input dropped below a lower threshold, but it just keeps activating the solenoid (applying power, at least) when I have the beam focused on the photoresistor without moving anything.

WTF

#include

int PowerPin1 = 13; // power pin – potentiometer
int PowerPin2 = 2; // power pin – photoresistor
int PotPin = 0; // input pin – potentiometer
int PhotoPin = 5; // input pin – photoresistor
int ServoPin = 9; // output pin – servo
int SolePin = 4; // output pin – solenoid

Servo Ultraman; // set servo
long angle = 0; // 95 to stop…

int punch = 0;
int msecond = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(PowerPin1, OUTPUT);
  pinMode(PowerPin2, OUTPUT);
  pinMode(PotPin, INPUT); // 0~1005
  pinMode(PhotoPin, INPUT); // 750+
  pinMode(ServoPin, OUTPUT);
  pinMode(SolePin, OUTPUT);
  digitalWrite(PowerPin1, HIGH);
  digitalWrite(PowerPin2, HIGH);
  digitalWrite(ServoPin, LOW);
  digitalWrite(SolePin, LOW);

Ultraman.attach(ServoPin);
  Ultraman.setMaximumPulse(2400); // 2400 default
  Ultraman.setMinimumPulse(544); // 544 default

Ultraman.write(0);
}

void loop()
{
  angle = analogRead(PotPin);
  angle = angle*180/1005;
  Ultraman.write(angle);
  msecond = millis()/1000;
  if(millis()-msecond*1000 == 0)
  {
  Serial.print(“pot”);
  Serial.print(analogRead(PotPin));
  Serial.print(“:angle”);
  Serial.print(angle);
  Serial.print(” photo”);
  Serial.println(analogRead(PhotoPin));
  }
  if(analogRead(PhotoPin) > 750 && punch == 0)
  {
  Serial.print(“punch!”);
  punch = 1;
  digitalWrite(SolePin, HIGH);
  delay(500);
  digitalWrite(SolePin, LOW);
  }
  if(analogRead(PhotoPin < 600)) {punch = 0;}   Servo::refresh(); }[/sourcecode]

tilt sensor servo motor

Filed under: 5: Making Motion,Assignments,Christopher Bridgman — cbridgma @ 1:44 am

so, i guess this is a continuation of the making motion assignment. in my first attempt at this making motion, i tried using a simple button switch which when activated, sent a power surge into my usb port. me and a couple other students tried again to get a solenoid working, but we think that it is trying to send power into the arduino, not ground, and thus not working. so to complete the making motion assignment, i used a tilt sensor to control where the servo motor goes to. the servo motor goes to a certain position when the tilt sensor is HIGH, and to another position when the sensor is LOW.

int statusPin = 13;                // LED connected to digital pin 13
int switchPin = 6;                 // Gravity switch connected to pin 6
int servoPin = 11;                 //servo connected to pin 11
int val;

void setup()                    // run once, when the sketch starts
{
  pinMode(statusPin, OUTPUT);      // sets the digital pin as output
  pinMode(servoPin, OUTPUT);
  pinMode(switchPin, INPUT);
  Serial.begin(9600);  //sets the digital pin as input
}

void loop()                     // run over and over again
{
  val = digitalRead(switchPin);

  Serial.print("Value: ");
  Serial.println(val);    

  if (val == 1)
  {
      analogWrite(servoPin,16);
      digitalWrite(statusPin,HIGH);
    }
  if (val == 0)
  {
    analogWrite(servoPin,96);
    digitalWrite(statusPin, LOW);
  }
}

February 17, 2008

servo motor control

Filed under: 5: Making Motion,Gaku Sato — ponkotsu @ 9:26 pm

In Thursday’s class we spent the remaining time just debugging my Godzilla rig, so sorry for anyone else that needed debug advice.  Unfortunately that was only problem #1.

Problem #2: servo motor control
I tried using the ‘pulse’ code from ITP.  I wired and coded the servo signal (analog) to correspond to potentiometer readout (analog).  Unfortunately, all I was able to get out of this was speed control and not position control.

So I tried the servo library as advised (for anyone trying, the install dir is hareware\libraries, not what it says on that page).  It specifically says I can set servo position with a 0~180 (degree) numerical input into a library-defined servo.write function, but I still get speed control and no position control.  An input of 94 makes the servo rotate in one direction til it pins itself, 95 holds it in place, and 96 makes it rotate in the other direction til it pins itself on the other side.  The initial write(0) doesn’t seem to make it do anything either.  I tried changing the pulse max and min, and it made the servo respond differently to the input values, but not in a position-control kind of way as far as I could tell…wtf

So I’d love to get this (servo with position control) working.  In fact I can’t really get to work on the more mechanical assignment 6 til I get this, so anyone if you have any input here please comment!

My code right now looks like this.  I omitted the unnecessaries (there’s other things universally, in setup, and in loop).

#include <Servo.h>
int ServoPin = 9; // servo control pin (output)
Servo Ultraman;   // set servo
int angle = 96;   // servo angle

void setup() {
  Ultraman.attach(ServoPin);
  Ultraman.setMaximumPulse(2400); // 2400: change if necessary
  Ultraman.setMinimumPulse(544);  //  544: change if necessary

  Ultraman.write(0);
  delay(1000);
  Ultraman.write(angle);
}

February 14, 2008

Godzilla Puncher

Filed under: 5: Making Motion,Gaku Sato — ponkotsu @ 4:16 am

Circuitry & Controls:
The pot controls the servo position, on which Ultraman stands projecting his mighty energy beam. When he is aimed directly at the target, the photoresistor picks up the light. When that input exceeds a predefined threshold, a GO signal is sent to the transistor, which activates the solenoid to punch Godzilla right in the face.

img_7153b.jpgimg_7151b.jpg

Unfortunately, I couldn’t get the solenoid to work. So Godzilla is not punched in the face, and the people of Tokyo will not today be able to escape the always-happening disaster and the credits will not scroll. The solenoid works when it’s just straight 5V to ground, but won’t work when I plug it into a digital pin and output HIGH. The transistor circuit works with a resistor-LED combo in place of the solenoid. I’m not sure what’s going on here. So I’m posting this failure for reference only.

Servo Programming:
The servo control is similar to others’. It’s the only one I’ve come across online, and I’m assuming everyone got it there. The problem I found here was that the potentiometer input only seems to serve as speed control and not position control. I can get the servo to stop (v=0) at a specific pot position but that doesn’t correspond to servo position. I know servos with feedback loops can do position control, but can these not? I don’t know what the control signal is telling the servo to do, so I can’t even figure out the code. Am I doing something wrong here?

Lastly, I still can’t get the code to display below properly. I manually typed in the apostrophes but nothing. I just got another saved draft that crashes IE when I try to edit it. Fantastic. I’ll try to get something working soon…
I’ll be asking what the deal is in class tomorrow.

int PowerPin1 = 13; // power pin – potentiometer
int PowerPin2 = 2; // power pin – photoresistor
int PotPin = 0; // input pin – potentiometer
int PhotoPin = 5; // input pin – photoresistor
int ServoPin = 9; // output pin – servo
int SolePin = 4; // output pin – solenoid

int minPulse = 500;
int maxPulse = 2500;
int pulse = minPulse;
long lastPulse = 0;
int refreshTime = 20;

int punch = 0;

void setup()
{
Serial.begin(9600);
pinMode(PowerPin1, OUTPUT);
pinMode(PowerPin2, OUTPUT);
pinMode(PotPin, INPUT); // 0~1000
pinMode(PhotoPin, INPUT); // 800+
pinMode(ServoPin, OUTPUT);
pinMode(SolePin, OUTPUT);
digitalWrite(PowerPin1, HIGH);
digitalWrite(PowerPin2, HIGH);
digitalWrite(ServoPin, LOW);
digitalWrite(SolePin, LOW);
}

void loop()
{
pulse = analogRead(PotPin) * 2 – 20 + minPulse;
if(millis() – lastPulse >= refreshTime)
{
digitalWrite(ServoPin, HIGH);
delayMicroseconds(pulse);
digitalWrite(ServoPin, LOW);
lastPulse = millis();
}
if(analogRead(PhotoPin)>800 && punch == 0)
{
punch = 1;
digitalWrite(SolePin, HIGH);
delay(500);
digitalWrite(SolePin, LOW);
}
if(analogRead(PhotoPin<800)) {punch = 0;} }[/sourcecode]

February 12, 2008

Controlling a DC motor and Solenoid

Filed under: 5: Making Motion,Tiffany Yang — tyang1 @ 9:17 pm

My project uses a potentiometer to change the speed of the motor.  On a different pin, a solenoid is just opening and closing.       

int MotPin = 9;                                  // sets base of motor transistor to PWM 9
int potPin = 0;                                  // sets potentiometer to analog 0
int potValue = 0;                                // value returned from the potentiometer

int SolPin = 1;                                  // sets base of solenoid transistor to digital 1
int switchPin = 3;                              // sets switch pin to digital 3
int switchStatus;                                // status of the switch

void setup() {
  pinMode(MotPin, OUTPUT);                       // sets motor transistor pin as output
  pinMode(potPin, INPUT);                        // sets potentiometer pin as input
  pinMode(SolPin, OUTPUT);                       // sets solenoid transistor pin as output
  pinMode(switchPin, INPUT);                     // sets switch pin as input
  Serial.begin(9600);
}

void loop() {
  potValue = analogRead(potPin) / 4;             // read potentiometer, convert to 0 - 255
  analogWrite(9, potValue);                      // use potentiometer to control transistor

  switchStatus = digitalRead (switchPin);        // reads status of switch
  if (switchStatus == HIGH) {                    // If switch is pressed...
    digitalWrite(SolPin, HIGH);                  // turn solenoid on
    Serial.println("button pressed");
    delay(100);
  } 
    else {                                       //  otherwise ... 
    digitalWrite(SolPin, LOW);                   // turn solenoid off
    Serial.println("button not pressed");
    delay(100);
  }
}

      

Making Motion

Filed under: 5: Making Motion,Assignments,Paul Castellana — paulcastellana @ 2:54 pm

For this assignment, I used a potentiometer to control a DC motor and a servo simultaneously. The speed of the DC changes as you turn the potentiometer, as does the position of the servomotor. At this point my only goal was to produce some sort of variation in the movement of both motors, but it would be useful to further investigate the exact relationship between the turn of the potentiometer and the change in the motors. As it is now, with both motors powered at the same time, the servo is very jumpy and somewhat unpredictable, where as if I turn off the power to the DC motor, the servo runs more smoothly. I’m not sure what the cause of this is… possibly I have the diode in the wrong place?


int potPin = 0;           // Analog in 0 connected to the potentiometer
int potValueT = 0;         // value returned from the potentiometer used to control transistor
int potValueS = 0;        // value returned from the potentiometer used to control Servomotor
int transistorPin = 9;    // connected to the base of the transistor

int servoPin = 2;         // Control pin for the servomotor
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

void setup() {

  pinMode(transistorPin, OUTPUT);  // set the transistor pin as output:
  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() {

  potValueT = analogRead(potPin) / 4;  // read the potentiometer, convert it to 0 - 255:
  analogWrite(9, potValueT);  // use that to control the transistor:

  potValueS = analogRead(potPin);      // read the potentiometer input
  pulse = (potValueS * 19) / 10 + minPulse;    // 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

  }
}
Next Page »

Blog at WordPress.com.