Go Down

Topic: arduino & processing (Read 7402 times) previous topic - next topic

mr_Jungle

hi, im new to arduino and i'm tryng to test some simple example of the learnig section of the site.

Now i'm stuck on "drimmer" example  

(/arduino.cc/en/Tutorial/Dimmer)


i try to paste the code on processing tool and run it but don't work proprely. I'm pretty sure that the issue is on the serial com but i don't know how resolve it.

this is the code:

Code: [Select]
import processing.serial.*;
Serial port;

void setup() {
size(256, 150);

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

// Uses the first port in this list (number 0).  Change this to
// select the port corresponding to your Arduino board.  The last
// parameter (e.g. 9600) is the speed of the communication.  It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, Serial.list()[0], 9600);  

// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}

void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}

port.write(mouseX);
}


this is the answer:

Code: [Select]
Available serial ports:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
processing.app.debug.RunnerException: ArrayIndexOutOfBoundsException: 0
     at processing.app.Sketch.placeException(Sketch.java:1543)
     at processing.app.debug.Runner.findException(Runner.java:582)
     at processing.app.debug.Runner.reportException(Runner.java:558)
     at processing.app.debug.Runner.exception(Runner.java:498)
     at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
     at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
     at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0
     at sketch_jan14a.setup(sketch_jan14a.java:36)
     at processing.core.PApplet.handleDraw(Unknown Source)
     at processing.core.PApplet.run(Unknown Source)
     at java.lang.Thread.run(Thread.java:636)



i also try to change whit:

Code: [Select]
port = new Serial(this, /dev/ttyACM0, 9600);  

that is the com on my linux os.


thanks and best regards
:)

mr_Jungle

#1
Jan 14, 2011, 06:22 pm Last Edit: Jan 14, 2011, 06:23 pm by mr_Jungle Reason: 1
i try this and sems work

Code: [Select]
port = new Serial(this, "/dev/ttyUSB0", 9600);  

but now it underline this:
Code: [Select]
import processing.serial.*;
Serial port;
 void setup() {
size(256, 150);
  println("Available serial ports:");
  println(Serial.list());
    port = new Serial(this, "/dev/ttyUSB0", 9600);  
}
 void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
 // write the current X-position of the mouse to the serial port as
// a single byte
[glow] port.write(mouseX);[/glow]
}


and give me back this:

Code: [Select]


Available serial ports:
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
java.lang.NullPointerException
     at processing.serial.Serial.write(Unknown Source)
     at sketch_jan14a.draw(sketch_jan14a.java:52)
     at processing.core.PApplet.handleDraw(Unknown Source)
     at processing.core.PApplet.run(Unknown Source)
     at java.lang.Thread.run(Thread.java:636)
processing.app.debug.RunnerException: RuntimeException: Error inside Serial.write()
     at processing.app.Sketch.placeException(Sketch.java:1543)
     at processing.app.debug.Runner.findException(Runner.java:582)
     at processing.app.debug.Runner.reportException(Runner.java:558)
     at processing.app.debug.Runner.exception(Runner.java:498)
     at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
     at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
     at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.write()
     at processing.serial.Serial.errorMessage(Unknown Source)
     at processing.serial.Serial.write(Unknown Source)
     at sketch_jan14a.draw(sketch_jan14a.java:52)
     at processing.core.PApplet.handleDraw(Unknown Source)
     at processing.core.PApplet.run(Unknown Source)
     at java.lang.Thread.run(Thread.java:636)



PaulS

Code: [Select]
Serial port;
declares a variable named port, of type Serial. It does not assign it a value.

Code: [Select]
port = new Serial(this, "/dev/ttyUSB0", 9600);
tries to assign port a value. It is not guaranteed to succeed.

Code: [Select]
port.write(mouseX);
This code assumes that port is a valid object, which it may not be.

Code: [Select]
  println("Available serial ports:");
  println(Serial.list());

This code lists all the serial ports that Processing knows it can talk to. Notice that the list is empty. This means that Processing does not know how to talk to any of the com ports that may be on your computer.

This, along with the port names that you are trying to force it to use, suggests that you have a Uno and are not using Windows.

Con you confirm what Arduino you have and what OS you are on?

mr_Jungle

#3
Jan 14, 2011, 07:06 pm Last Edit: Jan 14, 2011, 07:06 pm by mr_Jungle Reason: 1
I'm on Ubuntu10.10 and Arduino 2560

:)

PaulS

Processing has not caught up with the new Arduinos, yet (the Uno and the Mega 2560).

You might get away with explicitly defining the COM port to use, but I'm not sure if that really works. Your troubles seem to indicate not.

Go Up