Joan Soler-Adillon [*] || ITP Page

Physical Computing

Instructor: Jeff Federson

See Syllabus

Back


Journal

Week one : (untitled)

Week two : Let there be light

Week three : Plugging a tupperware to the computer

Week four : One step forward and two steps back

Week five : The chip is dead, long live to the the chip!

Weeks six and seven: motors and to the midterm

Week eixght: THE HALLOWEEN MIDTERM / Essay

Week nine and ten: From stupidity to Serial Killer

Final project: Planet of sound


Week one:

Introduction to the course. We got the assignment of getting the parts.
As an international student it's quite a job to match the names of the parts with the actual components.
Most of the parts, though, were anyway unknown to me even in my own language.

journal index

Week two:

Let there be light

The first circuit. Someone said that he felt an indescriptible pleasure when he saw his first LED lit.
I would add to it what I call the pleasure of understanding, which lasts even longer and may increase to the infinite
It's like what I felt when studying maths or logics, but here it is the pleasure of understanding what is each component in the circuit doing to make it work and why does all that toghether work.
The worst part was the soldering. Working with tiny things drives my nerves crazy... I just can't help it!

Here's more or less the script of this two weeks:

First step: Get the basic components

Second:

Make it work!

so...
...and there was light

journal index

Week three:

Pluging a tupperware to the computer

First idea I got comming back home from ITP. I'm gonna build my board into a trafic light.

...and it worked. I plugged three 220 om. resistors in pins 13 to 16. A red LED related to pin 16, yellow to 15 and red to 14, with a buzzer in pin 13.

The code was as simple as

Option Explicit

Public Sub Main()

delay 0.5

do

putpin 16, 1
delay 0.5

putpin 13, 1
delay 0.5
putpin 13, 0
delay 0.5
putpin 13, 1
delay 0.5
putpin 13, 0
delay 0.5
putpin 13, 1
delay 0.5
putpin 13, 0
delay 0.5
putpin 13, 1
delay 0.5
putpin 13, 0
delay 0.5
putpin 13, 1
delay 1.0


putpin 16, 0
putpin 15, 1

delay 1.0

putpin 15, 0
putpin 14, 1

delay 4.0

putpin 14, 0
putpin 15, 1

delay 1.0

putpin 15,0

loop

End Sub

 

But it worked, so the lights when on and the buzzer beeped on and off while the green light was on.

journal index

Week four:

One step forward and two steps back

This week started well. The previous, in one of these pcomp-looking-all-the-junk-piles I found a pc on the street, which I picked up with the idea of breaking it down into pieces. But the great surprise was that it was working, and luckily my roommate had a monitor, keyboard and mouse I could use.
So I was dedicated to bring this machine back to a decent live, more for the pleasure of doing it than for it's actual use... though I discovered little by little that it was a pentium II, 6gb hard drive, 64 ram, 56kb modem and DVD rom and a broken floppy. Not bad for $0.
Then I bought a floppy drive so I could format it, which then implied looking for the cards in the mainboard, finding the drivers and all this stuff, appart from installing the OS. Lots of gateway database searches and mainboard chip reading, dealing with windows and DOS... but now I'm writing on this pc, wich I hope is not the cause of what comes next.

Sometimes things give wrong turns, though we are never completely innocent. This week I left my pcomp work for thursday evening (first error).

The first thing was that the street light wasn't working properly, and I had lost the exact final code used, so I disposed myself to rearrange it to upload the details.

I think it was just after reseting the bx-24 or something similar (the connection between the program and the chip was certainly working), all of a suden it got lost and I kept on receiving the "error 220 unable to halt Basix" message.

I tried to swich it on an of while the program was trying to get to it, ground pin 22... and I also cheked the soldered part of the serial connection, which was working... no idea why the ....... thing wasn't working at all.

journal index

Week five:

The chip is dead, long live to the chip!

The further investigation with Jeff led us to the terrible conclusion: the BX24 was dead, so it was conveniently put on a box and brought back were he belonged...

... but after some minutes and some $42, I had another bx24 working fine! So I could finally start working in something.
I decided to go on with the street light thing and integrate in one program last week's idea and the potentiometer version, so there would be two possibilities to run the same circuit.
So it finally ended as a street light that can both work automatically or manually, depending on the state of a switch. If automatic, the light and buzzer would go on as on the week3 project, and in the manual the potentiometer would be used to determine 5 states of lighting and beeping.
It was quite easy to set up the two manual and automatic routines.
The difficulty was in make the chip being constantly cheking the state of the switch and at the same time running the routines properly, so at any time it would notice the state of the switch and change the mode.
That was hours of work, rewriting once and again the code.
And when it all should have been ok, the automatic routine started to get stopped at it's thenth step.
After debuging all possible and not understanding what was happening, I posted and e-mail on the p-comp list. Tom Igoe told me to do some stuff to make the code look better (I needed that, too) and try this way to fix it.
It didn't... so I kept on trying untill I finally fixed it getting rid of a function that didn't seem necessary.
Suddently it all was working just as I expected it to!
And after a while, Tom posted another e-mail telling that the problem probably had been that the bx24 was going under more than 10 levels, which happens to be it's limit.
That made sense! I knew the clue had to be this 10 but I didn't know any reason for it to be a problem.
Now I know: the bx24 can only go 10 levels deep in subroutines of if statements.

And another really helpful tip: the startAgain subroutine in my program made me be aware of every time the chip was being reset, and having sound on this message was a really good thing.

