Pages: [1]   Go Down
Author Topic: Problems communicating with processing  (Read 773 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

My problem is as follows -

I am following an Arduino tutorial with processing and TouchOSC on my iPhone to control an RGB LED. So far, I have the TouchOSC interface created and it can control the Processing sketch (3 simple sliders). However, I run into the following problem when trying to add the Arduino to the equation.

Here is the code for the Procsessing sketch:

Code:
import cc.arduino.*;
import processing.serial.*;
import oscP5.*;
import netP5.*;

Arduino arduino;

OscP5 oscP5;

float redAmount = 0.0f;
float greenAmount = 0.0f;

float blueAmount = 0.0f;

void setup(){
  size(320, 480);
  background(0);
  oscP5 = new OscP5(this, 8000);
  [color=red]arduino = new Arduino(this, Arduino.list()[0],57600);[/color]
 
 
}


void draw(){
  background(redAmount, greenAmount, blueAmount);
 
  fill(0);
  //red rect
  stroke(255,0,0);
  rect(34,39,67,255);
  fill(50,40,40);
  rect(34,39+255,67,-redAmount);
 
  //green rect
  fill(0);
  stroke(0,255,0);
  rect(124,39,67,255);
 fill(40,50,40);
  rect(124,39+255,67,-greenAmount);
 
  //blue rect
  fill(0);
  stroke(0,0,255);
  rect(216,39,67,255);
  fill(40,40,50);
  rect(216,39+255,67,-blueAmount);
 
  //write to arduino
  arduino.analogWrite(11, int(redAmount));
  arduino.analogWrite(10, int(greenAmount));
  arduino.analogWrite(9, int(blueAmount));
 
 
 
}

void oscEvent(OscMessage theOscMessage){
  String addr = theOscMessage.addrPattern();
  float val = theOscMessage.get(0).floatValue();
 
  if(addr.equals("/1/red")){ redAmount = val;}
  if(addr.equals("/1/green")){ greenAmount = val;}
  if(addr.equals("/1/blue")){ blueAmount = val;}

 
 
 
}

The issue occurs at the red line.

The error is as follows:

Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0
    at Colour_Mixer.setup(Colour_Mixer.java:45)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:662)



I have read that I should perform a println(Arduino.list()), but where can I read the output of this command?

I am running Ubuntu Linux 10.10 Maverick Meerkat 64 bit, Processing 1.5.1, and I have tried uploading both the Standard Firmata and the Standard Firmata For Uno sketches to the Arduino.

Thanks in advance,

Sam
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The output of the println should appear in the Processing console below the editor.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Many thanks - I was not seeing this due to a java version mismatch. All is well now.
Logged

Pages: [1]   Go Up
Jump to: