Go Down

Topic: Arduino-Processing Problem (Read 1 time) previous topic - next topic

SuperSparkplug

So, I'm using a book on AR and it explains how to connect Arduino to Processing in order to make an AR application that involves a pressure sensor. However, when I ran the processing code through I got an error on "cam.play();" saying that the function play() does not exist. If I remove this line, the program runs but immediately crashes and produces an error saying "Error inside Serial.<init>0." This has baffled me for the past few hours. Can someone please figure this out. I need this for a project that's due soon.

Here's my Arduino code. This works

void setup() {
 Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(A0));
}

Here's my processing code. This has a problem.

import codeanticode.gsvideo.*;
import jp.nyatla.nyar4psg.*;
import processing.serial.*;

Serial myPort;
GSCapture cam;
NyARMultiBoard nya;
PFont font;

String inString = null;
float low = 3.0;
float high = 32.0;
float weight;

void setup() {
size(640,480,P3D);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
font = loadFont("crystal-lightning-64.vlw");
cam=new GSCapture(this,width,height);
cam.play();

String[] patts = {"scale16.pat"};
double[] widths = {80};
nya=new NyARMultiBoard(this, width, height, "camera_para.dat", patts, widths);
print(nya.VERSION);
nya.gsThreshold=120;
nya.cfThreshold=0.4;
}

void draw(){

 if (cam.available() !=true) {
 return;
}
cam.read();
hint(DISABLE_DEPTH_TEST);
image(cam,0,0);
hint(ENABLE_DEPTH_TEST);
if(nya.detect(cam)){
 if (nya.markers[0].detected){
   nya.markers[0].beginTransform();
     textFont(font,25.0);
     textAlign(CENTER);
     fill(50,255,0);
     translate(0,50,80);
     rotateX(radians(180));
     rotateX(radians(90));
       text(weight,0,0,0);
     nya.markers[0].endTransform();
   }
 }
}
void serialEvent  (Serial myPort) {
 inString = myPort.readStringUntil('\n');
 if (inString != null) {
   inString = trim(inString);
   float val = float(inString);
   weight = 100+((val-low)*(100/(high-low)));
 }
}

PaulS

Code: [Select]
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);

The first line lists the serial ports that are available. Is your Arduino really at the second item in the list?

Go Up