Wednesday, September 29, 2004

Babysteps to the Broccoli bot

Hello.

On Saturday Lamar and I got to work on one of essential parts of our project. The project involves enhancing or changing the space at the supermarket. After observing the location we found that the most evident activity was the cart's role in shopping. Carts always tend to avoid each other and the people pushing them also avoid crashing into shelves, end displays and shoppers. Would it be possible to use the cart to enhance the environment ?

Jumping ahead, after a few ideas we decided that a giant inflatable piece of broccoli in the vegetable aisle would be a nice addition to a sometimes quiet environment. The broccoli would be a dressed up inflatable clown and when bumped by a cart would tell shoppers fun broccoli facts and cooking tips.

Now to talk about parts and construction needs.
1) inflatable clown was found on froogle at a kids store for $6.55 (plus $5 shipping, ugh) http://www.kidsurplus.com. Fedex delivered the clown yesterday but to whom I don't know. Kid Surplus's customer service is on the case now. Hopefully I'll have it by Monday night.

2) Felt - purchased down on one of the many fabric stores near canal and broadway. $6/yard^2.
3) Relay switch - 5V reed switch from radio shack - be persistent with the staff there they may try to tell you that they're out of parts.

other parts: breadboard, PIC 18F452, microcassette recorder and adjustable voltage regulator.

The adjustable voltage regulator was a new combination of components we learned about from Todd and was used to power the microcassette recorder. The way the the action will project will work is :

1) cart bumps broccoli
2) a switch is activated - tells PIC to turn on the microcassette recorder
3) PIC keeps the tape playing for about 15 to 20 seconds.

The microcassette recorder will be run off a relay switch, controlled by the PIC because a normal switch will won't be able to hold for a set amount of time. No big deal.

Next the idea came to me that the cassette recorder only needed 3 volts to run. it only had 2 AA batteries. would it possible to run the cassette player off the PIC's power from a pin that is turned on - it's output is 5V! Just to keep you all from wasting your own time, no you can't run a 3V cassette player off a 5V output pin from a PIC...simply because of the amps involved in starting and moving the player's tiny motor.

Here's a picture of the voltage regulator that we built. parts include a L3M17 voltage regualtor, trim pot, and 330 ohm resistor.





The main purpose of this setup was to give the cassette player the right voltage and amps that it needed. I'm still not entirely sure of the physics but the trim pot was adjusted with a screwdriver and measured with a multimeter. The voltage we were looking for was 3 - 3.5V. We set it to 3.5. After testing the new current on the player it worked. horrah!

Next step was to connect the player to the relay, and connect the relay to the PIC. This was a troubled spot because the relay we had was a piece of crap. the legs were too small and didn't sit in the breadboard. We went to radioshack and got a good reed relay the same as we saw in class. In a matter of 5 minutes after getting back to ITP we had that relay working with the PIC controlling the relay, the relay switching the player.

After the pleasure of our little hack subsided we called it a day. Some things still needed are the clown switch that activates when bumped by the cart or person. I am thinking that we need a small metal BB and some wires. As the clown sits still, the BB will have the switch closed, sitting on top of 2 wires. When the clown is bumped the BB rolls off the wires and now the switch is OPEN. The PIC will quickly see that the switch is open and turn the player on for a set amount of time. The BB will return to the dimple it nests in and the switch will close again, this happens as the clowns slowly settles down. The player is not controlled by the BB switch but is working from the PIC.

more later, hopefully when the clown comes in.

Thursday, September 23, 2004

Analog input with the PIC

I'm working on the analog input with the PIC controller right now. This is interesting - thinking of all the applications that use this type of control, potentiometers are in stero volume and tuning knobs, in flex sensors and in measuring temperature.

I hooked up a potentiometer to my PIC at RA0 which is the second pin on the top left of the chip - just under the 10K resistor. There is also a serial cable connected to the computer to display the value of the potentiometer or any variable resistor. Displaying from 0 to 1023 you can use this variable to control other elements on the board.




Later on I replaced the potentiometer with a photocell and had to add a 10k resistor with it to keep the current smooth. still not sure what that means. The resistor and a leg of the photocell was plugged into RA0 and the second leg of the photocell was plugged into ground.



The code I was working on was a distance location system. If nothing obstructed the light then the green LED stayed on. If a shadow or hand came into view of the photocell the yellow light would turn on (green off). If the shadow/hand got to close the red light turns on, and if impact occurs the red LED blinks.




here is the code.

'------------------------------------------------------------
' PicBasic Pro program to display result of
' 10-bit A/D conversion through serial at 9600 baud
'
' Connect analog input to channel-0 (RA0)

' 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

ADCvar 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

main:
ADCIN 0, ADCvar ' Read channel 0 to adval
serout2 PORTC.6, 16468, [DEC ADCvar, 13, 10] ' print it to serial out,

'determine the analog input and control the LEDs
SELECT CASE ADCvar
CASE IS > 820 'blink red led
high portd.6
pause 250
low portd.6
pause 250
low portd.5
low portd.4
CASE IS > 680 'turn on red led
high portd.6
low portd.5
low portd.4
CASE IS > 575 'turn on yellow led
low portd.6
high portd.5
low portd.4
CASE else ' keep green led on
low portd.6
low portd.5
high portd.4

END SELECT

'Button Code here
if portb.0 = 1 then ' if the switch is closed on pin RB0
low portd.0 ' set pin RD1 low
else
high portd.0 ' set RD1 high
SEROUT2 portc.6, 16468, ["Hello World!", 13, 10]
endif
GoTo main
'-------------------------------------------------------------------

The difficulties today came from the BASIC programming language. I ended up finding the error. After using IF THEN statements I decided to test out the SELECT CASE statement and use it instead. I forgot to remove the THEN statement and the compiler caught it. After referencing the manual I found my error. Compile then Programmer then test and hoorah!

It's simple enough. I'm going to look for a simple device to attach but will keep the board as is until class. Also bought some more jameco products so I'll have more to play with, the flex sensor should come next week.

Wednesday, September 22, 2004

Updated code.

In class right now and just learned that the code for the serial communications was a bit jumbled. I have the new code now and will change it tonight.

if you can't wait to see the code here you go:
SEROUT2 portc.6, 16468, ["Hello World!", 13,10]

the 13, 10 was switched previously. here is the website for serial communication with the PIC - http://stage.itp.tsoa.nyu.edu/%7Etigoe/pcomp/code/archives/000568.shtml

mr. board meet mr. computer

output from my serial communication test is a success. soldered the headers to the serial piece. check this out...

Hello Wo2ld!
Hell/ World!
HòHello WoòHello World!
Hello World!
€‹ë ºHª±±½World!
Hello World!
Hell World!
HelloÿWorld!
ello WoRld!
HÉllo World!
Hello World!
HËllo ׽ɱ‘…
Hello World!
ý

here's the code.

'---------------------------------------------------------
input portb.0
output portd.0
OUTPUT portc.6

main:
if portb.0 = 1 then ' if the switch is closed on pin RB0
low portd.0 ' set pin RD1 low
else
high portd.0 ' set RD1 high
SEROUT2 portc.6, 16468, ["Hello World!", 10, 13]
endif

goto main
'---------------------------------------------------------

Hello world indeed. not sure why the characters are goofy but it works. next i'm going to wire my pants to talk to my shoes and my shoes to talk to the floor. it's gonna be great.

Saturday, September 18, 2004

Blinkie and the Pic

18F452, sort of rolls off your tongue however it's bit intimidating at first. it's just a black little piece of plastic and metal, perhaps there's more inside the electronic insect. I have programmed Basic stamps before and I was just as anxious about the first success as getting the PIC to work.

Here's a quick run through of the events that occurred:
Thursday, September 16th
- 9:45AM Fedex arrives with free sample chips from MicroChip(.com)
- 2:30PM Get PIC programmer and set up in Lab
- 3:05PM First LED is blinking from the simple program on the chip.

Now that the first program is working and I understand the process of getting the code onto the chip I am much more comfortable with the needed technical knowledge.

The first program was to make an LED blink. Here's the code

'---------------------------------------------------------
main:
high portd.0 'turn LED on
pause 500 'wait half second
low portd.0 'turn LED off
pause 500 'wait another half second
goto main 'loop
'---------------------------------------------------------

The code wasn't new to me but the process of using a programming environment, compiling and then writing the program to the chip was. After writing to the chip, removing it from the cradle and placing it correctly onto the breadboard was an extra step that the Basic stamp avoided.

here are some pictures of the final products.




After getting the LED to blink I added a switch to the circuit. If the button was pressed, pin B.0, the LED, pin D.0 would turn on. If released the LED would turn off. here is the code...

'---------------------------------------------------------
input portb.0
output portd.0

main:
if portb.0 = 1 then ' if the switch is closed on pin RB0
low portd.0 ' set pin RD1 low
else
high portd.0 ' set RD1 high
endif
goto main
'---------------------------------------------------------


After the switch worked I decided to stop there. I will probably do more this weekend, play with some sensors and variable resistors.

Oh, yea, ArtBot is this weekend. get there.

Monday, September 13, 2004

First lab - getting the breadboard to work

OK, so the first lab went really well. It was all very satisfying even if some experiments did not work out completely. I was in the lab, playing, for about 3 hours on Monday afternoon. My first job was to get the power adaptor plug soldered and working. Todd was giving a quick demonstration and I watched his soldering techniques carefully... shouldn't be too difficult. So the iron is hot and ready, I tin the tip of the iron with solder and quickly sponge it. ok, all's good so far. Now i'm trying to get the solder onto the wires of the adaptor and this turned out to several attempts and about a half hour till I was satisfied.

The best tip I discovered when heating and applying solder is to get the components hot then touch the solder with the heat. When a drip connects the pieces together, slowly pet the droplet with the tip and edge of the iron, it really smoothed out the last spots I was fixing. Here is a picture of the adaptor with wire soldered.


Next was time to test the power. I put a 5V voltage regulator on the board, with some jumpers going to the bus runs. I had a LED and resistor to verify power. And tada!


I decided to make the breadboard look nice and neat the entire time. So I started to trim the jumpers down and place the power test LED at the bottom of the board.


The rest of the time in the lab I spent playing around rearranging and finding misc. electronics to plug into the board. The first test was the LED chaingang. 2 LED's worked in serial, 3 didn't.


I soldered my Potentiometer with the Red (power), Green (data), black (ground) and plugged it into the board to vary the resistance of my LED. Once I got the correct RGB wiring and not RBG the poteniometer was easy to use.


Next I replaced the Potentiometer with a photoresistor. I like the photoresistors, I think I will explore them more later - perhaps to detect shadows and shapes of shadows.


After some searching the junk shelf I found a little speaker, a noisemaker. Similar to the annoying sound of a smoke detector, the potentiometer made it a little fun -like a poorly made guitar.


Found a momentary switch/button on the shelf and replaced the potentiometer. I made a little horn.


Towards the end of the experimenting I found an old Microsoft mouse which I quickly chopped the end off of to see what wires lay inside. There were 5 - red, black, white, blue and orange. I hooked up the red and black to the power and ground then took all the wires from the blue, white and orange and twisted them together to make them share their juice. My multimeter found 5V at the red and black connection but nothing happened elsewhere. It would have been neat to use the mouse to vary the resistance and make the noisemaker play. I'll google microsoft mouse wiring right now and see if I can find anything.

Wednesday, September 08, 2004

Test Post

mm, electrons!