Exchanging data between Android and USB devices using Arduino

(Under Construction)

This section describes various approaches to hardware development of accessories using Andriod, Arduino, Microchip devices and interfacing to ERP system like OpenERP, SAP using Remote Function Calls (XML-RFC).  

BÁCON:CONSULT's objective is to enable easier real-time sensing and integration to Business Applications modules for ERP systems such as OpenERP, SAP. For instance interfaces to Weighing Scales, Production Controllers, Barcode Readers,  RFID controllers, QR-Code readers, etc. It is also seen that mobile phones are now more powerful computers which can do much more than merely making phone calls and sending SMS. The power of mobile devices enables easier integration for real-time Business Intelligence and Monitoring.  We use OpenERP as the proof of concept - mainly because it's opensource,  supports most business workflows ,  much cheaper to build demonstrators as it generally easy to build modules that work out-of-the-box.

Android Open Accessory (AOA)

AOA is quite an underutilised feature of Andriod SDK having been announce by Google in 2011. Official Android SDK support for external hardware such as USB devices (and, to some extent, NFC) is still in the early phases and the infancy of the APIs. 

At the same time as announcing the AOA APIs in the Android SDK, Google also announced  the availability of an Android Development Kit (ADK) microcontroller based on the popular Arduino hardware platform. In conjunction with external hardware, it is easy to see how mobile phones have shifted away from simply being cellular-enabled phones to “little computers in your pocket,” which can act as the brains for applications ranging from wearable computing to home automation

See also the Great Android Sensor Toolkit (GAST project) Great Android Sensor Tool  available on github.

Microchip Technologies Inc.

Microchip provide a PIC24F Accessory Development Starter Kit for Android™ (DM240415) for testing the interface with Android devices. 

Be aware that not all Android devices support AOA. This can be tested by installing the demo from microchip. 

Download the demo -> Microchip Android Demo If you can't install the demo then your Android device doesn't support AOA. If it does then testing interfaces is quite straight forward with this demo.  

Microchip’s line of PIC microcontrollers are widely used in the embedded systems industry but haven't seemed to reflect the growing popularity of the open source hardware movement. Microchip provide an IDE, but most use others such as from Crownhill or Swordfish to do development.  If you haven't used Microchips before then there is a steep learning curve, however, if you are already familiar with PIC chips, this would be a great development board to pick up as the approach is similar as other PIC chips. 

Bacon:Consult has over 10 years experience with PIC programming within embedded robotic and sensor applications and can support you with interfacing apps.


For starters in any type of hardware development and interfacing to devices I would recommend the Arduino. There are many versions available. i use Arduino Uno and others clones like Teensy, Solarbotics which works well for different project. The latest version such as Duo, Leonardo have extra features. The Leonardo has similar features to the Teensy in that it can emulate a mouse, keyboard, joystick which makes it easier to interface as a PC or Android will recognise it as that device.  

Arduino is written in Java Script. based on the same language as processing.org. which offers an extremely impressing fast and powerful graphical  representation of data.  . There are many website where you can test processing style java scripts such as http://processingjs.org/

Processing.org / Processing.js

Processing.js is the sister project of the popular Processing visual programming language, designed for the web. Processing.js makes your data visualizations, digital art, interactive animations, educational graphs, video games, etc. work using web standards and without any plug-ins. You write code using the Processing language, include it in your web page, and Processing.js does the rest.

Iframe Wrapper

Data Exchange with Android, Arduino and OpenERP

Exchange data between USB device and ADK-capable Android phone. I will be using a 360 degree infrared distance sensor as source device; the data will be received by the phone and displayed on a screen using Arduino Terminal Android application.

A phone is an USB device, too, and since two USB devices are unable to communicate to each other directly, I’m using Teensy Board equipped with USB Host shield to relay data between devices. 

The sketch which runs on Arduino is a mix of two other pieces of code, one from ADK terminal emulator article and another one from an article explaining interfacing with a barcode scanner.

Below is a full text of an Arduino sketch. It can be pasted from this page in Arduino IDE, compiled, and loaded into the board. It is also included in the examples section of USB Host library rev.2.0 distribution on gitHub. The library itself shall be installed in Arduino IDE tree as well.

To receive data from Arduino you’ll need Arduino Terminal application installed on your phone. The source code of application is also available – it is released under GPL2, if you make modifications to the code, please make them available for other people!

Finally, you''ll  need some hardware – an Arduino board, USB Host shield, a USB hub, “declawed” CueCat or any other HID boot barcode scanner, as well as ADK-compatible Android phone. We will also need a 5V power supply capable of providing ~700ma of electrical current. I will show arrangement of all necessary pieces after explaining the sketch code.