Controlling Arduino with Android using Processing

 

IMPORTANT NOTE:
These examples are optimized for Processing version 2.0.3a. Since Processing was heavily rebuilt at version 2.0.6a, these examples are no longer compatible with the latest releases. The good news is that the rebuilt software is significantly easier to work with. The latest official instructions for Processing+Android are available here.

We will continue to host these examples, as we feel that they are valuable for the community as inspiration, building blocks and for future reference. Feel free to take these examples and update them to the latest procedure- if you share with us, we’ll link to them from here.

2

There are 3 main steps to this process:

1.  Install the Android SDK
2.  Install Processing and launch it on your Android
3.  Install the Arduino software

*Note:  If you’re already set up to with the software, you can skip ahead and download our sample sketches.

Part 1:  Install the Android SDK

You can get the Android SDK and installation instructions from the Android Development website:

Instructions:  http://developer.android.com/sdk/installing.html
Windows Download:  http://dl.google.com/android/installer_r16-windows.exe
Mac OS X Download:  http://dl.google.com/android/android-sdk_r16-macosx.zip

Note:  You may skip their step 3 of the installation guide.  Step 4 can be time consuming, as you need to include multiple APIs for Google (at least version 8; however note that the APIs do not include one another and must each be installed separately.  In other words, if you install 10, don’t expect 8 to be automatically included).

Here is an image of the packages I have installed:

Screen Shot 2012-03-01 at 12.22.33 PM

Part 2:  Install Processing

*Note that Processing Version 2.0.3 or newer is required to create Android applications.

