We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Huge 20sec+ delay in with Arduino.
Page Index Toggle Pages: 1
Huge 20sec+ delay in with Arduino. (Read 1229 times)
Huge 20sec+ delay in with Arduino.
Nov 3rd, 2008, 6:38pm
 
Hi,
At the moment I'm having a huge, 20 second plus delay when sending anything to my Arduino Diecimila via processing Serial Library.
I've had it running fine with much more data being sent over in the past.
Basically I'm trying to get the simpleWrite program working in Processing but as I said there's a huge delay of about 20 seconds from when I put the cursor over the rectangle to when arduino actually executes the command.
When I send an H (turns on the LED) in arduino IDE serial monitor it works fine.

Any ideas anybody?
Thanks

Tim
Re: Huge 20sec+ delay in with Arduino.
Reply #1 - Nov 3rd, 2008, 11:02pm
 
Ok, I now have some more information after playing for a little while. I've edited the simpleWrite code mainly to add a delay of 500 at the beginning of void draw() so that it now looks like this...

Quote:
/**
 * Simple Write. 
 * 
 * Check if the mouse is over a rectangle and writes the status to the serial po
rt. 

 * This example works with the Wiring / Arduino program that follows below.
 */


import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;        // Data received from the serial port

void setup()
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw() {
  delay(500);
  println("done");
  background(255);
  if (mouseOverRect() == true) {  // If mouse is over square,
    fill(204);                    // change color and
    myPort.write('H');              // send an H to indicate mouse is over square
  } 
  else {                        // If mouse is not over square,
    fill(0);                      // change color and
    myPort.write('L');              // send an L otherwise
  }
  rect(50, 50, 100, 100);         // Draw a square
}

boolean mouseOverRect() { // Test if mouse is over square
  return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}



the 20 second lag is now gone (except for when the code goes through the delay) but obviously no good for any kind of work that I want to do.
Any ideas? I'm thinking along the lines of bandwidth or something like that!?

Thanks again, Tim
Re: Huge 20sec+ delay in with Arduino.
Reply #2 - Nov 5th, 2008, 3:01pm
 
try to increase the baudrate of the serial connection to 57600 instead of 9600 or send the data to the arduino only when the event occurs and not continously in the draw loop.
Re: Huge 20sec+ delay in with Arduino.
Reply #3 - Nov 6th, 2008, 1:44am
 
Still not working how it should I'm afraid! Still a large lag between the two events. Could this be a bug in the processing Serial Library? I've tried running this simple code on 4 machines under 3 different OS's.

Tim
Re: Huge 20sec+ delay in with Arduino.
Reply #4 - Nov 6th, 2008, 4:13pm
 
could you paste the code you have on your arduino? I don't think that this is a bug of the serial lib, recently i used it for an installation which runs for hours.
Re: Huge 20sec+ delay in with Arduino.
Reply #5 - Nov 6th, 2008, 5:09pm
 
As I've said it's just the simpleWrite example in processing and the arduino code looks like this:

Quote:
  // Wiring/Arduino code:
 // Read data from the serial and turn ON or OFF a light depending on the value
 
 char val; // Data received from the serial port
 int ledPin = 4; // Set the pin to digital I/O 4
 
 void setup() {
 pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
 Serial.begin(9600); // Start serial communication at 9600 bps
 }
 
 void loop() {
 if (Serial.available()) { // If data is available to read,
 val = Serial.read(); // read it and store it in val
 }
 if (val == 'H') { // If H was received
 digitalWrite(ledPin, HIGH); // turn the LED on
 } else {
 digitalWrite(ledPin, LOW); // Otherwise turn it OFF
 }
 delay(100); // Wait 100 milliseconds for next reading
 }



I had an installation recently (in the summer) which relied on processing and arduino working together over the serial library which makes this so frustrating!

Thanks for your help.

Tim
Page Index Toggle Pages: 1