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
Running out of memory (Read 1335 times)
Running out of memory
Jan 14th, 2010, 6:57am
 
Hi, I've set up a serial link between Arduino & Processing, moving a webcam feed around the screen using the input from two potentiometers - I've got the code to work, but it keeps running out of memory within ten seconds. I'm not really sure what's causing the problem? Could it be on the webcam side of the program?

Here's my code:
Code:
import processing.opengl.*;     // import the Processing opengl library
import processing.video.*; // import theProcessing video library
import processing.serial.*; // import the Processing serial library
Serial Arduino; // The serial port
Capture webCam; // The webcam feed

float xpos, ypos; // Starting position of the webcam feed

void setup() {
size(640,480,OPENGL);

// List all the available serial ports & cameras
println(Serial.list());
println(Capture.list());

webCam = new Capture(this, width/2, height/2, "USB PC Camera-WDM", 30);
Arduino = new Serial(this, Serial.list()[1], 9600);

// read bytes into a buffer until you get a linefeed (ASCII 10):
Arduino.bufferUntil('\n');

noStroke();
}

void captureEvent(Capture webCam){

webCam.read();
}

void draw() {
background(153, 153, 0);
image(webCam, xpos, ypos);

}

void serialEvent(Serial Arduino) {
// read the serial buffer:
String myString = Arduino.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (myString != null) {

myString = trim(myString);

// split the string at the commas
// and convert the sections into integers:
int sensor[] = int(split(myString, ','));

// print out the values you got:
for (int sensorNum = 0; sensorNum < sensor.length; sensorNum++) {
print("sensor " + sensorNum + ": " + sensor[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensor.length > 1) {
xpos = map(sensor[0], 0,width,0,width);
ypos = map(sensor[1], 0,height,0,height);

}
}
}


Any pointers would be great!
Re: Running out of memory
Reply #1 - Feb 2nd, 2010, 7:52am
 
I think you should double check the ports Smiley Smiley
Page Index Toggle Pages: 1