Go Down

Topic: Processing and teensy arduino problem (Read 2 times) previous topic - next topic



I have a problem with processing code and teensy 2 ++ controler. I create a ambilight fonction with teensy 2 ++. I have two programs (program for arduino and program for processing. When i start the two programs, i have a error message like this:

java.io.IOException: Input/output error in writeByte
   at gnu.io.RXTXPort.writeByte(Native Method)
   at gnu.io.RXTXPort$SerialOutputStream.write(RXTXPort.java:1093)
   at processing.serial.Serial.write(Unknown Source)
   at sketch_121106b.draw(sketch_121106b.java:86)
   at processing.core.PApplet.handleDraw(Unknown Source)
   at processing.core.PApplet.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)
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_121106b.draw(sketch_121106b.java:86)
   at processing.core.PApplet.handleDraw(Unknown Source)
   at processing.core.PApplet.run(Unknown Source)
   at java.lang.Thread.run(Thread.java:619)

my processing code is:
Code: [Select]

import java.awt.Robot; //java library that lets us take screenshots
import java.awt.AWTException;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.awt.Dimension;
import processing.serial.*; //library for serial communication

Serial port; //creates object "port" of serial class
Robot robby; //creates object "robby" of robot class

void setup()
port = new Serial(this, Serial.list()[0],9600); //set baud rate
size(100, 100); //window size (doesn't matter)
try //standard Robot class error check
robby = new Robot();
catch (AWTException e)
println("Robot class not supported by your system!");

void draw()
int pixel; //ARGB variable with 32 int bytes where
//sets of 8 bytes are: Alpha, Red, Green, Blue
float r=0;
float g=0;
float b=0;

//get screenshot into object "screenshot" of class BufferedImage
BufferedImage screenshot = robby.createScreenCapture(new Rectangle(new Dimension(1368,928)));
//1368*928 is the screen resolution

int i=0;
int j=0;
//I skip every alternate pixel making my program 4 times faster
for(i =0;i<1368; i=i+2){
for(j=0; j<928;j=j+2){
pixel = screenshot.getRGB(i,j); //the ARGB integer has the colors of pixel (i,j)
r = r+(int)(255&(pixel>>16)); //add up reds
g = g+(int)(255&(pixel>>8)); //add up greens
b = b+(int)(255&(pixel)); //add up blues
r=r/(684*464); //average red (remember that I skipped ever alternate pixel)
g=g/(684*464); //average green
b=b/(684*464); //average blue

port.write(0xff); //write marker (0xff) for synchronization
port.write((byte)(r)); //write red value
port.write((byte)(g)); //write green value
port.write((byte)(b)); //write blue value
delay(10); //delay for safety

background(r,g,b); //make window background average color

My arduino code
Code: [Select]

Arduino Code: (transfer this program to the Arduino)
//Developed by Rajarshi Roy
int red, green, blue; //red, green and blue values
int RedPin = 25 //Red pin 25 has a PWM
int GreenPin = 26; //Green pin 26 has a PWM
int BluePin = 24 //Blue pin 24 has a PWM
void setup()

//initial values (no significance)
int red = 255;
int blue = 255;
int green = 255;

void loop()

//protocol expects data in format of 4 bytes
//(xff) as a marker to ensure proper synchronization always
//followed by red, green, blue bytes
if (Serial.available()>=4) {
if(Serial.read() == 0xff){
red = Serial.read();
green= Serial.read();
blue = Serial.read();
//finally control led brightness through pulse-width modulation
analogWrite (RedPin, red);
analogWrite (GreenPin, green);
analogWrite (BluePin, blue);
delay(10); //just to be safe

I am a noob in programing an i don't understand this problem
can you help me please
thanks for next answers

Coding Badly

[font=Courier New]port = new Serial(this, Serial.list()[0],9600); //set baud rate[/font]

Are you certain the Teensy is the first serial port on your computer?


hello  Coding Badly, thanks for this first answer

I try every COM port available in my computer and the result is the same. My strip led doesn't light. I show you in this photo the port com available. I have COM1 and COM2

I explain you with more details:
firstly, i use only arduino software : (software parameter COM is on COM 2) I add a initialisation code in arduino program in order to know if my electric installation is ok and i program a red light during 2 seconds then green light 2 seconds and finally blue light 2 seconds. I upload the code in teensy 2++ and my strip led light correctly.

Secondely, i try to modify the processing code and change the "0" at port line to [1] or [2]. I run the processing program (arduino code is in the teensy) and the strip led doesn't light.

Do you think the problem is about the COM port or perhaps there are problems with Java or RXTX ?

Sorry for my english, i am french, thanks for next answers

Coding Badly

Unfortunately, that's all the help I can offer.  I have not ever used Processing.  Hopefully, someone else with more (any) experience can help.


I try every COM port available in my computer and the result is the same

That is not the point. Processing has a list of com ports, it is not in the same order as the COM number.
Try printing the serial list to see what com port is the one that is first in the list. I think you will find it is not COM 2.

Go Up