chipKIT® Development Platform

Inspired by Arduino™

Chipkit-based Android accessory example

Created Sun, 30 Mar 2014 16:04:56 +0000 by benderamp


Sun, 30 Mar 2014 16:04:56 +0000


I have made a working example of using ChipKIT (WF32 or Max32 with Network Shield with USB) as Android accessory working in USB-host mode.

Here is the code:

chipkit_usbhost_android - sketch for ChipKIT AndroidUSBClient - android application

This is a simple demo of Android-board communication over USB cable, Android application has 2 buttons to switch LED on pin 13 on the board on and off.

It works with WF32 or Max32 with Network Shield and Android 4.0 tablet rather fine.

I have also packed this code in ChipKIT-friendly library format (attached archive) - the library should appear like ~\Documents\mpide\libraries\chipKITUSBAndroidHost, then working example would appear in mpide in File/examples/chipKITUSBAndroidHost/USBAndroidHost menu .

I had to solve some problems to make it work with current ChipKIT usb libraries.

  1. Android accessory USB host driver from Microchip usb_host_android.c is not available with ChipKIT USB host libs, so have to download it from Microchip site with MLA package: In the latest v2013-12-20 version Microchip by some reason removed majority of USB examples, so I have used previous v2013-06-15 version as the base, but it seems that android accessory driver is the same in both versions.

For android accessory driver I take the following files from MLA and put them to sketch directory: usb_host_android.c usb_host_android_local.h usb_host_android.h struct_queue.h Compiler.h

  1. The problem here is that android driver will not compile with chipKITUSBHost library provided by chipKIT for WF32 and Network Shield here:,892,942&Prod=CHIPKIT-NETWORK-SHIELD - it will show compilation errors like missing EVENT_1MS constant definition.

To solve it, I have taken a number of files from MLA and replaced their mpide versions in chipKITUSBHost library: usb_common.h (declares EVENT_1MS) usb_host.c (calls event with EVENT_1MS) usb_host.h (EVENT_1MS is not present, but after replacing prev files usb_host.c will not compile without it) usb_host_local.h (same as above)

  1. All above files are moved to chipKITUSBHost without modifications except usb_host.c - in usb_host.c had to replace debug print calls to things like: #ifdef DEBUG_MODE UART2PrintString( "HOST: Cannot allocate for endpoint 0.\r\n" ); #endif

  2. Created chipKITUSBAndroidHost.h and chipKITUSBAndroidHost.cpp ChipKIT-style C++ wrappers (quite optional, C calls also work just fine).

I have also checked at least ChipKITUSBMSDHost examples with updated chipKITUSBHost library and it seems to work. It would be good, if ChipKIT USB Host library provided from digilent would be updated to recent version from MLA, so this manual modifications will not be needed to make android accessory driver work.


Wed, 09 Apr 2014 17:05:12 +0000

This looks really cool. I will be trying it soon.

Update: The example breaks on boards that use USB for Serial. It does not give a compiler warning but the Serial.prints in the sketch cause it to fail. Other than that the code works pretty good so far.

Jacob Christ

Tue, 06 May 2014 21:54:55 +0000

Here is a video of a demo for Maker Faire that that mikes built for PONTECH based on this Android Accessory example code.

We are working on posting code here:


Jacob Christ

Wed, 17 Sep 2014 01:43:11 +0000

Here is a new project based on this library that utilizes this library.