IFD:Fire Water Air and Earth. And Electricity!/Shuyan

From Medien Wiki

Introduction

Nowadays, Arduino has been widely used to be as input and output in physical programming, and I wanna find out a different way which can be more convenient to build interactions between Arduino and our daily life. So what I have done was to use mobile terminal as a way to make something happen in Arduino side. I found TouchOSC from my research, this app is a data transmission based on osc(open sound control) message. Here is the website: http://hexler.net/software/touchosc. There are many intersting user interface can be found in TouchOsc, and the controls vary differently to fullfill your different needs.

How it works

Phone and computer are necessary to be connected to the same wireless network, and typing in the ip adress of your computer in TouchOSc side, so that connection is built to send the data from TouchOsc to your computer. In order to receive the data of TouchOsc in processing side, you need to write the incoming port which is outgoing port in TouchOsc side. After that, data are analyzed to be sent to Arduino through the serial port. NOTICE: you should upload your Ardunio first to build the connection between your Arduino IDE and your sensors before you run the processing code, so that the connection between processing and TouchOsc will not occupy the serial port. So in this work, I was using the push controls in TouchOsc to control the rotation of servo in Ardunio side. Processing was used to receive the data of TouchOsc and read the data of the controls to be sent to the servos in Arduino side.

 

 

 

Processing

import oscP5.*; // Load OSC P5 library import netP5.*; // Load net P5 library import processing.serial.*; // Load serial library

Serial arduinoPort; // Set arduinoPort as serial connection OscP5 oscP5; // Set oscP5 as OSC connection

int redLED = 0; // redLED lets us know if the LED is on or off int [] led = new int [5]; // Array allows us to add more toggle buttons in TouchOSC float v_push1 = 0.0f; float v_push2 = 0.0f;

void setup() {

 size(100,100);        // Processing screen size
 noStroke();            // We don’t want an outline or Stroke on our graphics
 oscP5 = new OscP5(this,8000);  // Start oscP5, listening for incoming messages at port 8000
 arduinoPort = new Serial(this, Serial.list()[3], 9600);    // Set arduino to 9600 baud
 print(Serial.list()[3]);

}

void oscEvent(OscMessage theOscMessage) { // This runs whenever there is a new OSC message

   String addr = theOscMessage.addrPattern();  // Creates a string out of the OSC message
   float val = theOscMessage.get(0).floatValue();
   if(addr.equals("/1/push1")) { v_push1 = val; }
   else if(addr.equals("/1/push2")) { v_push2 = val; }

}

void draw() {

background(50);        // Sets the background to a dark grey, can be 0-255
if(v_push1 == 1){        //  If led button 1 if off do....
   arduinoPort.write("F");    // Sends the character “F” to Arduino
   redLED = 0;        // Sets redLED color to 0, can be 0-255
 }
if(v_push2 == 1){        // If led button 1 is ON do...
 arduinoPort.write("B");    // Send the character “B” to Arduino
 redLED = 255;        // Sets redLED color to 255, can be 0-255
 }
fill(redLED,0,0);            // Fill rectangle with redLED amount
ellipse(50, 50, 50, 50);    // Created an ellipse at 50 pixels from the left...
               // 50 pixels from the top and a width of 50 and height of 50 pixels

}


Arduino

  1. include <Servo.h>

Servo me; float val=0.000f; int message=0; int ledpin=9;

void setup() {

 Serial.begin(9600);
 me.attach(ledpin);
 pinMode(11, OUTPUT);

}

void loop() {

  if(Serial.available()>0){
    message = Serial.read();
    digitalWrite(11,HIGH);
   if(val<179 && message == 'F'){
     val= val + 1;
     me.write(val);
     delay(5);
     Serial.println(val);
   }if(message == 'B'){
     me.write(val);
     val = val - 1;
     delay(5);
     Serial.println(val);
   }
   
  }
  
  

}

Development

When I was choosing to use the servos, I wanted to build my mobile phone as a portable controller to control the movement of an object. So it literally can be developed into many other contollers, such as remote Car controller, remote Fan controller, etc.