Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Tom Gerhardt

Hello there,

this page will be your guide to all things pComp section #2, or as I like to call it 'the best pComp section ever';
it will be updated ever so often with important info, or the choicest links you can imagine, so check back now and again.

When is class again?

6:30-9pm Monday, Classroom 20 (next to pComp lab)

I am best reached at:

tom-AT-tomgerhardt.com

My Office Hours will be:

7-9pm Wednesday, why not schedule a time?



CLASS #1 09/13/2010

'What is pComp?!?!?!' ...the links:
the small:
Robbie The Racist Robot
Tweenbots
Momo
Princes of Persuasion
The Felt Resistor
the large:
Ars Electronica Building
Troika Cloud
The Absolute Machine




MULTI-SENSOR SERIAL CODE

The Processing Code:

import processing.serial.Serial;

public static int packetSize = 4;

int readBuffer[] = new int[ packetSize ]; int readBufferPos = 0; int endOfPacket = 255;

int currentVals[] = new int[ packetSize ]; int latestValue = 0;

Serial ser;

void setup() {

  size( 300,300 );
  //		println( Serial.list());
  ser = new Serial( this,"/dev/tty.usbserial-FTF3JUAW", 9600 );

}

void draw() {

  background( 255 );

  //draw circles
  for( int v=0;v<packetSize;v++ )
  {
    pushMatrix();
    {
      //x
      if( v==0 || v==1 ) translate( 200,0 );
      else translate( 100,0 );
      //y 
      if( v==1 || v==2 ) translate( 0,200 );
      else translate( 0,100 );
      //draw
      this.ellipse( 0,0,currentVals[v]*0.4f,currentVals[v]*0.4f );
    }
    popMatrix();
  }

}

void serialEvent( Serial p ) {

  int inByte = p.read();
  //check bounds
  if( inByte < 0 || inByte > 255 ) return;
  //check for end of packet
  if( inByte == endOfPacket )
  {
    processPacket( readBuffer );//send vals
    readBufferPos = 0;//reset pos
    return;//exit
  }
  //check for overflow
  if( readBufferPos >= packetSize )
  {
    readBufferPos = 0;//reset buffer pos
    return; //exit
  }
  //record
  readBuffer[ readBufferPos ] = inByte;
  readBufferPos++;

}

void processPacket( int[] packet ) {

  if( packet.length != packetSize ) return;

  //record
  for( int v=0;v<packetSize;v++ )
  {
    currentVals[v] = packet[v];
  }

  //		println( packet[0] + "\t" + packet[1] + "\t" + packet[2] + "\t" + packet[3] );

}

The Arduino Code:

int analogIn0 = 0; int analogIn1 = 0; int analogIn2 = 0; int analogIn3 = 0;

void setup() {

  Serial.begin( 9600 );

}

void loop() {

  //read all analog inputs
  analogIn0 = analogRead( 0 );
  analogIn1 = analogRead( 1 );
  analogIn2 = analogRead( 2 );
  analogIn3 = analogRead( 3 );

  //scale vals 0-254 (255 reserved for end of packet)
  analogIn0 = analogIn0 * 0.25;
  analogIn1 = analogIn1 * 0.25;
  analogIn2 = analogIn2 * 0.25;
  analogIn3 = analogIn3 * 0.25;

  //check bounds
  if( analogIn0 > 254 ) analogIn0 = 254;
  if( analogIn1 > 254 ) analogIn1 = 254;
  if( analogIn2 > 254 ) analogIn2 = 254;
  if( analogIn3 > 254 ) analogIn3 = 254;

  //send packet
  Serial.print( analogIn0, BYTE );
  Serial.print( analogIn1, BYTE );
  Serial.print( analogIn2, BYTE );
  Serial.print( analogIn3, BYTE );
  Serial.print( 255, BYTE); //end packet

  //delay
  //delay( 10 );

}

  Edit | View | History | Print | Recent Changes | Search Page last modified on November 01, 2010, at 07:59 PM