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.
Page Index Toggle Pages: 1
Serial Speed (Read 3206 times)
Serial Speed
Jul 25th, 2005, 7:10am
 
Hi
i'm trying to communicate to a Basic Stamp, and am having a number of issues in relation to speed. not sure if this is the right place to post this, or if it should be in the syntax discussion.  
Data is taking more than a second to send - causing my LEDs to have a very slow refresh rate. I am only sending 48 numbers, so this seems pretty slow.

One issue is the delay(2) that i need to put in, if i don't, that data comes out wrong on the other side, even with using handshaking. If i don't use handshaking, then i need to increase the delay even more.

Also, what is the maximum Baud that the Serial library can handle.  I have tried using a number of different baud rates, tried 50 000, but it won't work in Processing.

Here's the code, is there anyway to speed this up, or are there any other issues regarding serial i'm not aware of :
void writeSerial(){
row++;
if (row>7){
row=0;
}
if (row<0){
row=0;
}


for (matrix=5;matrix>-1;matrix--){
// println (matrix+"/"+row);
 delay(2);

 output = unbinary(picData[matrix][row]);
 print (picData[matrix][row]);
myPort.write("*");
myPort.write(output);

}
}

void draw() {
background(0);
while (myPort.available() > 0) {
dd=myPort.read();

 if (dd == 53){
writeSerial();
  print(dd+".");
 dd=0;
}
}

}


//////////////////////////////////

A bit about my project:
The pice consists of a phyicals installation of 6 LED screens, driven by Basic Stamps, connected via serial to Processing, as well as a number of webcams. Each screen features a tamagotchi-like animal, which users can interact with, via SMS. The webcams are used to track motion and send live webcam shots to the website. The graphical display part takes image data and converts it to binary, which then sends to  the BS to turn on and off the  LEDs. However, the ability of the screens to refresh fast enough, will make the diffrence between an ok installation and a great one. But I'm seriously running out time, so any advice would be apreciated.  I am exhibiting in 2 weeks time, at the Stills Gallery, dring the Edinburgh Festival.
Re: Serial Speed
Reply #1 - Jul 25th, 2005, 5:29pm
 
What is the software on the Basic Stamp doing when it receives the serial data?  Your Processing code waits for a request (character 53) from the Basic Stamp before sending each row of data, so if the Basic Stamp does a lot of work when it receives the data, it may send requests very infrequently, slowly down the code.  

Also, at what baud rate do you initialize the serial connection (both in Processing's new Serial() and on the Basic Stamp)?
Re: Serial Speed
Reply #2 - Jul 26th, 2005, 4:19am
 
The chr 53 is being used for a handshake, i found that without putting a pause in the Stamp couldn't keep up. It was an attempt to reduce the pause, or get rid of it all together. however, there was no significant speed changes using either way.

I've tried a number of baud rates and am currently using 38400. would like to go to 50 000 but Processing doesn't seem happy with that
Re: Serial Speed
Reply #3 - Jul 28th, 2005, 1:17am
 
we're using rxtx to handle serial, so any baud rates it supports will work in processing: http://rxtx.org
Re: Serial Speed
Reply #4 - Aug 1st, 2005, 5:11pm
 
thanks Fry. I looked around there and it seems you can either use 38400 or 57600. The BasicStamp uses a max of 50 000, so I would like to use something closer to that. Is it possible to use any others?
Re: Serial Speed
Reply #5 - Aug 1st, 2005, 7:33pm
 
If, as you said, the Basic Stamp can't keep up with the data it's getting from Processing, increasing the baud rate probably won't help you much.  You should look at Basic Stamp code and see what you can do to speed it up.  For example, can you offload any of the work onto dedicated (or more intelligent) LED display chips?
Re: Serial Speed
Reply #6 - Aug 2nd, 2005, 1:06pm
 
It's not just the Basic stamp, and that code is seriously minimal.
It seem the bottleneck is lying in processing and or my keyspan USB adaptor, which often fails/stalls because of the ammt of data going through. i've tried to clear the buffers after each serial write, but no luck.
Re: Serial Speed
Reply #7 - Aug 2nd, 2005, 7:00pm
 
One quick thing to try is commenting out all the print() and println() in the Processing code; they can slow things down.

Failing that, we need to figure out exactly what is slowing things down.  Where is your picData coming from?  What does your setup() function look like?  How can you tell that the bottleneck is in Processing or the USB adapter?  Is the Processing code doing anything besides sending data to the Basic Stamp?

Try profiling your code to see how much time each part takes.  An easy way is putting (replace MESSAGE with an indication of where you are in the code):
 println(millis() + ": MESSAGE");
in various key spots (e.g. the start and end of writeSerial()).  How long does writeSerial() take to run?  How long are the pauses between calls to it?

Try sending data to the basic stamp with something other than Processing.  Or try sending data to a simpler Basic Stamp program, which does nothing but wait for the right amount of input and then reply with a handshake.  Or try sending data to something else (e.g. another computer or a Wiring board).
Page Index Toggle Pages: 1