Skip navigation

… Arduino and Processing Communication

Bill Graner originally wrote the code used for this part of the prototype. It can be viewed and download from the following link.
The communication is from Arduino to Processing. The Arduino code is very simple. It manages the switches placed in the floor. The code itself only turns on the LED light in the Arduino. The communication is done by sending the value of each switch from Arduino to Processing. For this example only one switch is used and it has declared the integer val as its value. They are sent to Processing via the serial port. Within the Processing sketch the communication is opened using the following line of code:
The serial must match in both sketches. In this case its 9600. In Arduino the port is established the following way:
The values from Arduino are read in Processing as a sequence of characters (string). The values from Arduino are the following:
We are using one switch but if more switches are needed the code could look like this:
These values are stored within Processing as an array that is called data_list in this particular example. Using the split function the string is broken in pieces. That is why commas separate the values from Arduino. More precisely the Serial.print(“,”); line is what separates the values from each other. The array data_list is managed the following way using the following line of code:
This part is important because the split function allows the string to be converted into a float or int array if the result is a set of numbers (like in our case).
For the main part of the installation we used the switch (case) structure, but for simpler parts like the sound of door opening we used this approach. Also the first experiments used with this code were using arrays. Declaring data_list as an array allows placing actions within.
The values from Arduino managed as a sequence of characters tells Processing each time a switch is pressed. For example switch 1 corresponds to val. When switch 1 is pressed val is sent to Processing. This value is placed inside data_list, which was previously declared as an array. To manage what happens when the switch is pressed an if statement is written. In the following example when the switch is pressed a new sound will play and it will increase the volume.
The value of the array is established by looking at the console area of Processing when a switch is pressed. It’s important that the switch is functioning in Arduino and has a function within the Arduino code. Otherwise it won’t send information to Processing.
This particular form of communication between Arduino and Processing was helpful for us because it allowed adding actions to the Processing sketch. There are other ways to establish communication but the main reason was the flexibility of this code.

Routes | Concept | Experience | Prototype | Technology | Code | Early Experiments |
Critical Reflection | Downloads | Credits