Graphing using serial monitor

I am working with an example sketch called Graph which is in the Learning section of the Arduino Home Site. I get a consistent error "variable or field 'serialEvent' declared void" when I attempt to compile the code. I'm not sure I'm using the code correctly, as it's printed as an adendum to the code which presents the input as a series of decimal values. Can someone offer some suggestions?

Serial_Graph_Processing.pde (766 Bytes)

This bit of code should be in the arduino and down loaded into an arduino board

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

And the rest of it should be loaded in Processing.

Where are you trying to compile and link that? It is a combination of Processing code and Arduino code that you need to split into two files - one to compile and link in the Arduino IDE and upload the the Arduino, and the other to compile, link, and run using Processing.

I have compiled and uploaded the first part of the sketch using Arduino, and it is running. When I enter the processing code (using Processing), I get the error
Error inside Serial.0
and it fails to compile correctly.

I tried it. It compiled and ran just fine. Post the code in a reply, not as an attachment, using the # button, and the EXACT error message.

If you wanted to have somewhat of a graph on the serial monitor, you might map the analog input to something like 32 points. Make a Serial.print(); loop printing a * for the number from the maping and end with a Serial.println();. Make the main loop loop every second reading the input and then printing the appropriate number of *. This should produce some what a verticle scrolling graph updaing each second.

Here is the code as I entered it. The error is

"Error inside Serial.()" The line that begins myPort = new Serial(list,........ is highlighted.

import processing.serial.*;

Serial myPort;
int xPos = 1;

void setup () {
size(400, 300);
println(Serial.list());

myPort = new Serial(this,Serial.list()[0],9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}

void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
xPos++;
}
}
}

That compiles and runs for me, on Win7 64 bit, using Processing 1.2.1. What OS are you using? What version of Processing?

I am using win 7, Processing 1.5.1.
Here is what I am doing:
I start Arduino, load compile and upload the Arduino segment

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

Next, using Processing, I load and attempt to compile the processing segment. This is where I get the error message.
I don't understand what's going on here.

It looks like the library you are using is not compatable with your version of processing. You can get older versions of processing so try downgrading it.

I don't understand what's going on here.

I downloaded 1.5.1, and that sketch compiles fine with that version. I don't know what your problem is, either.

I don't know what your problem is, either.

Me too, but what ever it is it is not an Arduino problem, so best ask in the Processing forum.

I don't understand what that code is doing. What is 'this' within the context of setup()?

'this' is part of the Processing language, and that is part of my problem. I'm not sure I'm using this correctly. I have posted this question on the Processing Forum.

jstanton:
'this' is part of the Processing language, and that is part of my problem. I'm not sure I'm using this correctly. I have posted this question on the Processing Forum.

I understand what the 'this' keyword means, but I don't understand what you intend it to mean within the context of the setup() function. 'this' is defined when you call a function of an object; it points to the object. But setup() is not a function of an object, it is a static function. What do you think 'this' means in that context?

The code is proper Processing code. The setup() function is static, true, but there is an object that this refers to that the Serial class needs in order to do its thing.