How many times do you suppose the draw() method in the Processing application is called, while the Arduino reads the serial data that it got? draw() is sending data far faster than the Arduino can read it, so the Arduino's receive buffer fills up. Data that arrives while the buffer is full is placed in the bit bucket. There is no method to retrieve data from the bit bucket.

Your Processing application has not implemented a handler (serialEvent) to be called when serial data arrives, so that data is not processed. Not processing data is far faster than processing it.

The speed at which draw() is called is only marginally affected by serial data processing. You need to add a delay to draw, so that data is sent at a more manageable (by the Arduino) rate.

if (Serial.available()) { Serial.println(Serial.read()); Serial.println('h');Now, you are sending the character plus a carriage return and line feed, the 'h' plus a carriage return and line feed, for a total of 6 characters.

Perhaps the Serial.println()s should be Serial.print()s to get rid of the carriage returns and line feeds.

I don't know what frameCount is, or how or where it is initialized or incremented. So, I can't comment on the output you show.

How are you capturing the Arduino output separate from the Processing output? You have one serial connection. Either the Serial Monitor should be on the other end (the Arduino is on one end) OR the Processing application should be on the other end.

Then the bufferUntil is useless right?http://processing.org/reference/libraries/serial/Serial_bufferUntil_.html

Quote

The 3rd line prints that character plus a carriage return and line feed. 3 characters.

A carriage return is like pressing enter/return on the keyboard right? So isn't that a line feed allready?

frameCount prints the current frame number, so when you start a processing sketch it starts with 1 and then it just counts.It would be like this in arduino (only in processing it's a default thing, you don't have to create the variable frameCount)

How are you capturing the Arduino output separate from the Processing output? You have one serial connection. Either the Serial Monitor should be on the other end (the Arduino is on one end) OR the Processing application should be on the other end.

The processing pde has a console, if i use println("something"); then it goes to the processing console, i could also create a printWriter to create a textfile for example then i can use output.println("something"); for example and it gets added to the textfile.

Quote

What OS are you using?

mac os x, lion

Quote

What, exactly, is the problem we are trying to address?

I want to set a simple delay with processing. Setting a delay between 0 and 255 is quite easy for that just send a byte, however i need a bigger range. I think something between 0 and 1000ms. Afcorse i could use a byte and multiply it by 4 by the arduino which is more easy (but 4 times less precise) but for the purpose of learning i don't.So at the moment i just try to send a value with processing, receive it with arduino and then send it back to processing (<< that is my goal).I used frameCount for now cause it's easy to see if things are going correct since it's produces 1,2,3,4,5,6,7,8,9,10,11 etc. If you look in the output below, you see a bit of it coming back.

A carriage return is like pressing enter/return on the keyboard right? So isn't that a line feed allready?

Ever seen a typewriter? There is a lever that you use to return the carriage to the left side of the typewriter, and advance the paper so you can type on the next line. So, the carriage return and line feed are separate activities. The enter key on a PC emulates the carriage return/line feed. How do you suppose it does that? Hint: it was two separate activities.

Quote

frameCount prints the current frame number, so when you start a processing sketch it starts with 1 and then it just counts.

"it just counts" when? Details are crucial. What causes it to increment?

Quote

The processing pde has a console, if i use println("something"); then it goes to the processing console

That explains how you know what Processing received. You seem to know what the Arduino sent, too. How?

Quote

Afcorse i could use a byte and multiply it by 4 by the arduino which is more easy (but 4 times less precise) but for the purpose of learning i don't.

Afcorse.

Quote

I used frameCount for now cause it's easy to see if things are going correct since it's produces 1,2,3,4,5,6,7,8,9,10,11 etc. If you look in the output below, you see a bit of it coming back.

Then why complicate with that 9999 or h crap. Just use the Serial.println() function on the Arduino and bufferUntil('\n'); in the Processing application.

The Processing application sends a string ("0", "1", ... , "10", "11"). You need to read that string, convert it to a number, and send that number back to Processing (as a string) to validate the communication process.

Ever seen a typewriter? There is a lever that you use to return the carriage to the left side of the typewriter, and advance the paper so you can type on the next line. So, the carriage return and line feed are separate activities. The enter key on a PC emulates the carriage return/line feed. How do you suppose it does that? Hint: it was two separate activities.

I understand it with a typewriter, but not with arduino.

Quote

Quote

frameCount prints the current frame number, so when you start a processing sketch it starts with 1 and then it just counts.

"it just counts" when? Details are crucial. What causes it to increment?

from: http://processing.org/reference/frameCount.html

Quote

The system variable frameCount contains the number of frames displayed since the program started. Inside setup() the value is 0 and and after the first iteration of draw it is 1, etc.

So every iteration of draw increments it.

Quote

Quote

The processing pde has a console, if i use println("something"); then it goes to the processing console

That explains how you know what Processing received. You seem to know what the Arduino sent, too. How?

by the serial monitor, or don't you mean that?

Quote

Quote

I used frameCount for now cause it's easy to see if things are going correct since it's produces 1,2,3,4,5,6,7,8,9,10,11 etc. If you look in the output below, you see a bit of it coming back.

Then why complicate with that 9999 or h crap. Just use the Serial.println() function on the Arduino and bufferUntil('\n'); in the Processing application.

bufferUntil('\n'); is a good idea! thanks! wish i could test it right away.