Introduction: Arduino to Processing: Serial Communication Without Firmata
This Instructable is intended for anyone to directly send input values read by Arduino to Processing. It is best used for passing one to several values, such as a few buttons, a joystick, or accelerometer. For mass I/O control in Processing, it is probably best to use Firmata.
This sketch assumes that you have some kind of input device (like a button) hooked up to your Arduino on an Analog Input. To get things up and running quickly, hook up two buttons to Analog Inputs 0 and 1 so you can use the attached sketches as is.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Upload Arduino Sketch to Your Microcontroller
To begin, make sure Processing is closed, and then open the attached Arduino sketch. Essentially, this Arduino sketch reads the incoming values on the analog ports and then uses Serial Communication functions to output the values. The values are separated by comma characters (denoted by quotation marks) which will be used to parse, or separate the values. Processing will do this work.
While the sketch is excessively commented, take note of the argument to the Serial.begin() function: this is the baud rate - in other words, the number of "signaling events per second." This can be modified according to your project specifications, but make sure that the rate is the same in the simultaneous Processing sketch (in my examples, the default is 9600).
If you are not familiar with the second argument of the Serial.print() function, note that this is the base (or format) of the first argument - in this case, DEC stands for "decimal" or a base 10.
Step 2: Run the Processing Sketch
Now, leaving your Arduino program running, and the mircocontroller plugged in via USB (enabling the Serial Communication), open the attached Processing Program.
NOTE: At this point, if you have not used the Serial library in Processing, the program may prompt you in the Debug Window (see image) to open your Terminal and run two SUDO commands. This can be dangerous, but if you follow the exact instructions in the Processing debug window, no harm will come to your computer.
The attached Processing sketch is intended to explain the complex aspects so it will be useful for anyone. Aside from the essential terminal commands, the only function that may need modification is the initialization of a new Serial object (line 20 in the sketch):
port = new Serial(this, Serial.list(), 9600);
This creates a new object (which is an instance of a class - the fundamental building-block of OOP, or "Object Oriented Programming"). The second argument of the Serial.list() function is the incoming port being used by your Arduino. Most users can probably use the default  port, but this may need to be changed if you are using a different port. The third argument is the baud rate which must match the baud rate used in the Serial.begin() function of your Arduino sketch.
When you are finished modifying the sketch (if it needs it), run the program with the Play button and read the values in Processing's Debug Window. These values, which are stored in the cells of your array, can now be used in Processing sketches.