Advertisement

Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

Thursday, February 28, 2013

Android Jelly Bean and Arduino Uno Communication with USB Shield

It has been sometime since I wrote my last post. In between I bought a Samsung Galaxy Note 2 phone with Android Jelly Bean 4.1.1 Version and a USB Host Shield for Arduino. I have read that the  Arduino can be used as an ADK (Android Development Kit) alternative when it is plugged to a USB Shield.

There is a post in Circuits at Home web site which shows how to connect Android phone and Arduino with USB Shield. I followed the link but ran into problems while using the Sample program with Jelly Bean.

After hours and hours of googling I found the following needs to be done to enable Jelly Bean to communicate with Arduino Uno with USB Host Shield.

  1. You need Arduino IDE 1.0 or higher, can download it from this link
  2. You need the latest release of ADK which was released in 2012, can download it from this link
  3. Put the libraries available in above ADK into your Arduino IDE libraries directory.
Now you should be able to compile the code above shown in the Circuits at Home web site. If you get the errors similar to the following.


C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static void MAX3421E::setRST(uint8_t)':
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:58: error: 'PORTJ' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:58: error: 'PJ2' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:60: error: 'PORTJ' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:60: error: 'PJ2' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static uint8_t MAX3421E::readINT()':
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:65: error: 'PINE' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:65: error: 'PE6' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp: In static member function 'static void MAX3421E::pinInit()':
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:77: error: 'DDRE' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:77: error: 'PE6' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:78: error: 'DDRJ' was not declared in this scope
C:\Program Files\arduino-1.5.2\libraries\USB_Host_Shield\Max3421e.cpp:78: error: 'PJ2' was not declared in this scope

Then you need to have the following in your Max3421e_constants.h instead of the existing

#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__)
  #define SCK_PIN   52
  #define MISO_PIN  50
  #define MOSI_PIN  51
  #define SS_PIN    53
#define MAX_SS    53
#define MAX_INT   9
#define MAX_GPX   8
#define MAX_RESET 7
#endif
#if  defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
  #define SCK_PIN   13
  #define MISO_PIN  12
  #define MOSI_PIN  11
  #define SS_PIN    10
#define MAX_SS    10
#define MAX_INT   9
#define MAX_GPX   8
#define MAX_RESET 7
#endif