Week 16

interface and application programming
(May 18)

Assignment:

write an application that interfaces with an input &/or output device that you made, comparing as many tool options as possible

1. Prepare Arduino code

For this assignment I use the old modified Satshakit I've made as a test for old input/networking assignment (abandoned for 2nd Evaluation round). I want to use it's input (capacitive & temperature) and visualize the parameter with Processing or VVVV.
On the back there is circuit board with temperature sensor. On the other side there is capacitive area.

Both Processing and vvvv will listen to arduino IDE with Serial comunication. In case of Processing, I use Serial.write. In case of vvvv, I use Serial.println

/* read temperature + capacitive sensor
    serial write to processing
    serial println to vvvv
*/

#include <VirtualWire.h>
#include <CapacitiveSensor.h>

CapacitiveSensor capSensor = CapacitiveSensor (4, 2);
int threshold = 1000;


void setup()
{
  pinMode (13, OUTPUT);
  Serial.begin(9600);
  Serial.println("setup");
  vw_setup(2000);  // Bits per sec
}

void loop()
{
  int tempValue = analogRead(A0); //temperature sensor
  int capValue = capSensor.capacitiveSensor(30); // capacitive sensor

  Serial.print(capValue);
  Serial.print(',');
  Serial.println(tempValue);

  if (capValue > threshold) {
    digitalWrite(13, HIGH); 
   // Serial.write(tempValue); // write in serial for processing

  } else {
    digitalWrite(13, LOW);
  }
}

2. Processing

The code goes like this :
import processing.serial.* ;
Serial myPort;
float alfa = 0.0;
int bgcolor =0;
int raw = 0;
float easing = 0.05;
float smoothDest = 0.0;

void setup() {
  size (800, 200);
  colorMode(HSB, 255);

  println("Available serial ports: ");
  println(Serial.list());

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

void draw() {
  if (myPort.available() > 0) {
    alfa = 255;
    raw = myPort.read();
    bgcolor = int(map(raw,0,30,1,255));
    println(bgcolor);
  } else { 
    alfa = 0;
  }
  smoothDest = smoothDest + (bgcolor-smoothDest) * easing;
  background(smoothDest, 255, 255);
  textSize(32);
  text("processing your prophecy..", 200, height/2); 

  fill(255, alfa);
}

2. vvvv

vvvv is a hybrid visual/textual live-programming environment for easy prototyping and development. For communicate it with Arduino you can use Serial.println in arduino and read it with asString (raw) node in vvvv.
There is a full reference from inside vvvv folder : girlpower\IO\Arduino\1_Arduino_DataAsStrings.v4p

Serial communication

Main sketch

read from temperature sensor then calculate

For data visualization

3. Interference problem ?

I have noticed a huge amount of disturbing value.. seems like when the capacitive value is over 1000, it disturbs temperature value and that make temperature value wrong


I print the value in this format : capacitive read, temperature read

This screenshot is when capacitive is not touched

Now it is touched. notice that capacitive value is above 1000 and the temperature read is above reality (it should be around 150-160)

Could it be interference ? Is capacitive area to big ? I tried a stupid thing : put a paper on the capacitive surface and it lower the value a lot !

the visualization



Download files :
Processing sketch (pde)
vvvv patches (zip) used with vvvv_45beta34.2_x86



<< previous | next >>