Saturday, March 1, 2008

Lab 5 - Serial Output/Processing

So the good news is my camera's new, and even without knowing much about it it still takes better shots. Things kind of go downhill from there.

Unlike in the example, I used a photocell and pot as my two analog ins with my digital in switch. I'm starting to understand more fluidly the reason for scaling/ranging, it sometimes outputs a more stable or controllable range of data. My first send through pin 0 (the pot) emitted DEC values of around 227-228, while the 2nd time I tried a BYTE modifier in the code and my values were more á and "beta".
















I was ready to try sending serial communication using multiple modifiers. My results? In tabbed columns:
Aplha-Beta (BYTE/ASCII) 11100010-11 (BIN) 226-227 (DEC) E2-E3 (HEX) 342-343 (OCT)



Clearly, Arduino and serial i/o are communicating. When I sent BIN values for all 3 sensors, I got my continuous feed of A's until I entered a character, and in the serial monitor I received a 3-ASCII char response. Then I tried it with DEC variables and it spit back 0-255 values in response to the pot, plus values of 100 (off) and 255 (on) when I clicked the digital switch.



So why wouldn't Processing run my program properly when all other communications were verified? I can tell you I checked many factors over and over again, and checked with many people including my professor, students and PhysComp grads on the floor. I could have perhaps used a multimeter to check voltages across the circuit, but other tests ascertained it was not a hardware problem but a code one in nature. Having never seen the Processing environment before (I am not in ITP and haven't taken ICM), I can tell you the code was different enough to make things difficult to debug alone, but I picked up a few tips from others along the way, including writing in println statements at each step to ensure messages were being received. We did deduce that somehow color messages (supposedly controlled by the digital switch) were not being sent - or were sent only as pure black, rendering visibility impossible on a black background - so we changed that part of the code to a constant white value. Good, at least it's on the screen.



And it stayed mostly upper left thereafter, at first with a lot of jostling back and forth which meant control with the pot wasn't smooth and obvious, until some extra tweaks like ridding the code of tabs in the printout, which slowed the ball down considerably. But at least some tangible result was reached. I owe my newest ITP floor buddy Kristen a lot in helping me understand Processing better, so I will take this as a "whatever doesn't kill you makes you stronger" moment. Thanks, Kristen!

Friday, February 15, 2008

Lab 4 - Servo; Analog Output

I'm looking heavily into upgrading my documentation capabilities with a better digital camera, having enlisted advice from Rob, ITP students, my Dad, and consumer reports online. I can't decide whether to go really high-end or just find a better portable camera (money may make this choice for me). Anyway, for kicks I checked out the worst camera from the ER for this lab and it still worked better than mine, plus I tried a couple short movies with it which you'll also find below. Today I'll go to B&H to try out some cameras.



By now I understand the basics behind preparing a simple circuit on a breadboard, and following the photos and schematics is never that hard. Still, it took me a minute to realize the servo outputs can't go directly into the Arduino but need a bypass first on the breadboard - this involves tampering with the 3 header pins with needle-nose pliers to get them long enough to seat. I color coded the analog output leads to match the servo's leads, and used one blue lead in series with my photoresistor, since I didn't own an FSR with 2 entwined leads (as shown in the lab demo picture). I followed the code exactly and it did produce physical results, a 180 degree turn with every pinch or light variation on the resistor, however the serial monitor did not display any data. Also, the motor did not respond well to a thermistor, so that and the serial issue together leave some unanswered questions.

But look at my movie!



For kicks I tried the $15 stretch sensor I'd bought a few days back - I didn't bother to solder leads to it but if I use this in a project down the road then I probably should. For lab purposes, the servo responded fine to my stretch sensor.



The main issue I'm having, and with all the labs is, what can I do with all this? I'm not conjuring anything original like some of the students have shared, and wondering when my stroke of inspiration will begin. I'm not even quite sure how to attach other blades to the servo and what kinds of things it can power, so I'll have to read some forums online I suppose. Not being an ITP student, I'm not as "immersed" in the culture here as much as some, so I took it upon myself to check out some of the advanced projects currently on the floor... knowing now how much effort goes into one little lab, I'm amazed by the things I've seen: The inkjet cartridge guitar string machine, the scantron test robot, the Torrini magician documentary box, and a seesaw with an Arduino on it that I didn't get to see work but seems really interesting too.

