Introduction to Open Accessory Framework
Using Android and Arduino together
At Google IO 2011 they announced a interesting framework as a iOS developer I always wanted to be able to interface with circuits using my phone. they announced the open accessory framework allowing you to interact with Ardiuno and other microcontroller platforms.
The potential for this is amazing. augmenting a phone (which has cameras, gps, cellular data connection,wifi) with hardware such as motors, relays, leds , and exotic sensors. have many artistic possibilities.
Approaching this from a non computer science-y way lets jump straight in to making and worry about programming our own app from scratch later.
We are going to work off the example code given to us in Spanish by Alex TC
Things you will need:
- Android device with 2.3.4 +
- Arduino based microcontroller (if you already have a uno or dumevello you need a usb host) or buying new official adk mega (awesome but $$$), freetronicsUSBDroid (less pins but less $$)
- Breadboard and Jumper cables
- your Androids charging cable
- RGB led (or 3 led’s)
- Light sensor
for this example i’m using a Dumevello which has less inputs and outputs than the mega, but is cheaper and more easily replicated
into a home made board if you want at a later point.
So install eclipse and once you’ve done that its time to add the Android Developer Tools (ADT) and the Android SDK
open elclipse. in the menu bar go help > install new software
A new window will open and go to the top right and select add
enter “ADT Plugin” for the Name and insert the url https://dl-ssl.google.com/android/eclipse/ for the “location” Click OK In the Available Software dialog, select the checkbox next to Developer Tools and click Next.In the next window, you’ll see a list of the tools to be downloaded. Click Next.scroll through the license agreements, then click Finish. now close then re open eclipse.
now we need to set up the ADT preferences so that it knows where the SDK is.
firstly go to your downloads folder and find the sdk unzip it and move the folder to a safer place like Documents.
Go to Eclipse > Preferences).
Select Android from the left panel.
now it will ask for the SDK Location in the main panel, click Browse… and navigate to the SDK folder then. click apply then ok.
Now go to the menu bar again and select Window > Android SDK and AVD Manager.
check that the you have the sdk level 10 developer tools selected (or in the future android 4.0)
oookkkayyy so now eclipse is set up nicely. now we need to actually deal with code.
the example code is called demokit its in this ADK release download then unzip
file > new Project > android project
select new project from a existing source and link it to the “app” folder in the ADK release
give it a name and then click next and select google api’s 10.
and then finish.
all the code should now be in the projects pane on the left of the ide.
To enable running apps on your phone from eclipse on your device: Settings > Application Settings > Development. and tick USB Debugging
when its plugged in the usb port it should state USB Debugging mode and have a cute computer chip like Android logo up the top left on the phone.
after this is done push run in eclipse and select your phone.
Setting up the arduino.
Place the usb host on top of the Arduino (the pins should match up to the holes) the power requirements of the system is somewhat demanding compared to a normal (if there is such a thing) Arduino circuit, due to having to provide power (5v 0.5amp) for the phone you have to provide greater than 5v to the vin pin
4x rechargeable AA’s in series is my favorite portable method that works so far, a 9V battery or a plug in a transformer 7-9v highly recomended.
So to start we are just going to have the RGB led control and the LDR as input.
its a nice clean easy circuit to breadboard and easy to check that everything is working.
upload the modified demokit sketch and upload to the arduino then your ready to plug it all in!
right click on your arduino app an select “show package contents”
resources> libraries leave this window open and find your adk download again and navigate to firmware > arduino libs copy the contents to the libaries folder.
Arduino code: download modified demokit to work on atmega 128, unzip and open the .pde in arduino and upload to board.
now when you plug the phone into the usb host the app should auto launch. and you can see the light reading and control led 1.