- Got same delay on Processing 1.5.1 and Processing 2.0a6 on Windows 7 (with RXTX fix; Arduino is only COM port listed)
- Got same delay on Processing 1.5.1 on Mac 10.5 (with RXTX fix)
- Reinstalled Processing 1.5.1 on Windows 7 and included the Arduino-Processing library. The sketch runs despite the version mismatch but experiences the same delay.
Lets see if we can figure out if the delay is on the Processing side, the Arduino side, or both. Can you add a println() to your processing code right at the top of the mouse event code, and a Serial.println() on the Arduino side right where you first check for incoming data?
Once you do that, does that narrow the problem down?
Just to be sure, you did put a message in the Processing println() function you added, right? So the line looks like this...
println("Over the rectangle!");
...when you run the sketch do you see the message appear immediately in the Processing window when you mouse over the rectangle? Or is there a delay there?
Same thing with the Arduino, you DO have a message in the Serial.println(), right? Like this...
Serial.println("Got serial data from the processing sketch!");
When you run the Arduino sketch with the serial monitor window open, does THAT message show up right away?
I have no idea what the problem might be, but keep reading about other people haveing problems with arduino and large delays.
I made a small test-code, which you could test if you like. It turns the led on the arduino-board on/off and prints the time it takes until a message from arduino is sent back. This time should not be more than a few milliseconds.
Arduino:
// libraries
#include <Messenger.h>
// instantiate Messenger object with the default separator (the space character)
//Messenger message = Messenger();
String message;
// led pin
int ledPin = 13;
int incomingByte = 0; // for incoming serial data
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
digitalWrite(ledPin, incomingByte);
// send something back
Serial.println(incomingByte, DEC);
}
}
Processing:
// libraries
import processing.serial.*;
// serial connection
Serial port;
// toggle light
byte toggleLight = 0;
// time
int sendAt;
void setup() {
// size
size(200, 200);
// print all available serial ports
println(Serial.list());
// init connection to arduino
port = new Serial(this, Serial.list()[0], 57600);
}
// serial event
void serialEvent(Serial p){
// get message till line break (ASCII > 13)
String message = port.readStringUntil(13);
// just if there is data
if (message != null) {
println("response time: "+(millis()-sendAt));
}
}
So if you have large delay with this code, then it should be something with your hardware-setup. Otherwise, please post your arduino- and processing-code, so we can have a look and maybe fix it.
Hi all,
I just encountered this Processing/Arduino bug recently. My serial code, which was working properly with earlier versions of Processing/Arduino, now suffers from huge delays. My Processing code doesn't wait for a reply from Arduino. It only checks if the serial port is open during the draw() loop. I've also tried simply writing to the serial port without checking as well.
If the USB FTDI adapter is plugged in (whether the Arduino is powered or not) the delay occurs. When I pull the FTDI or disable the Processing serial code, it runs fine.
Hmmm.
Michael