Pages: [1]   Go Down
Author Topic: arduino & processing  (Read 6561 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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:
port = new Serial(this, /dev/ttyACM0, 9600);  

that is the com on my linux os.


thanks and best regards
 smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i try this and sems work

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

but now it underline this:
Code:
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:

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)

« Last Edit: January 14, 2011, 12:23:31 pm by mr_Jungle » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

Code:
  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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm on Ubuntu10.10 and Arduino 2560

 smiley
« Last Edit: January 14, 2011, 01:06:57 pm by mr_Jungle » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: