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 › worse code or is arduino really that slow
Page Index Toggle Pages: 1
worse code or is arduino really that slow (Read 809 times)
worse code or is arduino really that slow
Oct 13th, 2008, 10:35am
 
The following sketch should capture a video signal from a DV cam, check if a pixel fulfills a condition (brightness), then give a response. The patch works fine as I see the response in time on my screen. But the same responde should also be sent to arduino. Now it's getting strange. Arduino gives respones when I start the patch,after ~1 sec nothing.
I'm not a efficient programmer so maybe my code is crap/too slow. Or is the arduino-processing communication crapy.
Thanks for any hint.

import JMyron.*;

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

JMyron m;

//fixe pixelpositionen für notengrabbing
int x_gr = 172;
int x_ro = 286;
int x_ge = 403;
int x_bl = 516;
int x_or = 629;
int y = 377;
int x = 0;

int num = 0;

int w = 720;
int h = 576;

boolean hit = false;

int i=0;
int j=0;

int pin = 11;

color gruen = color(0, 255,0);
color rot = color(255, 0,0);
color gelb = color(255, 255,0);
color blau = color(0, 0,255);
color orange = color(255, 170,0);

color fc = color(0,0,0);

color blank = color(255,255,255);

void setup(){

 int w = 720;
 int h = 576;
 //int w = 320;
 //int h = 240;

 colorMode(HSB, 255);

 size(w,h);

 m = new JMyron();
 m.start(720,576);
 m.findGlobs(1);
 println("Myron " + m.version());

 //arduino setup
 
 arduino = new Arduino(this, Arduino.list()[1], 115200);
 arduino.pinMode(11, Arduino.OUTPUT);
 arduino.pinMode(12, Arduino.OUTPUT);
 arduino.pinMode(13, Arduino.OUTPUT);

}

void mousePressed(){

 println(mouseX);
 println(mouseY);

}

void draw(){

 m.trackColor(255,255,255,255);

 m.update();
 int[] img = m.image();

 //first draw the camera view onto the screen
 loadPixels();

 for(int i=0;i<width*height;i++){
   pixels[i] = img[i];
 }

 updatePixels();

 for(int j=0; j<=2; j++) {
   switch(j) {
   case 0:
     x = x_gr;
     fc = gruen;
     break;
   case 1:
     x = x_ro;
     fc = rot;
     break;
     case 2:
     x = x_ge;
     fc = gelb;
     break;
   
   }

   color cp = pixels[y*w+x];
   float value = brightness(cp);

   //check if brightness value is above
   if (value >= 200) {

     hit =true;
     pin = pin + 1;

     arduino.digitalWrite(pin, Arduino.HIGH);
     arduino.digitalWrite(pin, Arduino.LOW);
   }

   noStroke();
   fill(blank);

   if (hit) {
     fill(fc);
     hit = false;
   }
   rect(x, 0, 55, 55);
 
 
   rect(x_gr, y, 5, 5);
   rect(x_ro, y, 5, 5);
   rect(x_ge, y, 5, 5);
   rect(x_bl, y, 5, 5);
   rect(x_or, y, 5, 5);
 }
}

public void stop(){
 m.stop();
 super.stop();
}

Re: worse code or is arduino really that slow
Reply #1 - Oct 14th, 2008, 9:35am
 
Arduino is pretty fast Smiley

You should never use 115200 baud speed while communicating with arduino unless you plan to send a LOT of data.

This has been discussed at length on the Arduino forum but the summary is :
When you switch to that speed the USB driver made by FTDI increases the communication buffer to 4k. If you dont fill that up with data it waits until a timeout before actually transfering the data.
You'll find that at 9600 baud it's much faster...

BTW place a println("i'm sending to arduino");
before the arduino commands so you can see if it's the arduino that's slow in responding or your processing code.

massimo
Page Index Toggle Pages: 1