help needed with processing code

Can anyone tell me what I am doing wrong? I have an Arduino Duemilanove sketch running, which correctly outputs data as follows.

Arduino serial monitor output (typical values) - 656 656 656 658 656 656 656 657 656 655 657

I am using the following readString() example from the processing reference -

// Example by Tom Igoe

import processing.serial.*;

Serial myPort; // The serial port

void setup() { // List all the available serial ports: println(Serial.list());

// I know that the first port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[0], 9600); }

void draw() { while (myPort.available() > 0) { String inBuffer = myPort.readString(); if (inBuffer != null) { println(inBuffer); } } }

The problem is that blank lines are sometimes inserted, and the string is sometimes split into two lines, as shown below.

The processing output window -

Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 [0] "COM3" 658 658 658

658 659 658

658 659 659

657 659 660

659 658 655 6 59 659 659 6 59 659 656 65 9

Thanks in advance!

The readString function takes an optional argument that defines what terminates the string. With no value supplied, the end of the serial data terminates the string.

You need to have the Arduino send some consistent line terminator (using Serial.println is fine). Then, you need to tell readString to wait for that terminator to arrive.

Paul, Many thanks for your help. As an aside, Arduino is using Serial.println. The readString function without arguments seems a bit too flaky to be of any use. At least, to noobs like me. Regards. Simon