When it gets to project time, I would like to incorporate materials for both this class and my Adv MAX/MSP class. On the Arduino site I found an arduino2MAX object, so once I get more comfortable with MAX I should start thinking of a creative sensor to trigger a patch with.

Wednesday, February 13, 2008

Lab 3 - Analog Input

I'm killing time waiting to get some help... the first stage is already giving me trouble because the Arduino program on upload reads "programmer is not responding". Kind of surprised as this one looked fairly straightforward, and the code was already written for me?? Wait, I unplugged and replugged the USB cable, and remembered to hold down reset before uploading, and now the program loads. But, no light on the LED. Tried another LED, no luck. OMG, would you believe that I switched the leads in the power and ground pins on the Arduino? Now it lights, and the POT dims the LED at will.



On my second task, looks like I'll have to write the program myself. I'm still very much at the stage of "following recipes". Yes, I understand it later if it all works and I check as to why, but I'm not thinking ahead toward other possibilities at this point. I've just read that the 2 variable resistors I'll use will need to have their voltage divided prior to analog input, so I've set up the breadboard accordingly and will now have to go out and buy some flex or some other sensors. Back shortly.



Now I've come armed with photocells, thermistors and a stretch sensor (and bought the basic took kit I never had before), and have decided to start with comparing one each of the first two choices. I varied the previous code by doubling certain commands to address a second variable, renamed all my variables and... voila! The lights are pretty much completely on, and there's no visible indication that my hand pressure or the flash on my camera is affecting the LEDs.

I sought Jeff's assistance and he showed me how to run the serial monitor to see the printed values, and edit the code so the printouts read in clear columns and compute a little more slowly, for easier reading. Some variations were noticeable, but he said that in order to really see the difference in the LEDs the resultant values would have to be scaled to a range appropriate for outputting voltage, namely 0-255. That required making sense of the math and writing a good formula:

OUT = 255/(INmax - INmin) * (IN - INmin)

... where OUT is the desired voltage value to send to the LEDs, IN is the initial reading, INmin is the initial minimum value and INmax the initial maximum value. I re-wrote the code as follows and it helped my variable resistors' sensitivity much better:

int photoPin = 0; // Analog input pin that the photocell is attached to
int thermoPin = 1; // Analog input pin that the thermistor is attached to
int photoValue = 0; // value read from the photocell
int thermoValue = 0; // value read from the thermistor
int ledA = 9; // PWM pin that the LEDa is on. n.b. PWM 0 is on digital pin 9
int ledB = 10; // PWM pin that the LEDb is on. n.b. PWM 0 is on digital pin 10
int P,T;

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(photoPin, OUTPUT);
pinMode(thermoPin, OUTPUT);
}

void loop() {
photoValue = analogRead(photoPin); // read the photocell value
thermoValue = analogRead(thermoPin); // read the thermistor value

Serial.print("photovalue; "); // print the photocell value back to the debugger pane
Serial.print(photoValue); // print the photocell value back to the debugger pane
Serial.print(" thermovalue; "); // print the thermistor value back to the debugger pane
Serial.println(thermoValue); // print the thermistor value back to the debugger pane

P = 5*(photoValue-100)/6;
T = 8*(thermoValue-90)/1;

analogWrite(ledA, P); // PWM the LED with the photocell value (divided by 4 to fit in a byte)
analogWrite(ledB, T); // PWM the LED with the thermistor value (divided by 4 to fit in a byte)

delay(100); // wait 100 milliseconds before the next loop
delay(100); // wait 100 milliseconds before the next loop
}

Scaling to a range of values is something I'll need for MAX/MSP and other applications so it was good to get clear with that in my head and in the code. To make a truly user-friendly luv-o-meter, a step I'm not yet prepared to take, I would want many LEDs arranged in an aesthetically pleasing design and also a video display that outputs the scaled values as a dial reading with a meter hand, and each chunk out of the total 255 represents a different level of Don Juan-ness with some silly appellation and graphic for it. I wonder if this is what Jitter is for - in that case it would probably not require an extra microcontroller and out connection. But if it's for market sale and needs to be portable, then maybe it would require a second microcontroller, or some other step that would take the place of needing a whole PC to do the work.



I think that of the two, the thermistor makes the most sense for a luv-o-meter. For a test of strength, some giant FSR or stretch sensor may be appropriate.

Friday, February 1, 2008

PhysComp Lab 2 - The Arduino