1.  Download and Install Processing (2.0.4)
(These steps are based on this wiki: http://wiki.processing.org/w/Android check there for the latest version)

Mac OS X http://processing.googlecode.com/files/processing-2.0a4-macosx.zip
Windows http://processing.googlecode.com/files/processing-2.0a4-windows.zip
Windows (no java) http://processing.googlecode.com/files/processing-2.0a4-windows-expert.zip

2.  Install Libraries and Tools

Once Processing is installed, you will need to install specific tools and libraries to enable processing to work with the ADK board. Download and unzip the following file:

http://sandbox.tellart.net/apa/Processing.zip

Inside the unzipped file are 2 folders,  “Libraries”, and “Tools.

Inside the Libraries folder are 2 processing libraries named ArduinoAdkUsb and controlP5. Both of these need to be placed into your Processing libraries folder:

Mac: /Users/*username*/Documents/Processing/Libraries
Win: My Documents → Processing/Libraries
*Note:  If the libraries folder does not already exist, create it, then place the libraries into it.

In the Tools folder is a toolkit named “Arduino_ADK”. This toolkit needs to be placed in your processing tools folder:

Mac: /Users/*username*/Documents/Processing/Libraries
Win: My Documents → Processing/Libraries
*Note:  If the tools folder does not already exist, create it, then place the toolkit into it.

Screen Shot 2012-02-28 at 3.36.11 PM

3.  Connect Processing to the Android ADK

Now that Processing and the Arduino ADK have been installed, we need to connect them together.

Open Processing. In the top right hand corner of the window, you will see a box that says “Standard”.  Click on this and select “Android” as shown below:

Screen Shot 2012-02-28 at 3.37.28 PM

Doing this will popup a window asking if the SDK is installed. Click “Yes.”

Screen Shot 2012-02-28 at 3.38.13 PM

Select the location of the Android SDK installation, and click “Choose.

Screen Shot 2012-02-28 at 3.39.15 PM

Your Processing window should have now changed colors from a blue to a green background, like this:

Screen Shot 2012-02-28 at 3.39.57 PM

Great work!  The Arduino SDK and Processing are now connected, and you can begin developing applications for use on your Android.

Part 3:  Install Arduino

Note:  This process requires Arduino software version 1.0 or greater.

(These steps are based on this wiki: http://wiki.processing.org/w/Android please check there for the latest version.)

1.  Download and install the Arduino 1.0.

Mac http://arduino.googlecode.com/files/arduino-1.0-macosx.zip
Win http://arduino.googlecode.com/files/arduino-1.0-windows.zip

Windows only note: In order to get working the board needs a .inf file:

http://arduino.cc/en/uploads/Main/Arduino_ADK.zip

1.  Plug in your board and wait for Windows to begin it’s driver installation process.  After a few moments, the process will fail, despite its best efforts
2.  Click on the Start Menu, and open up the Control Panel.
3.  While in the Control Panel, navigate to System and Security. Next, click on System. Once the System window is up, open the Device Manager.
4.  Look under Ports (COM & LPT).  You should see an open port named “Arduino UNO (COMxx)”
5.  Right click on the “Arduino Mega (COmxx)” port and choose the “Update Driver Software” option.
6.  Next, choose the “Browse my computer for Driver software” option.
7.  Finally, navigate to and select the driver file, named “Arduino MEGA ADK.inf” that we downloaded and unzipped above.

Windows will finish up the driver installation from there.

2.  Install Libraries

Once the Arduino software is installed, you will need to install two libraries to enable communication with the ADK’s usb-connector to work with the ADK board. Download and unzip the following file.

http://sandbox.tellart.net/apa/Arduino.zip

Inside the libraries folder you will find two Arduino libraries, named AndroidAccessory and USB_Host_Shield. Both of these need to be placed in the Arduino libraries folder:

Mac: /Users/username/Documents/Arduino/libraries
Win: My Documents → Arduino/libraries
If the Libraries folder does not already exist, you may create it

Once those are moved into the right folders, installation is complete.  You should double check that everything has gone as planned.

Now the fun part: Try it out

Download our example sketches at the following link:

http://sandbox.tellart.net/apa/Tellart-Android-Processing-Examples.zip

We are going to test this with the RGB sketch, which will control the background color of your Android device using three potentiometers connected to the Arduino.  Think of them as volume knobs, where each controls one of the RGB values.

On the Arduino:
1.  First, start up the Arduino software.
2.  Plugin in the ADK board
3.  Under Tools > Board, Select the “Mega 2560 or Mega ADK”
4.  Under Tools > Serial Port, select the correct serial port for your Arduino (if you dont know which one to select, make a mental note of which ports are available in the list, then unplug the Mega ADK from the USB.  When you check the Serial Port list again, you will see which one has disappeared. That is your serial port, and it should reappear once you plug it in again)
5.  Open the RGB example from the folder “Android_Proccesing_Arduino_Examples.” Inside you will find two folders.  One, named RGB_Arduino, contains the Arduino code.  The other, RGB_Processing, contains the Processing code.  There is also an image of the connection.
6.  Open the RGB_Arduino.ino file (from the RGB_Arduino folder) with the Arduino software. It should look like this:

Screen Shot 2012-03-01 at 12.38.33 PM

7.  Press the Verify button ( Screen Shot 2012-03-01 at 12.39.34 PM ) to make sure everything is correct.  If so, press Upload ( Screen Shot 2012-03-01 at 12.39.41 PM ) to load it onto your Arduino.

8.  If your upload completes, without any errors, you have finished with the Arduino part.

In Processing:

1.  Make sure that the Android device is in USB debugging mode. This is usually found in the Settings/Applications/Development menu, but might be different depending on your Android version.
2.  Connect the Android device to the computer
3.  Open the Processing software
4.  Open the example RGB_processing from the folder Android_Proccesing_Arduino_Examples/RGB
5.  Make sure you are in Android mode
6.  Use the Arduino tool you installed previously by pressing “Tools/Arduino ADK.”
This brings up this dialog:

Screen Shot 2012-03-01 at 12.46.31 PM

7.  Press “Run on Device.”  This should launch the application on the Android device and start it up right away.
8.  Once it is running on the device, you should see a small red circle in the top left. This means that it is not connected. Quit the application on the Android device and disconnect it from the computer, and connect it directly to the ADK board.
9.  Launch the application again and this time the circle in the top left should be green, which means you have established a connection and everything is communicating properly.
10.  Done! Spin the potentiometers and the background should change color accordingly.

Next steps

Now that all the pieces of the puzzle are set up, we can get to the fun part of exploring the tools. In the files you downloaded, there is a set of examples which each include a Processing sketch, an Arduino sketch and a schematic on how to connect the sensor/actuator just like the RGB one.  Use these as the building blocks to start developing and exploring your own ideas.

When developing your ideas we recommend a five step process:
1.  When you develop the code for the Arduino, make sure all the sensors and actuators work by sending commands from the Serial Monitor in the Arduino software.
2.  When you develop the code for the Processing, make sure it works on the computer by using the mouse as a replacement for the Arduino.
3.  Test your Processing code on the Android device to make sure it behaves as expected.
4.  Connect the Processing code with the Arduino code.

5. Explore, enjoy, iterate!