Saturday, December 31, 2011

A USB Host Shield 2.0 compatible AndroidAccessory Library

I've been reading the Arduino + Android Projects for the Evil Genius book (by Simon Monk) .... if you are interested in learning what's required to communicate between an Arduino and an Android Phone or Tablet, this is a great way to get started.   

Anyhow...while playing with the sample projects, downloading the code, etc. I found that my USB Host Shield (which uses v2.0 of the Arduino library from Circuits@Home found here) wasn't compatible with the AndroidAcessory library found in the Android Open Accessory Development Kit (ADK) that can be accessed here.  

So, rather than taking the time to change all of the Arduino sketches to be compatible with the newer USB Host Shield library, I went a different direction and instead took some time to create a 'compatible' AndroidAccessory library.  I can tell you that all of the Arduino sketches in the aforementioned book will compile unchanged ... and they seem to run just fine.   It really should work with any sketch that references the AndroidAccessory library ... but, I certainly can't guarantee that.

You can find the new AndroidAccessory library here.


Note:  I have tested this with Arduino 1.0 only ... but it really shouldn't matter, since there now aren't any Arduino-specific #includes ... but I could certainly be wrong ... so, if you end up having problems, let me know, I'll try to help.


Updates

01-01-2012
  • Removed some (most) of the #included headers from the AndroidAccessory.cpp file which weren't needed ... just trying to make it as-compatible as-possible.
  • Removed a cast in the AndroidAccessory::read function call to RcvData that wasn't necessary.
  • Removed USB_NAK_LIMIT from the AndroidAccessory.h file and keywords.txt  ... it is already #defined in the USB_Host_Shield 2.0 library.
01-02-2012
  • Added some Serial.print (and println) calls for visibility while debugging... of course, your sketch will have to begin the Serial connection.   But, now you'll be able to tell if anything is amiss.
  • Renamed the .zip to USBHost2_0_AndroidAcessory.zip and added a README.txt file; although neither of these things have any effect on the library itself.
01-11-2012
  • Re-Added USB_NAK_LIMIT to AndroidAccessory.h for compatibility with the recent USB_Host_Shield 2.0 library changes that now support Arduino 1.0.  I made it an #ifndef, so if it's already there it won't be added and if it isn't, it is added.
02-14-2015
  • Move Library to Github.