Today this handheld device, in one fell swoop, was to help me create a blinker, a switchlight and a combo lock-driven light, and it supplied USB power to my breadboard, rendering the DC power unnecessary for this lab.

Still, I kept the LED on the far end of my board to indicate that the board was indeed powered when I plugged in the Arduino. I also put an LED in the digital output and ground of my Arduino to make sure power worked in that as well.



Once power was determined on all fronts, I created an LED circuit much like in the first lab, but also wrote a simple program to create a blinker with .5 sec delay.





void setup() {
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}


I was now ready to try a toggle switch light with the Arduino. This was done in the 1st lab without code, but it's more satisfying to make something work with it.



void setup() {
pinMode(13, OUTPUT);
pinMode(2, INPUT);
}

void loop() {
// check the digial input. If it's high, do something:
if (digitalRead(2) == HIGH) {
// set the digital output HIGH (turn on the LED):
digitalWrite(13, HIGH);
}
else {
// turn off the LED:
digitalWrite(13, LOW);
}
}


I furthered the code in a 3rd application by adding one LED and allowing for the switch between one light being on while the other was off, and vice versa:


void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(2, INPUT);
}

void loop() {
// check the digial input. If it's high, do something:
if (digitalRead(2) == HIGH) {
// set the digital output HIGH (turn on the LED):
digitalWrite(13, HIGH);
}
else {
// turn off the LED:
digitalWrite(13, LOW);
}
// check the digial input. If it's high, do something:
if (digitalRead(2) == HIGH) {
// set the digital output HIGH (turn on the LED):
digitalWrite(12, LOW);
}
else {
// turn off the LED:
digitalWrite(12, HIGH);
}
}




Finally, my combo application was a simple recursion in the code - an "if" statement inside an "if" statement - that allowed the 1st switch pressed followed by the 2nd to cause the LED to light up.

void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
}

void loop() {
// check the digial input. If it's high, do something:
if (digitalRead(2) == HIGH) {
if (digitalRead(3) == HIGH)
{
// set the digital output HIGH (turn on the LED):
digitalWrite(13, HIGH);}
}
else {
// turn off the LED:
digitalWrite(13, LOW);
}
}




The venture was a success, and I was pleased to realize this could imply much more than powering lights. Motors and sound cues could be the stuff that dreams are made of from here on out.

PhysComp Lab 1 - Basic Circuitry

After barely skating past the basics of "up and running" (Add/Drop, parts purchase, preliminary readings, close observation in class, signing for listservs, trainings and duties, and pulling my hair out), I delved right in and attempted to solder wires to my toggle switch, pot and DC power. Wait, not so fast. I found and met the people I need to meet to acquaint me with the shop, and help me to get started. Quite a friendly bunch, really. Why they have time for me is anybody's guess.

So, I discovered more than one soldering technique, and also that there are some irons that work better than others. I did touch the tip to the solder, I must say, it got a good gob going and then I spread it around the joints. By the 4th or 5th try I was an expert, at least until tomorrow when I forget everything (muscle memory in me is malaise).

That part took all my limbs and then some helping hands, so no good photos here. But then I prepared the breadboard with power and ground from the DC power and again from the voltage regulator. I tested the presence of power in the board with an LED on the other side, with ground and 220 ohm resistor and.... voila! It lit up.



I tested the regulator for 5 volts and discovered that the multimeters in the shop also possess varying levels of reliability. But I got one finally to read what I wanted.

So, for my 1st LED circuit. It was like following a recipe once and then realizing there are subtle variations you can adjust according to taste, or in this case, location on the board. As long as positive flowed to negative and the resistance was in place, I was good to go.



Once this worked out, trying 2 LEDs in series was not so bad. I even checked the voltage and got around half the desired total on each LED. Life was good.



Life got a little trickier when I moved to 3 LEDs in parallel. Sure, they worked, and the lights went dimmer as guessed, but somehow there was no reading for current on the multimeter. One resident suggested the meter itself wasn't working, but it happened on a couple of them.



The most fun part of the lab was getting the pot involved. Here one could conjure immediate applicable ramifications for such a device, most obviously, light dimmers. Not sure if that is really in the domain of resistors or switches, but there you go nonetheless. In one day I became a convert to electronics hobbyism. One year down the road and I may even become handy around the house, much to my wife's pleasure.

Saturday, October 27, 2007

Internet 2 Musings

