Skip to main content
Tweeted twitter.com/#!/StackArduino/status/508491888790212608
added 3 characters in body
Source Link

I'm currently on project #14 of the arduinoArduino project book.

I'm trying to control a processing sketch on my laptop using my arduinoArduino.This This is accomplished by using a potentiometer to control the background of an image.

Arduino code:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write(analogRead(A0)/4);
}

Processing:

//imports serial library
import processing.serial.*;
//setups the serial object
Serial myPort;
//creates an object for the image
PImage logo;
//variable to store background color
int bgcolor = 0;

void setup(){
  colorMode(HSB,255);
  logo = loadImage("http://arduino.cc/logo.png");
  size(logo.width,logo.height);
  println("Available serial ports");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);
}
//equivalent of arduino's loop function
void draw(){
  if(myPort.available() > 0)
  {
    bgcolor = myPort.read();
    println(bgcolor);
  }

  background(bgcolor,255,255);
  image(logo,0,0);
}

Now, while the code works, and the background color changes as i turn the potentiometer, there is a [b]HUGE[/b]huge lag between turning the potentiometer and seeing the background change color, and the values from the arduinoArduino/potentiometer change on the processing's serial monitor.

What i'veI've tried:

  • Changing the speed of Serial communication

I've noticed that when iI decrease the speed of Serial communication, e.g. around 100, the delay between turning the potentiometer and seeing it change on my laptop decreases to about 1 secsecond. However, when iI decrease the speed of Serial communication even further E, e.g   a value of 1, the delay increases again.

On the flipsideflip side, at the standard speed of 9600, the delay is huge,roughyl about roughly 5sec ++ before the changes in the potentiometer show up on the laptop/processing.

Why does decreasing the communication speed  (up to a certain point) decrease the time lag,and and increasing it increase the time lag.Also? Also,is is there anyway iI can make it near instantaneous?

I'm currently on project #14 of the arduino project book.

I'm trying to control a processing sketch on my laptop using my arduino.This is accomplished by using a potentiometer to control the background of an image.

Arduino code:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write(analogRead(A0)/4);
}

Processing:

//imports serial library
import processing.serial.*;
//setups the serial object
Serial myPort;
//creates an object for the image
PImage logo;
//variable to store background color
int bgcolor = 0;

void setup(){
  colorMode(HSB,255);
  logo = loadImage("http://arduino.cc/logo.png");
  size(logo.width,logo.height);
  println("Available serial ports");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);
}
//equivalent of arduino's loop function
void draw(){
  if(myPort.available() > 0)
  {
    bgcolor = myPort.read();
    println(bgcolor);
  }

  background(bgcolor,255,255);
  image(logo,0,0);
}

Now, while the code works, and the background color changes as i turn the potentiometer, there is a [b]HUGE[/b] lag between turning the potentiometer and seeing the background change color, and the values from the arduino/potentiometer change on the processing's serial monitor.

What i've tried:

  • Changing the speed of Serial communication

I've noticed that when i decrease the speed of Serial communication, e.g around 100, the delay between turning the potentiometer and seeing it change on my laptop decreases to about 1 sec. However, when i decrease the speed of Serial communication even further E.g   a value of 1, the delay increases again.

On the flipside, at the standard speed of 9600, the delay is huge,roughyl about 5sec ++ before the changes in the potentiometer show up on the laptop/processing.

Why does decreasing the communication speed(up to a certain point) decrease the time lag,and increasing it increase the time lag.Also,is there anyway i can make it near instantaneous?

I'm currently on project #14 of the Arduino project book.

I'm trying to control a processing sketch on my laptop using my Arduino. This is accomplished by using a potentiometer to control the background of an image.

Arduino code:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write(analogRead(A0)/4);
}

Processing:

//imports serial library
import processing.serial.*;
//setups the serial object
Serial myPort;
//creates an object for the image
PImage logo;
//variable to store background color
int bgcolor = 0;

void setup(){
  colorMode(HSB,255);
  logo = loadImage("http://arduino.cc/logo.png");
  size(logo.width,logo.height);
  println("Available serial ports");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);
}
//equivalent of arduino's loop function
void draw(){
  if(myPort.available() > 0)
  {
    bgcolor = myPort.read();
    println(bgcolor);
  }

  background(bgcolor,255,255);
  image(logo,0,0);
}

Now, while the code works, and the background color changes as i turn the potentiometer, there is a huge lag between turning the potentiometer and seeing the background change color, and the values from the Arduino/potentiometer change on the processing's serial monitor.

What I've tried:

  • Changing the speed of Serial communication

I've noticed that when I decrease the speed of Serial communication, e.g. around 100, the delay between turning the potentiometer and seeing it change on my laptop decreases to about 1 second. However, when I decrease the speed of Serial communication even further, e.ga value of 1, the delay increases again.

On the flip side, at the standard speed of 9600, the delay is huge, roughly 5sec ++ before the changes in the potentiometer show up on the laptop/processing.

Why does decreasing the communication speed  (up to a certain point) decrease the time lag, and increasing it increase the time lag? Also, is there anyway I can make it near instantaneous?

Source Link
Kenneth .J
  • 393
  • 1
  • 5
  • 11

Reducing lag between the arduino and a processing sketch on my computer

I'm currently on project #14 of the arduino project book.

I'm trying to control a processing sketch on my laptop using my arduino.This is accomplished by using a potentiometer to control the background of an image.

Arduino code:

void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.write(analogRead(A0)/4);
}

Processing:

//imports serial library
import processing.serial.*;
//setups the serial object
Serial myPort;
//creates an object for the image
PImage logo;
//variable to store background color
int bgcolor = 0;

void setup(){
  colorMode(HSB,255);
  logo = loadImage("http://arduino.cc/logo.png");
  size(logo.width,logo.height);
  println("Available serial ports");
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[0],9600);
}
//equivalent of arduino's loop function
void draw(){
  if(myPort.available() > 0)
  {
    bgcolor = myPort.read();
    println(bgcolor);
  }

  background(bgcolor,255,255);
  image(logo,0,0);
}

Now, while the code works, and the background color changes as i turn the potentiometer, there is a [b]HUGE[/b] lag between turning the potentiometer and seeing the background change color, and the values from the arduino/potentiometer change on the processing's serial monitor.

What i've tried:

  • Changing the speed of Serial communication

I've noticed that when i decrease the speed of Serial communication, e.g around 100, the delay between turning the potentiometer and seeing it change on my laptop decreases to about 1 sec. However, when i decrease the speed of Serial communication even further E.g  a value of 1, the delay increases again.

On the flipside, at the standard speed of 9600, the delay is huge,roughyl about 5sec ++ before the changes in the potentiometer show up on the laptop/processing.

Why does decreasing the communication speed(up to a certain point) decrease the time lag,and increasing it increase the time lag.Also,is there anyway i can make it near instantaneous?