Thursday, October 21, 2004

Shoe Pictures



Wednesday, October 20, 2004

PIC Shoe Code

input portc.7
INPUT portb.7
output portc.6
inputVar VAR byte
pot1 VAR WORD ' Create variable to store result
pot2 VAR WORD
buttonVar VAR WORD


' POTENTIOMETER SETUP
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS


TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
PAUSE 500 ' Wait .5 second


'-------------------------------------------------------


main:
ADCIN 0, pot1 'potentiometer variable
ADCIN 1, pot2 'potentiometer variable
pot1 = pot1/4 'divide the value because it's too big
pot2 = pot2/4


'----------------------
' THE LISTENING CODE - puts message into inputVar
serin2 portc.7, 16468, [inputVar] 'listening for potentiometer value
if portb.7 = 1 then
    buttonVar = 1
else
    buttonVar = 0
endif


if inputVar=65 then ' if received message is 65, then respond to processing


'usage: serout2 dataPin, mode, [data]
serout2 portc.6, 16468, [pot1,pot2,buttonVar] 'talk to processing
ENDif


goto main


nodata:
return

Processing Shoe Code

float[] data = new float[3]; // create 2 space data array. 1) Potentiometer and 2) photocell
int index=0;
float xpos,ypos;
int bck;

int[] dotsXpos = new int[30];
int[] dotsYpos = new int[30];
int dots;

void setup() {
background(0);
size(305,305);
beginSerial(); //begin serial communication thing
serialWrite(65); //talk to PIC . like saying hello
}

void loop() {

fill(0,140,140);
noStroke();
ellipse(xpos,ypos,3,3);

for (int i=0;i if ((dotsXpos[i] != 0) && (dotsYpos[i] != 0)) {
fill(255,255,0);
noStroke();
ellipse(dotsXpos[i],dotsYpos[i],10,10);
}
}

if (bck==1) {
dotsXpos[dots] = int(xpos);
dotsYpos[dots] = int(ypos);

if (dots>30) {

dots= 0;
}
else {
dots = dots++;
}
}
}

void serialEvent() { //automatic serial listener
data[index] = serial; // save messages to data array
index=index+1; // increment serial counter

if (index==3) { // both messages received
ypos = 255 - float(data[0]); // rename the first message to xpos
xpos = float(data[1]);
bck = int(data[2]); //save photocell value
serialWrite(65); // responsd back to PIC
index = 0; // reset serial counter to zero
}

}

Sunday, October 17, 2004

serial and processing code

PROCESSING CODE

float[] data = new float[2]; // create 2 space data array. 1) Potentiometer and 2) photocell
int index=0;
float xpos;
int bck;

void setup() {
size(255,255);
beginSerial(); //begin serial communication thing
serialWrite(65); //talk to PIC . like saying hello
}

void loop() {
background(bck);
fill(0,0,244);
ellipse(xpos, 100, 50,50); //movable circle

}

void serialEvent() { //automatic serial listener
data[index] = serial; // save messages to data array
index=index+1; // increment serial counter

if (index==2) { // both messages received

xpos = float(data[0]); // rename the first message to xpos
bck = int(data[1]); //save photocell value
serialWrite(65); // responsd back to PIC
index = 0; // reset serial counter to zero
}

}



'----------------------------------------
PIC CODE


input portc.7
output portc.6
inputVar VAR byte
sensorValue VAR WORD ' Create variable to store result
photoValue VAR WORD

' POTENTIOMETER SETUP
' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
PAUSE 500 ' Wait .5 second

'-------------------------------------------------------

main:
ADCIN 0, sensorValue 'potentiometer variable
ADCIN 1, photoValue 'photocell
sensorValue = sensorValue/4 'divide the value because it's too big

'----------------------
' THE LISTENING CODE - puts message into inputVar
serin2 portc.7, 16468, [inputVar] 'listening for potentiometer value

if inputVar=65 then ' if received message is 65, then respond to processing
gosub blink 'blink LED
'usage: serout2 dataPin, mode, [data]
serout2 portc.6, 16468, [sensorValue,photoValue] 'talk to processing
ENDif

goto main


blink:
high portd.2
pause 250
low portd.2
pause 250
return

nodata:
return

Wednesday, October 13, 2004

Servo control not sooo bad but...

Ok, so on Friday night I began testing out the servo motor more. I got the motor to move both from a program and from a potentiometer.

After taking the code from the website to make the servo move to the left then to the right I wanted to add in some buttons to control the direction. This took some figuring out but eventually I understood that the pulsewidth that the PIC is sending out must stay between two constants: minPulse and maxPulse. While I'm not totally sure if this is correct but pretending the pulseWidth is a degree element 0 degrees to 200 degrees (more like 180) it was easier to see how the variable referred to position.

here's the code for the button servo action.

===========================================

INPUT portd.1
INPUT portd.0
OUTPUT portc.3

start:

pulseWidth VAR BYTE
' set up constants with the minimum and maximum pulsewidths
minPulse CON 50
maxPulse CON 250
' set up a constant with the time between pulses:
refreshPeriod CON 20

' set an initial pulsewidth:
pulseWidth = minPulse

main:
' change the angle for the next time around:
IF (pulseWidth <= maxPulse) AND (portd.1=1) THEN
pulseWidth = pulseWidth+1
GOSUB move
HIGH portd.2
ELSE
pulseWidth = pulseWidth
LOW portd.2
ENDIF

' change the angle for the next time around:
IF (pulseWidth >= minPulse) AND (portd.0=1) THEN
pulseWidth = pulseWidth-1
GOSUB move
HIGH portd.3
ELSE
pulseWidth = pulseWidth
LOW portd.3
ENDIF
GOTO main