The artistically collaborative possibilities inherent in the new strain of Internet 2 technologies has caused me to think on future projects in a new light. I have an idea for a rock musical, for instance, but because such a notion of "rock musical" is already tainted with cliché connotations, why not make the thing into an event, one with as much an element of the unpredictable as there is of the rehearsed? Perhaps I could explain this in the program, and announce the specific moments when the experimentation will occur. Given the beta-ever-evolving nature of the medium at this stage - and the economics of charging high tickets prices to cover overhead in NYC - I don't think it would be fair to trick audiences into thinking they'd get the same thing every time. Then again, with practice I suppose the whole thing could be made seamless. Clearly, though, a spectator has to go into this with a much more open-minded view of what theatre is and could be.

I am encouraged by the egalitarianism of bringing this capability to the masses via iChat, although clearly the difference between an amateurish vaunt and a more professional one requires some pretty pricey equipment (mixers, monitors, cameras, projectors, screens, and the like). Many of those putting on events like this in the future may choose to bypass many of these components, in which case an already prominent trend of bringing the arts to a more casual home play space is likely to continue in that direction. As with any artistic endeavor, you have to play to the space, and if that space is increasingly people's laptop screens then producers of events in larger traditional theatre and concert hall spaces are to have even more to compete with since the first fallout of the domestic entertainment revolution, the surround sound home theatre. Can the arts survive this? What may finally trump this threat is that man is indeed a social animal... so if someone at home can log in and watch an event from anywhere, they become exposed to it, and may want to bring their friends to it live thereafter, thereby making the streaming version a form of advertising for the real thing (because, clearly, the quality cannot be as good without some parts that are truly in the flesh). We'll see, if we get to the point of 3-D holograms and perfect precision in audio with zero latency then the living real time arts may one day be dead.

Thursday, October 25, 2007

Reflections on 2 Events

Last night was a second premiere of my electro-acoustic piece Take Flight Uncertain at NYU, this time with a live percussion ensemble and tape. It was a "Meet the Composer" kind of event, where the composer is asked to come to the stage prior and briefly discuss his/her work. I fear I may have put the players off by mentioning how sobering it is to hear the same piece live when a recorded version using samples at home had already been staged, but what I meant by that is how samples cannot prepare a composer for the challenges of the instruments for which he is writing when the piece goes to live. For instance, I had to rent three of the percussion instruments, which were not easy to find. Second, the tuned water glasses had to be amplified to be heard, and the thunder sheet on hand did not make quite the same extended effects as I was used to hearing from the samples. Interaction with the electronic CD accompaniment was sure to be an artificial construct in that theatre space with the two sources of sound happening at once, one that would have to be practiced to achieve the right balance. Also, in my score preparation I knew it would be challenging to communicate the idea of multiple simultaneous tempi. I think all said and done, though, the piece was delivered exceptionally well, and I was able to convey my feeling of implosion on an airplane which was the impetus behind the piece in the first place. Special thanks to the large supportive audience that came out, the players, Jonathan Haas, and the other composers whose pieces were all really great and wide-ranging.

Prior to this event, Take Flight was part of an Internet 2 event also in Loewe Theatre, entitled "Trying to Connect". This was more informal in intent and less advertised and attended, but the results were every bit as immersive as seeing a live concert music performance. The multimedia and cross-server aspect of this had something to do with it. A great deal of set up was done one day prior, and thanks to Tom Beyer and John Gilbert the equipment - which included 3 giant screens, 3 video cameras, a video mixer and 2 monitors, an audio mixer, and the internet connection powered by, of all things, iChat - performed to great success, and brought the improvisational aspects of the music and dance to a larger-than-life quality. An I2 improv duet with John Gunther at the University of Colorado on two saxophones was for me a great experience, one that I look forward to repeating in future collaborations. Take Flight in this version was rendered as a DVD with iMovie animated photo stills (my own first attempt at "multimedia"), and while some aspects of my video were quite amateurish, I overall have to be pretty happy with my first stab at this - the images were just enough to not stay in the way of the music and terrific dance improvisations, skillfully mixed onto multiple screens by our expert crew. I also enjoyed being part of the collective improvisations with the NYU Composers Ensemble and with Dinu Ghezzo and Tom Beyer. It made for a very varied evening whereby, with artistic and technical sleight of hand, the unpredictable can be made to appear planned and carefully thought out.