Chipkit-based Android accessory example

Let us know what you think about the chipKIT, and what can be done to make it better!
Post Reply
benderamp
Posts: 16
Joined: Tue Mar 11, 2014 7:21 pm

Chipkit-based Android accessory example

Post by benderamp » Sun Mar 30, 2014 5:04 pm

Hello,

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:
https://github.com/1i7/snippets/tree/co ... ndroid-usb

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:
http://www.microchip.com/pagehandler/en ... tools/mla/
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

2) The problem here is that android driver will not compile with chipKITUSBHost library provided by chipKIT for WF32 and Network Shield here: http://digilentinc.com/Products/Detail. ... ORK-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)

3) 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

4) 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.
Attachments
libraries.7z
chipKITUSBAndroidHost and chipKITUSBHost libraries
(971.37 KiB) Downloaded 299 times

mikes
Posts: 74
Joined: Mon May 14, 2012 10:37 pm

Re: Chipkit-based Android accessory example

Post by mikes » Wed Apr 09, 2014 6:05 pm

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.

User avatar
Jacob Christ
Posts: 723
Joined: Sat May 28, 2011 6:34 am
Location: Southern California
Contact:

Re: Chipkit-based Android accessory example

Post by Jacob Christ » Tue May 06, 2014 10:54 pm

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

https://www.youtube.com/watch?v=2IdhJw5HJgQ

We are working on posting code here:

http://quick240.com/quicki/demos:pingponglev

Jacob
PONTECH Quick240 an industrial form factor platform for chipKIT and Arduino users.

User avatar
Jacob Christ
Posts: 723
Joined: Sat May 28, 2011 6:34 am
Location: Southern California
Contact:

Re: Chipkit-based Android accessory example

Post by Jacob Christ » Wed Sep 17, 2014 2:43 am

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

http://quick240.com/quicki/demos:androi ... tiesviewer

Jacob
PONTECH Quick240 an industrial form factor platform for chipKIT and Arduino users.

Post Reply