Home‎ > ‎Unit 05‎ > ‎

Arduino Library

Now that your Arduino board is ready to go you need to add the Arduino Library to Processing. Libraries add functionality to programing languages. Basically they include code that people have found very useful and wanted to use repeatedly. By putting this code in a library it becomes very easy to add it to new programs as needed without having to type it all in again or even copy and paste.

You can get the Arduino Library from: http://arduino.cc/playground/uploads/Interfacing/processing-arduino-0017.zip 

Unzip the library and copy the "arduino" folder into the "libraries" sub-folder of your Processing Sketchbook. You can find the location of your Sketchbook by opening the Processing Preferences. You'll need to create a new folder named "libraries" all lowercase in your Sketchbook folder (complete details in the video below).

Next you'll need to identify the Serial Port you are using. The Arduinos we are using plug in via a usb cable but the computer through the usb port that acts like a serial port.

To find your port number paste this code into a new Processing sketch and run it. (code adapted from physcomp/Labs/SerialOut)
import processing.serial.*; 

Serial myPort;            // The serial port 

void setup () 

 size(400, 300);          // window size 
 println(Serial.list());  // List all the available serial ports 

The picture to the right shows what I see on my WinXP desktop. I have two serial ports, COM1 and COM6. My Arduino is in COM6 (i.e. the same port I selected in the Arduino interface). You can run the same code on a Mac (and I assume Linux). Then simply look for the same port you used in Arduino. Put the appropriate number in your brackets whenever you use Processing with your Arduino. Note, if you plug the Arduino into a different USB port  in WinXP you may end up with a different COM port as well (so, you'd need to run the above Sketch again).

Once you've identified the proper port number note it down. You'll need it later. You'll end up putting it in a line of code that looks something like:

arduino = new Arduino(this, Arduino.list()[1], 57600);

The number in the square brackets is your port number. On my computer it is 1.

Once you've figured out which port number to use open the arduino_input sketch in Processing. Look in the void setup for the arduino line and put in your port number. The default is Arduino.list()[0] Change the zero to your port (if necessary). The run the sketch and poke at the pins on the back of the arduino board.

See video below for full details