IOIO-OTG Hookup Guide

Pages
Contributors: Joel_E_B, Ytai
Favorited Favorite 5

Building Your First Android App

Now that we know how to upload a known-good application, let's see what it takes to build our own using Android Studio.

Open Android Studio

Note: Going into detail about how to use Android Studio is beyond the scope of this tutorial. This section will minimally cover how to upload an app using this software. For more information on getting started with Android Studio, we suggest you complete their Building Your First App tutorial.

Open Android Studio. If this is the first time you're opening it, it may take a few minutes. There may be several setup/first-time-tips windows to navigate through.

You should eventually be presented with the following screen asking what action you'd like to perform:

alt text

Choose 'Open an existing Android Studio project.'

Open HelloIOIO Application

Inside the Android Studio file explorer window, navigate to ~/App-IOIO0507/src/applications, and open the folder titled HelloIOIO.

alt text

Heads up! Upon opening the project, Android Studio may yell at you about there being mismatched versions of various pieces needed to compile the code, such as the Android SDK or the Gradle Wrapper. It will offer downloads of the version(s) needed to correct the mismatch.

Keep clicking OK and installing any missing platforms until Android Studio is happy.

The project tree has many files. The file that contains the Java code for the IOIO is in HelloIOIOscrioio.examples.helloMainActivity.java. Double click on the MainActivity.java file, and you should see this:

alt text

The MainActivity.java file contains the code that talks to the IOIO board. If you want to change the UI (user interface or graphics) of your app, the res → layout → main.xml file is where you make the changes. Here you can start writing code and changing the HelloIOIO sketch, if you desire.

Delete App from Android Device

Though we'll be installing the same app as in the previous section (unless you decided to alter the code), you will need to uninstall the app on your Android device to ensure that Android Studio is working properly.

Make sure that you are uninstalling the app and not just removing it from your home page. On most devices, this requires long tapping the app and dragging it to the Uninstall (trash bin) area at the top of the screen.

Plug in Your Android Device to Your PC

Plug your Android device into your PC.

Heads up! Be sure to enable USB Debugging before you plug in your Android device.

Upload App to Android Device

With your device connected to your PC, click the 'Run' button:

run

Android Studio will ask to which device you'd like to upload the application. Assuming you only have one device plugged in, there should only be one option. You can also use the Android emulator if you do not have an Android device.

select device

You should see the build status at the bottom of the window. It will say Gradle Build Running, followed by Gradle build finsihed.

build

On your Android device, navigate to your applications. You should now see a HelloIOIO app on your device.

app

Plug in the IOIO to Your Android Device

Heads up! Be sure to disable USB Debugging before you plug your IOIO into your Android device.

Unplug your device from the PC, keeping the micro USB cable attached to your Android device. Attach the red USB Female A to Micro A OTG Cable to the end of the micro USB cable. Then attach the micro A end of the OTG cable to the Micro A-B connector on the IOIO-OTG.

Provide power to your IOIO using the Barrel Jack-to-JST Adapter. The red power LED should illuminate.

alt text

Open the HelloIOIO app, and you should be presented with this now familiar screen:

app

Press the button on the touchscreen to turn the Stat LED on and off. You've just successfully built, uploaded and used your first IOIO Android application!

alt text

For a complete list of all the commands you can issue to the IOIO, go back to the IOIO folder you downloaded from GitHub. Inside that folder is another folder titled doc. Navigate to doc, and open the index.html file in your browser. There you will find a reference of all the IOIO classes. See if you can get an LED to blink on one of the IOIO's digital I/O pins.

Check the Resources and Going Further section for more information and links to IOIO resources.

If you are having trouble getting the app to work, please visit the Troubleshooting section.