Blog

Android Connectivity using the Android Open Accessory Development Kit

Android Connectivity using the Android Open Accessory Development Kit

With Android operating system’s market share growing rapidly, the appeal for developers to release their applications on this platform has never been higher. Android is quite developer friendly, and as it matures the variety of applications has been growing steadily.

Most Android programs (and really most mobile apps), run on the target device and will interact to the outside world over some sort of wireless network: Wi-Fi, Bluetooth, NFC, etc. However, a much less common (but equally as awesome) mode is to interface with external hardware directly using a physical connection. One of the coolest examples of this type of communication in my opinion has been credit card readers that connect to a mobile device using the 1/8” headphone/microphone jack. Another communication interface that is provided with nearly all mobile devices running Android is USB. Google supports a software development kit called the Open Accessory Development Kit (ADK) which is a software stack that defines methods for the Android device to communicate to a generic external device over USB. This allows for custom hardware to be easily interfaced to a device running the Android operating system. One example application of this technology would be for a navigation app to use an external GPS to obtain a more accurate location than the device itself can supply.

At DMC, we recently created a simple “Hello World” Android application to demonstrate using the ADK to connect a Nexus 7 Android tablet to an electronic dial indicator. After a few minor communication issues, we quickly prototyped a working system, and I wanted to share the result with our blog readers.

The goal was to create a simple Android app that would display, in real-time, the current measurement on the electronic indicator. The indicator can send its current measurement interface through a RS-232 serial interface, so the first design challenge was to find a method of translating this information to USB format in a way that is compliant with the ADK protocol. Luckily, Future Technology Devices (FTDI) makes a chip that serves this exact purpose, and they also sell some simple development boards that demonstrate the various supported interfaces (General I/O, Serial, SPI, etc.). For each of the interface modes, they wrote a very basic Android application to demonstrate the functionality and released the source code for public reuse.

For our demo, we used the FT311D board. Connecting this device to the electronic indicator was simple. RS-232 is a two-wire interface (not counting the ground connection), so we simply sliced open the vendor-supplied cable and connected the two serial pins appropriately to the FT311D headers. The development board has three pairs of pins that are jumpered together to set up the interface mode, so these were set up for RS-232 communication.

Connection between the FT311D board and the Android tablet was very simple. The device serves as a USB host and will recognize any device running a flavor of Android that supports the ADK (this includes 3.1 and above natively, although version 2.3.4 can support the ADK with some additional libraries). One of the cool features of the ADK is the ability for the Android device to associate the attached peripheral to an installed application, and launch it automatically when the peripheral is connected. The FTDI-provided code supported this functionality out of the box, so the RS-232 application launched immediately after powering up the board.

The electronic dial indicator’s serial command set returns the current measurement after a request command is received. Unfortunately, FTDI’s application didn’t work natively with the indicator. I spent some time trying to debug the software by checking the serial lines with a Bus Pirate (which is an immensely useful tool for anyone working with any of the generic flavors of serial communication!), but wasn’t able to pinpoint exactly why the communication wasn’t working properly. Instead, I decided to re-design the application so that it was more centric to the gauge’s command set. That is, on a fixed update interval the application sends a “Get Current Reading” message to the gauge, looks for the response, updates the display, then goes idle.

The display of the dial indicator updates at a rate of approximately 30Hz, and I targeted the Android application to have the same refresh rate to duplicate the physical hardware’s user experience. The revised code worked just as I expected, and we were able to view the current measurement gauge measurement on the Nexus tablet. I also added a button to “Clear” the current measurement, which mimics the physical button on the front of the gauge. You can check out the final result in this video below!

The process of developing a simple “Hello World” application with the Android ADK was surprisingly easy, and yielded some cool results. For anyone interested in tinkering with this interface, I would highly suggest the FT311D development board from Future Technology, as it was very easy to use right out of the box, and is quite reasonably priced. Happy hacking!

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts