Lab 1: Basic Electronics
Everything went pretty smoothly on this one. I got the necessary parts over at the computer store, and now that I have seen some of the nifty extras that came with other people's kits, I may just have to spring for it. I took Michael's advice and used the multimeter to test the voltage throughout building the circuit, make sure I matched up the positive and negative correctly when soldering the converter piece. Had it halfway soldered when I realized I had switched black for red. Got the right resistor in there, but the lab seemed to be out of switches. I went with the touching-two-wires-together method, while Sai salvaged one from the parts shelf. The first little green LED lit up, no problem. Got another in the series and they both lit. But I guess there was too much resistance to power 3, they wouldn't light up. So back with 2 LEDs??, I found again that the lab was out of pots or other variable resistors (gotta get the kit). Carlyn was kind enough to dig out some pots and photocells out for us, and give Sai, Kati and myself a little lesson on how to wire them up properly. A few solders later we found that the pot had to wired into ground too, not just into the LED, in order for it to light. Got those 2 LEDs?? dimming on and off. Huzzah.
Lab 2: My First PIC Program
Okay, starting to get a little trickier. Started out by getting the breadboard set up. Had to rely on my notes a lot for the specific details, which seemed to be omitted from the directions on the web. In this case, which size capacitors to use on the 12v in, and on the power rail with the 5v. I had an LED hooked in to test the power, and it was working, so I went ahead to program, get the chip involved.
Again, the directions on the web seemed to leave out some details about the PIC programming. I had to go to my notes to remember to define the speed for the crystal, and to be sure to set the inputs and outputs before I made a label. I also kept getting error messages, including the "0000 Error," which was just explained to me that the computer can't find the chip. Had to remember to select the right chip from the pull-down menu in both of the programs.
So the first day, after programming, I got my LED to light up, but it wasn't blinking. I tried re-programming, I tried replacing parts on the breadboard. Kazu helped me for a while, looked at my setup. I tried adding the power and ground on both sides of the chip, added more capacitors on those and the other power/ground rows that went directly into the chip. When I would wiggle some of the parts, the LED would flicker, I suspected that it was a bad connection. But by the end of the day, the closest I had got was the LED stayed on all the time, but was very lightly blinking to my program. Gave up for the night.
Next time I came back in, just getting started. Rocio made some comment about needing a chip puller, and I was thinking "mine is really easy to pull out." Hmm. At that point I gave the chip a more forceful push, and realized that I just hadn't pushed it in far enough into the breadboard. Click. I re-programmed it just to be sure, and of course it worked right away, happy flashing LED. I quickly soldered the button switch from my kit, set it up with the resistor, added an LED, and wrote a progam for the input. Bam. Happy toggle.
Came back in tonight to try to do something a bit more complicated. I really wanted to do a ripple effect, where one push of the button would set off a series of LEDs? in sequence. But I couldn't quite wrap my mind around that one. I considered setting up the chip with multiple inputs, and have the switch trigger an output that would be wired back to another input with its own set of commands. Seemed a little complicated, I didn't actually try to implement any code.
I went with another idea I had. I hooked up the breadboard with three pairs of LEDs?, one pair of each color. I wanted it to flash one pair at a time, for a second each, yellow, red, green when switch = 0. Then when the button was pressed, I had it switch order, green, red, yellow, and only flash each pair for 200 miliseconds. My initial code didn't work - the switch seemed to have no effect at all, it just did the slow pattern all the time, even tried pulling the switch out of the circuit altogether. I tried getting complicated, adding GOSUB commands, but it still did the same thing. The key turned out to be simplification of course. Within the IF section, I had created a new label for what I wanted it to do, and had a GOTO before the ELSE. I did the same thing in the ELSE section, thinking that this was the way to make that section of the code loop. When I got rid of it, I realized that the main: label and the GOTO main applies to the whole code, the section that gets looped just becomes dependent on the condition of the INPUT.
Once I got it right, the effect was nice - when plugged in the LED pairs would blink in a slow circle, one pair at a time. As soon as the button was held down, the LEDs? switched direction and began to blink much faster. Felt kind of like "its alive, just breathing, on its own, but my input = MORE ACTIVITY!" And then when you let go, it resumes its natural state. Joanna tried it, said "what, so you made the seizure board?" I like it.
-Body Switch Design-
So I'm trying to think of a body switch, sitting there, scratching my head. Scratching my head...
I would like to design some sort of hair/headscratch switch. It would consist of a pressure sensor that would rest against the scalp, with an array of thin, plastic strands connected to it. Essentially, it might look like a small piece of scalp with plastic hairs coming off of it. Each of the plastic hairs has its own small pressure sensor at its base, part of the "scalp" piece pressure sensor. As someone runs their fingers through their hair or scratches their head, the pressure is measured by the sensor on the scalp, and the direction and speed determined by the sensors on the bases of the plastic hairs. The hairs would touch into one another as they are moved around, and switch on and off circuit signals as they do so. The scalp switch could run a program that would record the movements of the plastic hairs and the pressure exerted on the head. Equipping the hair-base sensors with small rubber pieces or other material with friction would massage and scratch the scalp as they move. Recorded scratchings could be played back on multiple hair sensors to give the pleasure of a hands-free headscratch, or to mimic the scratching on the other side of the head when only one hand is available for scratching.
Lab 3 - Analog Out (PWM, Tone Generation)
Here's the code that I used for the sound section of this lab. I used adcVar for both frequencies so that essentially the pot served as a control for both. I tried a number of different durations, I put 25 here because it wasn't very 'pulsing,' (the cycles did not really generate a cadence in the tone) and it had a couple of different spots along the range of the pot where the harmonics seemed particularly strong. It was a fun one to play with, I recorded a bunch of the sound for my own purposes.
DEFINE OSC 4
DEFINE adc_bits 8
DEFINE adc_sampleus 20
DEFINE adc_clock 3
adcon1 = %00000000
INPUT porta.0
adcVar VAR BYTE
x VAR BYTE
FOR x = 0 TO 3
PAUSE 200
PAUSE 200
NEXT
main:
ADCIN 0, adcVar
FREQOUT portd.2, 25, adcVar, adcVar
GOTO main
I really wanted to do something like FREQOUT portd.2, 25, adcVar, adcVar + 100 to get a harmonic that would slide up and down with the pot, but Microcode studio told me that adcVar +100 is a 'bad variable' so I couldn't use it. Chris Kucinski was telling me about some way that he made a really simple ring modulator using 'multipliers' I think he said. Hopefully we will learn something soon that will allow me to further manipulate the frequencies.
Lab 4 - Serial Communication
Here's the code I used that ultimately allowed me to read analog input from my pot (including blinky):
DEFINE OSC 4
define adc_bits8
define adc_clock3
define adc_sampleus20
adcVar var byte
input porta.0
txPin var portc.6
output portc.6
output redled
x var byte
for x = 0 to 3
high redled
pause 200
low redled
pause 200
next
main:
adcin 0, adcvar
serout2 txpin, 16468, [dec adcvar, 13, 10]
goto main
I've been getting kind of confused about defining variables, and outputs. Like variables that are set to a port (txPin VAR portc.6), remembering to also set that port as the output (OUTPUT portc.6). Maybe I'm getting lazy, something. I should do it the way that its laid out in the code examples: a big list of all the variables, followed by a long list of DEFINEs?. To be honest, I didn't take this lab all the way to the finish, I didn't get a chance to try out the Processing code. A combination of running out of time/pussing out cause I've never used Processing and found the code to be a bit intimidating. I should probably also order a flex/force sensor and an RGB LED, lazy lazy lazy.