Finally, I added a loudspeaker in pin 17 and called freqout in the manual mode (thanks to Jared, Maya and Mina for the research group presentation).

This is how my board looked like,
... and this is the final version of the code:
			
Option Explicit

dim potVar as integer
dim switchState as byte
dim autoContador as byte
Sub Main()

call startAgain()

autocontador = 0
do

call Check()

loop

end sub

'check if the swich is on or off and go to one mode or the other
sub Check()
switchState = getpin(8)	
	
 debug.print "swithcstate=" ; cStr(switchState)

		if switchState = 0 then
			debug.print "CALL manual"
			call manual()
		else
		 	debug.print "CALL automatic"
			call automatic()
		end if
end sub

' declare as subroutines the 4 possible states of the traffic light
sub stateLight1()
	call putpin(9,1)
	call putpin(10,0)
	call putpin(11,0)
	call putpin(12,0)
			debug.print "stateLight is 1"
		call delay(0.5)
end sub

sub statelight2()
	call putpin(9,1)
	call putpin(10,0)
	call putpin(11,0)
	call putpin(12,1)
			debug.print "stateLight is 2"
		call delay(0.5)	
end sub

sub statelight3()
	call putpin(9,0)
	call putpin(10,1)
	call putpin(11,0)
	call putpin(12,0)
			debug.print "stateLight is 3"
		call delay(0.5)
end sub

sub statelight4()
	call putpin(9,0)
	call putpin(10,0)
	call putpin(11,1)
	call putpin(12,0)
			debug.print "stateLight is 4"
		call delay(0.5)
end sub


' automatic street light code
Sub automatic()

autoContador = autoContador + 1
				debug.print "autoCounter=" ; cStr(autoContador)


Select Case autocontador
	case 1
		debug.print "case1"
		call Statelight1()
	case 2 
		debug.print "case2"
		call statelight2()

	case 3 
		debug.print "case3"
		call statelight1()
	
	case 4
		debug.print "case4"
		call statelight2()

	case 5 
		debug.print "case5"
		call statelight1()

	case 6
		debug.print "case6"
		call statelight2()

	case 7 
		debug.print "case7"
		call statelight1()

	case 8 
		debug.print "case8"
		call statelight2()

	case 9 
		debug.print "case9"
		call statelight1()

	case 10
		debug.print "case10"
		call statelight2()
		call delay (0.5)
	
	case 11 to 14
		call statelight3()
	
	case 15 to 22
		call stateLight4()

	case 23 to 24
		call stateLight3()

	case 25
		autoContador = 0
		
end select

end sub


'more elegant code for fancy street light
sub manual()
dim lightOff as byte
dim potVar as integer
dim thingOn as byte
dim lightOn as byte

' turn counter for street light to zero
autoContador = 0
'turn off all the leds
	for lightOff = 8 to 11
		call putPin(lightOff, 0)
	next

'set a variable and divide the potentiometer range in 5 states	
potVar = getADC(13)
	thingOn = cbyte(potVar\200)
		debug.print "thinOn = " ; cstr(thingOn)

'thingOn is 0		
	if thingOn = 0 then
call freqout(17, 1000,1000,100)
delay 0.4
		for lightOff = 9 to 12
			call putPin(lightOff, 0)
		next
	end if
'thingOn is 1
	if thingOn = 1 then
call freqout(17, 1100,1100,80)
		for lightOff = 10 to 12
			call putPin(lightOff, 0)
		next
		
		for lightOn = 9 to 9	
			call delay(0.2)			
			call putpin(lightOn,1)
			call delay(0.2)
			call putpin(lightOn,0)
		next
	end if

'thingOn is 2
	if thingOn = 2 then
call freqout(17, 1200,1200,60)
		for lightOff = 11 to 12
			call putPin(lightOff, 0)
		next
		
		for lightOn = 9 to 10
			call putpin(lightOn,1)
			call delay(0.1)
			call putpin(lightOn,0)
		next
	end if

'thingOn is 3
	if thingOn = 3 then
call freqout(17, 1300,1300,40)
		for lightOff = 12 to 12
			call putPin(lightOff, 0)
		next
		
		for lightOn = 9 to 11
			call putpin(lightOn,1)
			call delay(0.05)
			call putpin(lightOn,0)
		next
	end if

'thingOn is 4
	if thingOn = 4 then
call freqout(17, 1400,1400,20)
		for lightOn = 9 to 12 	
			call putpin(lightOn,1)
			call delay(0.025)
			call putpin(lightOn,0)
		next
	end if

'thingOn is 5
		if thingOn = 5 then
call freqout(17, 1500,1500,10)			
		for lightOn = 9 to 12
			call putpin(lightOn,1)
			call delay(0.0125)
			call putpin(lightOn,0)
		next
	end if

end sub





'light up and beep when starting
Sub startAgain()

call delay(0.5)

dim nextLightVar as byte
dim timesResetLight as byte	

	for timesResetLight = 1 to 4
		for nextLightVar = 9 to 12
			call putPin(nextLightVar, 1)
			call putPin((nextLightVar - 1), 0)
			call delay(0.04)
			if nextLightVar = 12 then
				call putPin(12,0)
			end if
		next
	next
call delay(0.5)
end sub



journal index

Weeks six and seven:

Taking it easy
Due to a bunch of other ITP obligations, nothing spectacular.
Lab assignments and playing a little bit by adding motors to my long long code. Not worth a longer entry to the journal, though.

 
journal index

Back