/*Serial Communication: A serial port is a serial communication physical interface through which information transfers in or out one bit at a time (digital pulses one after another back and forth) between computers. This program reads a string of characters from a serial port you define. Converts the strings into integers and prints. */ import processing.serial.*; //import processing library int linefeed = 10; Serial myPort; //the serial port void setup() { println(Serial.list()); //list all available serial ports //plug in the serial port number that is attached to Arduino myPort = new Serial(this, Serial.list()[0], 9600); //Mac USB is 0 //read bytes into a buffer until linefeed (ASCII 10) myPort.bufferUntil(linefeed); } void draw() { } void serialEvent(Serial myPort) { //read serial buffer String myString = myPort.readStringUntil(linefeed); //if you have any bytes other than linefeed if (myString != null) { myString = trim(myString); //convert sensor values into integers - set up for multiple sensors int sensors[] = int(split(myString, ',')); //print out the values from the variable sensor for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); } //add a linefeed after all the sensor values are printed println(); } }