Compiler Errors with Graph Example under Communication

i understand what the errors are, but don't know how to correct the errors. I'm in the Arduino 1.0 environment using a pre-made example out of the Communication tab called Graph. Here are my errors and code. Thanks.

Graph:53: error: variable or field 'serialEvent' declared void
Graph:53: error: expected `)' before 'myPort'
Graph:54: error: 'import' does not name a type
Graph:56: error: 'Serial' does not name a type
Graph.cpp: In function 'void setup()':
Graph:62: error: 'size' was not declared in this scope
Graph:65: error: 'class HardwareSerial' has no member named 'list'
Graph:65: error: 'println' was not declared in this scope
Graph:69: error: 'myPort' was not declared in this scope
Graph:69: error: expected type-specifier before 'Serial'
Graph:69: error: expected `;' before 'Serial'
Graph:73: error: 'background' was not declared in this scope
Graph.cpp: At global scope:
Graph:85: error: variable or field 'serialEvent' declared void
Graph:85: error: expected `)' before 'myPort'
/*
  Graph
 
 A simple example of communication from the Arduino board to the computer:
 the value of analog input 0 is sent out the serial port.  We call this "serial"
 communication because the connection appears to both the Arduino and the
 computer as a serial port, even though it may actually use
 a USB cable. Bytes are sent one after another (serially) from the Arduino
 to the computer.
 
 You can use the Arduino serial monitor to view the sent data, or it can
 be read by Processing, PD, Max/MSP, or any other program capable of reading 
 data from a serial port.  The Processing code below graphs the data received 
 so you can see the value of the analog input changing over time.
 
 The circuit:
 Any analog input sensor is attached to analog in pin 0.
  
 created 2006
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe and Scott Fitzgerald
 
 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Graph
 */
/*
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
}

void loop() {
  // send the value of analog input 0:
  Serial.println(analogRead(A0));
  // wait a bit for the analog-to-digital converter 
  // to stabilize after the last reading:
  delay(10);
}
*/

 // ******************************************************************************
 // Graphing sketch
  
 // This program takes ASCII-encoded strings
 // from the serial port at 9600 baud and graphs them. It expects values in the
 // range 0 to 1023, followed by a newline, or newline and carriage return
 
 // Created 20 Apr 2005
 // Updated 18 Jan 2008
 // by Tom Igoe
 // This example code is in the public domain.
 
 import processing.serial.*;
 
 Serial myPort;        // The serial port
 int xPos = 1;         // horizontal position of the graph
 
 //********************************************************************
 void setup () {
 // set the window size:
 size(400, 300);        
 
 // List all the available serial ports
 println(Serial.list());
 // I know that the first port in the serial list on my mac
 // is always my  Arduino, so I open Serial.list()[0].
 // Open whatever port is the one you're using.
 myPort = new Serial(this, Serial.list()[1], 9600);
 // don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 // set inital background:
 background(0);
 }
 
/*
 //*************************************************************************
 void draw () {
 // everything happens in the serialEvent()
 }
 */
 
 
 //*************************************************************************
 void serialEvent (Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');
 
 if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // convert to an int and map to the screen height:
 float inByte = float(inString); 
 inByte = map(inByte, 0, 1023, 0, height);
 
 // draw the line:
 stroke(127,34,255);
 line(xPos, height, xPos, height - inByte);
 
 // at the edge of the screen, go back to the beginning:
 if (xPos >= width) {
 xPos = 0;
 background(0); 
 } 
 else {
 // increment the horizontal position:
 xPos++;
 }
 }
 }

Looks like you are trying to compile the Processing code with Arduino. The version in my copy of File->Examples->Communication->Graph has the Processing code commented out and the Arduino code NOT commented out.

i did notice that and even ran the code using Processing.exe. Maybe I can go back to that environment and fix it. However, the code not commented out that compiles in Arduino 1.0 environment uses the Serial Monitor and shows decimal 0-1023 by adjusting the potentiometer. It doesn't graph, which is what I want to do.

Also, I tried to find this graph example in Processing 1.5.1 but no luck. why would it be an example in Arduino, but then want stuff from Processing? i guess i will cut and paste the code over in Processing, but this just doesn't make much sense.

Ok, I just tried in Processing. I commented out the first setup() and loop() so i could use the second setup() and SerialEvent(). I also commented out the draw() because it isn't used. However, now I'm getting a NullPointerException when the graph window pops on the screen. any ideas why?

I also commented out the draw() because it isn't used.

Used or not, it is a required function.

However, now I'm getting a NullPointerException when the graph window pops on the screen. any ideas why?

There is a whole stack trace printed. Might not mean anything to you, but I'm guessing that it will to someone with more experience.

That isn't the same example my Arduino-1.0 has in it.

After the void loop() {} section there is a comment that says:

 /* Processing code for this example

That entire section of code is commented out...

that's kind of funny to me. why would the Arduino 1.0 environment have a pre-made example that you'd need to carry the code over to Processing 1.5.1. environment. Ok, it seems to me that Processing would be able to make the graph, but Arduino would not. I say that because the examples are 'display' oriented in Processing environment, where as in Arduino it's all hardware functionality and reading data (numeric) value input using the Serial Monitor. what are your thoughts. Can I graph in Arduino 1.0? I don't believe so.

what are your thoughts.

What is the point of your polls? :roll_eyes:

Can I graph in Arduino 1.0? I don't believe so.

Probably yes, but you need a way to display the graphs that are made by the arduino. Graphs are just visual displays that represent some type of data. The arduino can generate the data, but obviously it by itself has no visual display mechanism (at least mine doesn't).

encryptor:
that's kind of funny to me. why would the Arduino 1.0 environment have a pre-made example that you'd need to carry the code over to Processing 1.5.1. environment.

Because the first part of the example is Arduino code, the 2nd part is Processing code.

Why is that so funny?

i said kind of funny, not so funny...but because there wasn't anything made clear to say take this code over to the Processing environment. I was left guessing as a newbie.