move:
'take the output pin low so we can pulse it high
LOW PORTC.3
' pulse the pin
PULSOUT PORTC.3, pulseWidth
' pause for as long as needed:
PAUSE refreshPeriod
RETURN


===========================================
and a button servo picture.



I got the code for the servo to be controlled by a potentiometer and tried it out.
===========================================


' Define ADCIN parameters
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

sensorValue VAR WORD ' Create variable to store result

TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000010 ' Set PORTA analog and right justify result
PAUSE 500 ' Wait .5 second

pulseRange VAR WORD
pulseWidth VAR BYTE
' set up constants with the minimum and maximum pulsewidths
minPulse CON 50
maxPulse CON 250
' set up a constant with the time between pulses:
refreshPeriod CON 20

' set an initial pulsewidth:
pulseWidth = minPulse
pulseRange = maxPulse - minPulse

main:
ADCIN 0, sensorValue
'take the output pin low so we can pulse it high
LOW PORTC.3
' pulse the pin
PULSOUT PORTC.3, pulseWidth
' pause for as long as needed:
PAUSE refreshPeriod


pulseWidth = minPulse + (pulseRange * (sensorValue/10)) / 100

' change the angle for the next time around:
'IF pulseWidth > maxPulse Then
' pulseWidth = minPulse
'Else
' pulseWidth = pulseWidth + 1
'Endif

GOTO main

==========================================




I have another project from sustainable energy that I am working on that involves solar panels. I will post some information about that later on but think about charging a capacitor from a solar panel and then releasing it when it reaches a desired voltage. It makes a project very organic in the sense that it totally depends on the sun for life. I think these will make incredibly interesting opportunities for advocating alternative energies.

See you all in class.

Monday, October 11, 2004

The completed broccoli bot

So my first Physical computing project is finished. Last Wednesday we presented it to the class. As a review , the project proposed was suppose to enhance or change a space. We picked a supermarket and eventually made it to the idea that a talking piece of broccoli would be a nice enhancement for a shopping experience.

Purchased items include

Teenage Mutant Ninja turtle - Toys'R Us - $8
Felt - Canal Street - ~$10
Balloons - Party City - $5

5V Relay - Radio Shack - $3
Candy Corn (container) - CVS - $.99 (switch)

The project was a good experience for the first one, I really appreciated getting feedback from others and their ideas for it. While time constraints made it impossible to adjust this project I will be sure to talk up my ideas earlier on to get to use some people's ideas.

Lamar and I had both pleasant and stressful moments getting this to work. It's good to take breaks, walk away and just not think about certain pieces of the puzzle. And when all else fails ask Todd!

Here's a picture of the completed switch


On the top left is the homemade switch from a candy corn container, two metal threaded rods and a metal ball. The ball uses the two rods as contacts and becomes a rocker bumpin switch. The PIC is able to determine if the switch is open or closed and control the tape recorder from that contact. Here's a closer look.


A closer view of the breadboard is easier to follow so look at this.

On the bottom right of the board you'll see the typical 5V regulator we have been using in class since the beginning. The bottom bus has 5V in it and powers the switch (currently out of the picture) and the PIC. On the top bus is the power for the tape player - at the top left of the board we made an adjustable voltage regulator and this was described earlier - basically the adjusted voltage on the top bus is 3.7 V and this was enough to power the cassette recorder.

Using two 9V batteries we tested the voltages again and then we went to construct the broccoli. First blow up the bop bag. Next cover it in green felt and then balloons. Place board and tape player in the head region.
Enjoy these.





We didn't get permission to test the broccoli in the grocery store and I still think we should have just ran in and took the photos and left but something was in the air those last nights telling me to behave. So we took it out on the streets and had some people touch it.

The basic problems:
Interface - no one has really been standing next to a 33" tall vegetable before and they certainly don't want to break it and or knock it over. People need to know what they can and can't interact with, the broco gave mixed emotions and some people were just avoiding it. certainly no interaction from avoidance....or is there?

Listening - so if a piece of broccoli was going to talk to you would you listen? how is it going to be relevant? do you think you would respond back? Then what? If the broccoli had a large knowledge about a supermarket like where to get certain foods or products then the broco bot might help people shop - but that's what clerks are for too.

Having to do it again I think I would make the broccoli bigger and more durable. It's current size would be slayed by a normal shopping cart. I think there needs to be more affordance for people to know how to use it and probably not a sign like Andrew said. Could it constantly sway or bop back and forth to get people's attention and then use a proximity meter to know when to start talking?

I'm happy with the work, but I'm happier now because I know more technology and code to do more interesting things. but yea, baby steps.

Lata,

Saturday, October 02, 2004

code for PIC

main:

if portc.3 = 0 then
high porta.0
pause 10000
low porta.0
endif
goto main

this looks for an open switch and then turns pin A0 HIGH for 10,000 milliseconds. While the pin is HIGH the relay is closed and current flows for 10 seconds.

Candy Corn Switch

Yesterday we made a switch out of a candy corn cylinder from CVS pharmacy. Placing two parallel metal screws through the container the metal ball would close the switch when both contacts (screws) were touched. If bumped the ball rolls forward off the contacts and the switch is closed. This is where we will program in some logic to use the open switch to play the tape player for a few seconds.

All in all the switch isn't pretty but it works - no real need for asthetics because it will be hidden inside the head of the broccoli.


Will post pictures later.

----------------------------------------------------
Building the circuit.

We built a circuit with 2 different voltages on 2 separate buses. 1 with 3.7volts from the adjustable voltage regulator and the other bus with regular 5V. We discussed the situation and knew that we must keep the buses separate all the time and the closest they can get is at the reed relay. We programmed the PIC and then set up the relay and after some simple debugging we had the switch controlling the power of the tape recorder.

Today, saturday, we will clean up the board's wiring and test it out with 2 9V batteries.