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 & HelpSyntax Questions › Canvas Flickers when trying to graph serial input
Page Index Toggle Pages: 1
Canvas Flickers when trying to graph serial input (Read 624 times)
Canvas Flickers when trying to graph serial input
Aug 30th, 2009, 7:15pm
 
I'm trying to graph some data that's gathered from an Arduino board,
but I keep having trouble with screen flicker while graphing. This only seems to happen when I'm trying to draw other shapes or text to the canvas while graphing. I have tried drawing the data to a Pgraphics object and then displaying the Pgraphic object on the canvas, but I'm not sure I'm doing these things in the correct order.

The pseudocode for my first try was:

void setup()
{
do typical setup stuff and make a Pgraphics object
}

void draw()
{
Draw static shapes and text
}

void serialEvent(Serial ComPort)
{
-read serial data from arduino
-add data to an array
-graph array data on Pgraphics object
-display Pgraphics object in specific place on canvas
}


This made the graph flicker, but the static objects did not flicker.
The next try made the whole canvas flicker like mad:

void setup()
{
do typical setup stuff and make a Pgraphics object
}

void draw()
{
-set background color
}

void serialEvent(Serial ComPort)
{
-read serial data from arduino
-add data to an array
-graph array data on Pgraphics object
-draw static graphics and text (not in Pgraphics object)
-display Pgraphics object in specific place on canvas
}


I'm about to try a few more combinations of canvas drawing and Pgraphics drawing, but I'm hoping someone can shed some light on the root cause of the flickering overall.
Some specific questions I have are:
- Should I be using serialEvent(Serial ComPort) to handle the
data capture, or is there a better way?
- When using a PGraphics object, does using P2D vs. P3D make a difference?
- Note, I have tried writing -all- the graphics to a PGraphics object, but it seems impossible to write text to a PGraphics object - I have tried everything I can think of to write text to a PGrpahic, but I get error after error. Anyone else out there have any experience trying to do this?
- Also note, the PGraphics object that I'm writing to and displaying is much smaller than the main canvas, so I don't think the flicker is caused by overlapping of the static graphics and the graph.
Re: Canvas Flickers when trying to graph serial input
Reply #1 - Aug 30th, 2009, 7:39pm
 
everything you draw should happen in draw. Use your serielEvent only for updating your variables/data. SerialEvent is called everytime you receive new data, that doesnt happen on every frame. Thats why you get that flickering.

so for your first example try to move

"-display Pgraphics object in specific place on canvas"
to draw(){
Re: Canvas Flickers when trying to graph serial input
Reply #2 - Aug 30th, 2009, 7:47pm
 
Thanks Cedric, problem solved! <facepalm>...seems so obvious now...
Page Index Toggle Pages: 1