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.

Comments

  1. Android tablets are great, their slimness, quality of color, functionality. At first I was so confused about it, but once I decided to lets try and buy one. now according to my experience I advise every one to buy android.

    what is arduino

    ReplyDelete
  2. AndroidAccessory.h:13: error: expected class-name before '{' token

    i'm stuck on it... =(

    ReplyDelete
    Replies
    1. Do you havea the USB Host Shield 2.0 library from Circuits@Home? From here: https://github.com/felis/USB_Host_Shield_2.0

      and if so, make sure you, at least, include usb.h before including the AndroidAccessory.h in your sketch.

      Delete
  3. I am working on (Location Based Alarm System), a Friend Finder API . i am getting problem while setting up the range , so Will you please help me regarding to this.
    here is my email address : fahad0847@gmail.com

    ReplyDelete
  4. Hi!

    i am a student. and i am building my custom Arduino board. i am curious that i have to use adk library or Usb Shield. There are many other questions i have.

    what i am doing is
    1) Building Custom Arduino Board
    2) Building Custom FT232-RL USB-to-Serial Converter
    3) Arduino 1.0 IDE

    My Questions are

    1) How to burn bootloader (Which Board i select)
    2) What USB Host library i use.

    Please help me and send me an email.
    Thanx.
    Yasir Ali
    ali.yasir0@gmail.com

    ReplyDelete
  5. seems the link to the library is bad: https://docs.google.com/open?id=0Byxmdl8pLRmAMWU5NzlmMDctNGUyZC00ODlkLWE4YzMtYTllYmUzOWE4MGY0

    ReplyDelete
  6. Many Thanks for making this lib.

    Cheers

    Craig

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

Parallax Smart Card Reader Samples for Arduino

Parallax Smart Card Reader - Revisited