Introduction
This tutorial deals with installing the Arduino IDE onto the PC and ensuring that we can compile a program. We are following the “Installing the Arduino software and necessary libraries” section on this web page
Accessory Development Kit 2011 Guide | Android Developers
Download and install the Arduino IDE
We need three downloads. The following instructions assume a Windows installation as if you are using Basic4android you must have access to Windows in order to run the IDE.
The Arduino IDE itself, currently version 1.0.4, is available here. You do NOT want the 1.5 beta.
Arduino - Software
Extract the arduino-1.0.4 folder and place it somewhere convenient but NOT in Program Files or any other protected folder. If you get a security dialog when trying to run it right click arduino.exe, select Properties and click the Unblock button on the General tab.
The Accessory Development Kit package contains the necessary Arduino libraries and the demo program which we will use to demonstrate that the IDE will compile correctly but will not actually use on the Arduino.
https://dl-ssl.google.com/android/adk/adk_release_20120606.zip
Extract and copy the “AndroidAccessory USB” and “Host_Shield” folders from the “arduino_libs” folder in the archive (the complete folders, not just the files within) to the “libraries” folder in the Arduino IDE installation folder.
A further library which the demo program that we will compile uses.
Arduino Playground - CapacitiveSensor
Extract and copy the “CapacitiveSensor” directory and its contents to the “libraries” folder in the Arduino IDE installation folder. Note that the instructions in the “Installing the Arduino software and necessary libraries” section of the ADk web page are wrong as the name of this library has changed. Because of this we will also have to edit the Arduino demo source to get it to compile.
There is an alternative location for extra libraries under your personal Documents folder should you for some reason want to restrict their use by other users of your computer.
Arduino - Libraries
Configure the IDE
Run the IDE by double-clicking arduino.exe. Under Tools -> Board select “Arduino Mega 2560 or ADK”.
If, like me, you think that the default size of the IDE window is pathetically small there is a file called “preferences.txt” in your “AppData\Roaming\Arduino folder”. Modify the lines shown below to suit your preferences and restart the IDE.
editor.window.height.default=900
editor.window.width.default=1024
If you want more lines in the console panel at the bottom of the IDE then modify the line shown below.
console.lines=6
Arduino programs are referred to as “Sketches”. If you open a Sketch from anywhere on the File menu you get a new window opened which I find annoying. However if you open a Sketch using the Open (fourth) button on the toolbar then it opens in the existing window.
On the Arduino website there is a “Documentation” page Arduino - Docs that doesn’t seem to be reachable from elsewhere on the site. I came across it by accident when I was searching the website but I can’t find a direct link to it, perhaps you will. It contains a useful set of links to other topics on the site which, while all accessible from other pages, are convenient to have collected in one place. The “Environment” topic is an introduction to using the IDE. There is a local copy of this in the “reference” folder in the Arduino IDE installation folder which can be opened from the IDE by Help -> Environment. There are other local copies of parts of the website in the same folder that can be opened by other options on the Help menu. Help -> Find in Reference however doesn’t seem to have any effect for me.
First Compilation
Now let’s check that we can compile a program. Select File -> Examples -> AndroidAccessory -> demokit or Toolbar Open Button -> AndroidAccessory -> demokit. This loads the source code of the demo that requires the Android Demo Shield that we don’t have, but if we can compile it then that will show we have the correct libraries to communicate with an Android device. We are going to have to modify this program as the CapSense library has changed name since the ADK was produced. However the IDE doesn’t allow you to save files in any of the sub-folders of the IDE installation and give you a “Sketch is read-only” error as you will see if you now do File -> Save. Closing the Error dialog will give you a File Save dialog that will save the file in your “Sketchbook”, which is the “Arduino” folder in your personal Documents folder. Select OK and the saved file will now appear under File -> Sketchbook and directly under the toolbar open button menu. Versions of the IDE prior to 1.0 saved sketches with the extension .pde. When you open and then save one of these files it will be saved with the .ino extension.
The next tutorial will cover programming the Arduino in a bit more detail but now that we have an editable copy of the demo there are four changes we need to make. Three instances of “CapSense” need to be changed to “CapacitiveSensor” and one instance of “capSense” needs to be changed to “capacitiveSensor”, note the differences in case. Compile the program by Sketch -> Verify/Compile or by clicking on the “tick” symbol at the left of the IDE toolbar and you should get a message in white in the lower console window “Binary sketch size: 18,362 bytes (of a 258,048 byte maximum)”.
When compiling a program the Arduino IDE writes temporary folders and files to your “Appdata\Local\Temp” folder and does not delete them. As a mater of routine I regularly delete all the contents of this folder as other programs also write and leave temporary stuff there. I also regularly empty the “Windows\SoftwareDistribution\Download” and “Windows\Temp” folders as stuff builds up in both of those folders as well.
The next tutorial
This tutorial has shown that we can successfully compile a program that uses the Android Accessory libraries. Now we need to connect our Arduino to our PC and check that we can download and run a simple program that can communicate with the PC before finally trying to write and run Arduino and Basic4android companion programs that can communicate with each other.
Tutorials
In addition to this tutorial there are other tutorials. They are:
1. Introduction to the Arduino Mega ADK and Android Accessories. Introduction
2. This one!
3. Connecting the Arduino Mega ADK to your computer and running programs on it. Programming
4. Connecting the Arduino Mega ADK to your Android device and writing both an Arduino and a Basic4android program to communicate with each other. Consummation
5. Some commentary on the two programs in tutorial 4. Coda
This tutorial deals with installing the Arduino IDE onto the PC and ensuring that we can compile a program. We are following the “Installing the Arduino software and necessary libraries” section on this web page
Accessory Development Kit 2011 Guide | Android Developers
Download and install the Arduino IDE
We need three downloads. The following instructions assume a Windows installation as if you are using Basic4android you must have access to Windows in order to run the IDE.
The Arduino IDE itself, currently version 1.0.4, is available here. You do NOT want the 1.5 beta.
Arduino - Software
Extract the arduino-1.0.4 folder and place it somewhere convenient but NOT in Program Files or any other protected folder. If you get a security dialog when trying to run it right click arduino.exe, select Properties and click the Unblock button on the General tab.
The Accessory Development Kit package contains the necessary Arduino libraries and the demo program which we will use to demonstrate that the IDE will compile correctly but will not actually use on the Arduino.
https://dl-ssl.google.com/android/adk/adk_release_20120606.zip
Extract and copy the “AndroidAccessory USB” and “Host_Shield” folders from the “arduino_libs” folder in the archive (the complete folders, not just the files within) to the “libraries” folder in the Arduino IDE installation folder.
A further library which the demo program that we will compile uses.
Arduino Playground - CapacitiveSensor
Extract and copy the “CapacitiveSensor” directory and its contents to the “libraries” folder in the Arduino IDE installation folder. Note that the instructions in the “Installing the Arduino software and necessary libraries” section of the ADk web page are wrong as the name of this library has changed. Because of this we will also have to edit the Arduino demo source to get it to compile.
There is an alternative location for extra libraries under your personal Documents folder should you for some reason want to restrict their use by other users of your computer.
Arduino - Libraries
Configure the IDE
Run the IDE by double-clicking arduino.exe. Under Tools -> Board select “Arduino Mega 2560 or ADK”.
If, like me, you think that the default size of the IDE window is pathetically small there is a file called “preferences.txt” in your “AppData\Roaming\Arduino folder”. Modify the lines shown below to suit your preferences and restart the IDE.
editor.window.height.default=900
editor.window.width.default=1024
If you want more lines in the console panel at the bottom of the IDE then modify the line shown below.
console.lines=6
Arduino programs are referred to as “Sketches”. If you open a Sketch from anywhere on the File menu you get a new window opened which I find annoying. However if you open a Sketch using the Open (fourth) button on the toolbar then it opens in the existing window.
On the Arduino website there is a “Documentation” page Arduino - Docs that doesn’t seem to be reachable from elsewhere on the site. I came across it by accident when I was searching the website but I can’t find a direct link to it, perhaps you will. It contains a useful set of links to other topics on the site which, while all accessible from other pages, are convenient to have collected in one place. The “Environment” topic is an introduction to using the IDE. There is a local copy of this in the “reference” folder in the Arduino IDE installation folder which can be opened from the IDE by Help -> Environment. There are other local copies of parts of the website in the same folder that can be opened by other options on the Help menu. Help -> Find in Reference however doesn’t seem to have any effect for me.
First Compilation
Now let’s check that we can compile a program. Select File -> Examples -> AndroidAccessory -> demokit or Toolbar Open Button -> AndroidAccessory -> demokit. This loads the source code of the demo that requires the Android Demo Shield that we don’t have, but if we can compile it then that will show we have the correct libraries to communicate with an Android device. We are going to have to modify this program as the CapSense library has changed name since the ADK was produced. However the IDE doesn’t allow you to save files in any of the sub-folders of the IDE installation and give you a “Sketch is read-only” error as you will see if you now do File -> Save. Closing the Error dialog will give you a File Save dialog that will save the file in your “Sketchbook”, which is the “Arduino” folder in your personal Documents folder. Select OK and the saved file will now appear under File -> Sketchbook and directly under the toolbar open button menu. Versions of the IDE prior to 1.0 saved sketches with the extension .pde. When you open and then save one of these files it will be saved with the .ino extension.
The next tutorial will cover programming the Arduino in a bit more detail but now that we have an editable copy of the demo there are four changes we need to make. Three instances of “CapSense” need to be changed to “CapacitiveSensor” and one instance of “capSense” needs to be changed to “capacitiveSensor”, note the differences in case. Compile the program by Sketch -> Verify/Compile or by clicking on the “tick” symbol at the left of the IDE toolbar and you should get a message in white in the lower console window “Binary sketch size: 18,362 bytes (of a 258,048 byte maximum)”.
When compiling a program the Arduino IDE writes temporary folders and files to your “Appdata\Local\Temp” folder and does not delete them. As a mater of routine I regularly delete all the contents of this folder as other programs also write and leave temporary stuff there. I also regularly empty the “Windows\SoftwareDistribution\Download” and “Windows\Temp” folders as stuff builds up in both of those folders as well.
The next tutorial
This tutorial has shown that we can successfully compile a program that uses the Android Accessory libraries. Now we need to connect our Arduino to our PC and check that we can download and run a simple program that can communicate with the PC before finally trying to write and run Arduino and Basic4android companion programs that can communicate with each other.
Tutorials
In addition to this tutorial there are other tutorials. They are:
1. Introduction to the Arduino Mega ADK and Android Accessories. Introduction
2. This one!
3. Connecting the Arduino Mega ADK to your computer and running programs on it. Programming
4. Connecting the Arduino Mega ADK to your Android device and writing both an Arduino and a Basic4android program to communicate with each other. Consummation
5. Some commentary on the two programs in tutorial 4. Coda
Last edited: