Go Down

Topic: Arduino + Processing for Graphing (Read 2094 times) previous topic - next topic


I tried the following:


I put the arduino sketch in the same folder/directory as the processing sketch so when I verify the arduino sketch I get an error:

variable or field 'serialEvent' declared void.

So what am I doing wrong?


I forgot to post the code:


Code: [Select]
void setup() {
  // initialize the serial communication:

void loop() {
  // send the value of analog input 0:
  // wait a bit for the analog-to-digital converter
  // to stabilize after the last reading:

Processing code:

Code: [Select]

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
   // 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()[2], 9600);
   // don't generate a serialEvent() unless you get a newline character:
   // set inital background:

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:
     line(xPos, height, xPos, height - inByte);
     // at the edge of the screen, go back to the beginning:
     if (xPos >= width) {
       xPos = 0;
     } else {
       // increment the horizontal position:


So what am I doing wrong?

You answered your own question:
I put the arduino sketch in the same folder/directory as the processing sketch

Don't do that. Separate applications == separate folders.
The art of getting good answers lies in asking good questions.


Thank you PaulS, that fixed my problem and it works. It was a little fast so I slowed it down by making it a 20 mS delay instead to the 2 mS delay they had - thanks again PaulS

Go Up