I used to have this naive thinking that reading a sensor input from arduino is just a few lines of codes that I can copy and paste over and over again , probably because I worked with quite a lot of sensors in my last project “portable windows” as well, but for portable windows I was doing everything in arduino. So when I really wanted to start bringing in a few different input from the same port, I was completely stoned. Thankfully, I got myself a copy of “Making things work” by tom igoe and I saved myself back there. So i’m going to share this code with everyone, I modified it a little, its all about assigning variables so it should be easy. I would love to help if anyone needs any (not that i’m good) , but i’ll try.

here goes : processing.

import processing.serial.*;

int linefeed = 10;
Serial myPort; // The serial port

int one, two, three, four, five;

void setup()
{
size(512, 200);
// always start Minim first
println(Serial.list());

myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(linefeed);

}

void draw(){

background(0);
if(two>0){
five=two;

}
else{
two=five;
}
println(”five =”+five);
delay(1000);
}

void serialEvent(Serial myPort){
String myString = myPort.readStringUntil(linefeed); //the ascii value of the “|” character
if(myString != null ){
myString = trim(myString);
int sensors[] = int(split(myString, ‘,’));
//now assign your values in processing

if (sensors.length == 4){

one = sensors[0];
two = sensors[1];
three = sensors[2];
four = sensors[3];

println(”one =”+one);
println(”two =”+two);
println(”three =”+three);
println(”four =”+four);

}

}

}

For arduino’s part, its per normal but when you do a serial print u need to add a “,” after each sensor’s data. And after the last println it should end with a “|” println. What this does is that it recognises every data as an input denoted by the comma and ends every loop with an “|”.

Example :

Serial.print(gas,DEC);
Serial.print(”,”);
Serial.println(retTemp, DEC);
// Serial.print(”|”);

hope that helps.

Poet of the Piano

Posted on September 25th, 2007 in Readings music processing

Notes were his words
Ivories were his tools
Music was his poetry

Chopin the poet of the piano
My greatest champion of classical music
His music never fails to entrance me

So What’s all this about? I just read the biography of Chopin and i’m quite moved by this truly artistic pianist of his time. All along i felt it in his music and after reading this i feel even more so. This realtime graphic is dedicated to him, inspired by his raindrop prelude. If you have a mic connected to your com, play a song and watch it react to the song. If you play the piano , play the raindrop prelude along with it :) . You need java though.

raindrop.jpg

http://www.ctrlsave.com/applet/index.html