Instructables

Arduino to Processing: Serial Communication without Firmata

Picture of 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.
 
Remove these adsRemove these ads by Signing Up

Step 1: Upload Arduino Sketch to Your Microcontroller

Picture of 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.  
aberoukh6 months ago

Works great. Thanks!