Example Connection between USB Host and Android - Micro4you

26 downloads 124 Views 7MB Size Report
Example Connection between USB Host and Android. This example illustrates the connection between Board ET-. MEGA2560-ADK and Android through Port ...
Example connection between USB Host and Android

Example Connection between USB Host and Android

This example illustrates the connection between Board ETMEGA2560-ADK and Android through Port USB Host. In this case, it develops program by ADB (Android Debug Bridge) by using Library ADB of Microbridge. This example is compatible with every Android devices versions that have been installed the Operating System of Android version V1.5 and higher. It divides part of developing program into 2 parts. Firstly, it develops program in the part of Microcontroller (ET-MEGA2560ADK); and secondly, it develops program in the part of Android device. In this case, it uses Program Android SDK to develop Application of Android. There are many websites that have published information about developing program for board by ADB (Android Debug Bridge); in this case, we recommend the official website of http://developer.android.com/guide/developing/tools/adb.html.

ETT CO.,LTD

-1-

WWW.ETT.CO.TH

Example connection between USB Host and Android

Normally, the main circuit of Board ET-MEGA2560-ADK has been designed according to the standard of original circuit of Google ADK Mainboard (Google’s ADK Reference design); moreover, it has modifies some parts of sub-circuit suitably, so Board ET-MEGA2560-ADK can develop program through Android Open Accessory Development Kit (ADK) instantly. Nowadays, there are 2 main types to develop program of Android by Android Open Accessory Development Kit (ADK). Firstly, it develops program by Google Open Accessories API (ADK); in this case, it is compatible with Android devices that have been installed Operating system of Andriod version V2.3.4 or higher. Secondly, it develops program through ADB (Android Debug Bridge); in this case, it is used with Library of Microbridge. It is compatible with Android devices that have been installed the operating system of Android version V1.5 or higher.

ETT CO.,LTD

-2-

WWW.ETT.CO.TH

Example connection between USB Host and Android

Android Versions

Android is the operating system as Open Source Project from Google; it is suitable for mobile devices, especially Android Mobile Phone and Android Tablet. This Operating System of Android from Google is Open Source that can be developed and improved independently; so, it attracts many developers around the world to share the knowledge and develop program to supply requirement until it is a large community. It uses JAVA Language with Library of Google called “Google Developed Java Libraries” to develop program. Google continues improving and modifying the Library and nowadays there are more than 10 versions. If user requires using which Compiler version and Library version, it has to consider the Operating System of the device that has been installed to use with program development; next, user has to choose and set the Compiler version and the Library version according to the Operating System in the device. If user has set the Compiler version and the Library version that is higher than the actual installation in the device, the error maybe occurred because the device does not support some instructions.

ETT CO.,LTD

-3-

WWW.ETT.CO.TH

Example connection between USB Host and Android Android version is specified by name code (Nick Name) and API Level; however, some details are different. So, code and Compiler version must be matching, otherwise it cannot compile any code program.

Android Version

API Level

Name Code version (Nick name)

Android 1.0 Android 1.1 Android 1.5 Android 1.6 Android 2.0 Android 2.0.1 Android 2.1.x Android 2.2.x Android 2.3 Android 2.3.1 Android 2.3.2 Android 2.3.3 Android 2.3.4 Android 3.0.x Android 3.1.x Android 3.2

1 2 3 4 5 6 7 8 9

BASE BASE_1_1 CUPCAKE DONUT ECLAIR ECLAIR_0_1 ECLAIR_MR1 FROYO GINGERBREAD

10

GINGERBREAD_MR1

11 12 13

HONEYCOMB HONEYCOMB_MR1 HONEYCOMB_MR2

ETT CO.,LTD

-4-

WWW.ETT.CO.TH

Example connection between USB Host and Android

Android Open Accessory Development Kit (ADK) ADK is Android Program Development Kit that allows external USB Host device to interface with Android Operating System such as Android Phone and Android Tablet in the Accessory Mode; so, Android device can act as Host. Most devices are cheap such as mobile phones; it can communicate with external device through USB Bus according to conditions and restrictions of ADK. The format of Protocol ADK can reduce difficulty in communicating through USB of mobile phones. In this case, it moves the difficulty in communicating to the side of USB Host that is the outside of mobile phone instead. This capability is compatible with devices that have been installed the Android Operating System from version 2.3.4 (for old version that has been released) to version 3.1(for new product release). Accessory devices that are interfaced with Android devices in this operation mode must has own Power Supply; moreover, it cans also supply 5V/500mA to Android device to charge current for Android device.

Android Debug Bridge (ADB) This is the format of developing program that is Application for external devices; so, Android device can communicate and command various Input/output with external devices. In this case, user can apply cheap Android devices in the market for many applications; it seems to increase unlimited Input/Output systems into mobile phones. This capability is included in all Android device versions that have been installed the Operating System version 1.5 or higher; so, it can support almost devices in the market that have been installed the Operating System of Android. If interfacing Board ET-MEGA2560-ADK with mobile phone that has been installed the Operating System of Android, it looks like Board ET-MEGA2560-ADK acts as I/O of mobile phone; moreover, it is controlled and commanded by mobile phone through Cable USB. So, it seems that the mobile phone has the system of Input/Output that is both Digital and Analog, including other special Input/Output such as I2C, PWM, USART and so on. When user has studied and understood the format of communication between Android devices well, user can create and build many applications for using with mobile phones. For example, it controls ON/OFF the operation of electric appliances, including detect signal from the designed Sensors or detectors. ETT CO.,LTD

-5-

WWW.ETT.CO.TH

Example connection between USB Host and Android

The following example is a guideline to connect Android device with Board ET-MEGA2560-ADK; this example is modified from Library ADB of Microbridge. It uses the capability of GUI that uses touch screen and the display screen of mobile phone to command and display operating result of Input/Output of Board ET-MEGA2560-ADK. The operating result of program is to command ON/OFF LED(D13) on Board ET-MEGA2560-ADK according to the control of touch screen. In the meanwhile, Board ETMEGA2560-ADK sends the result of converting signal from Analog(ADC0) and then sends back to the Android device.

It shows result of example program by Emulator of Android.

ETT CO.,LTD

-6-

WWW.ETT.CO.TH

Example connection between USB Host and Android

How to test operation The method to test the operation of this example is to develop program for 2 sides; Microcontroller and Android device. On the side of Microcontroller, it uses Board ETMEGA2560-ADK and it develops program through Program Arduino with ADB Library of Microbridge. On the side of Android device, it uses computer PC with Program JAVA and Android Library of Google to be tool to develop program. First of all, user has to compile and upload program in the part of Microcontroller into Board ET-MEGA2560-ADK by Program Arduino first. Moreover, user has to copy Library ADB for AVR Microcontroller that has been developed and modified by Microbridge and then paste it in the Folder “..\arduino0022\libraries”. So, signals can directly interface with Hardware System of Board ET-MEGA2560-ADK as shown in the example below;

After user has installed ADB Library successfully, user can call IDE of Arduino, open the example file program and upload it into Board ET-MEGA2560-ADK instantly.

ETT CO.,LTD

-7-

WWW.ETT.CO.TH

Example connection between USB Host and Android

For the part of Hardware Board, it uses LED(D13) to display the operating result of ON/OFF that is commanded by from Android device; and it uses Signal Analog Pin A0 to receive Input Voltage and then convert it into data for sending and displaying on the screen of Andriod device. Moreover, user has to interface Input Voltage from Adjustable Resistor to adjust 0-5V Input Voltage according with Pin A0 to test the operation of program.

ETT CO.,LTD

-8-

WWW.ETT.CO.TH

Example connection between USB Host and Android

How to prepare ADK Development kit 1. Download and install Program 2. Download and install Program 3. Download and install program 4. Install Program ADT (Android

JDK (Java Developer Kit) Android SDK Eclipse IDE Development Tool) Plugin

1. Download and install Program JDK (Java Developer Kit). This is Java Language Program that includes various essential Libraries to develop program for Android. User can directly download and install the program from web page; http://www.oracle.com/technetwork/java/javase/downloads/i ndex.html; in this case, it has to connect Internet to computer PC to install program. When it has already connected to the web page of Download, choose Tab Download of Java Platform(JDK); next, choose Accept License Agreement to choose the program version that user requires downloading. In this case, user has to choose the program version according to the actual Operating System of computer. Finally, user has to follows instructions of installation.

ETT CO.,LTD

-9-

WWW.ETT.CO.TH

Example connection between USB Host and Android



Load from: http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html

ETT CO.,LTD

-10-

WWW.ETT.CO.TH

Example connection between USB Host and Android 2. Download and install Program Android SDK. User has to choose and set values according to the actual Operating System that has been installed in computer PC. If using with Windows, there are 2 choices; Zip File and Install File. In this case, it is better to choose version File Install because it is more convenient. When user has downloaded the program successfully, should install in because it is more Folder “C:\android-sdk-windows” convenient to call. Next, choose Package for installation as Accept All; in this case, it takes a long time for processing.



ETT CO.,LTD

-11-

WWW.ETT.CO.TH

Example connection between USB Host and Android 3. Download and install Program Eclipse IDE.



ETT CO.,LTD

-12-

WWW.ETT.CO.TH

Example connection between USB Host and Android 4. Install Program ADT (Android Development Tool) Plugin. This Program ADT links files and sub-programs that are essential and related to develop program for ADK; so, it is more convenient to call and command program through window IDE of Program Eclipse correctly. User has to install this Plugin while connecting Internet; click Menu Help  Install New Software…



ETT CO.,LTD

-13-

WWW.ETT.CO.TH

Example connection between USB Host and Android Set values in the window Install completely. Firstly, set the value in the blank of Work with as Add…; secondly, set Path value for downloading Program Plugin by setting Name as ADT; thirdly, set Path value in the blank of Location: as https://dl-ssl.google.com/android/eclipse/; and finally, click OK. User has to wait for a while and the program shows additional Developer Tools, user has to tick the check box and click Next to go to the next step.

After user has clicked Next, program shows details, conditions, and restrictions for using program; click I accept the terms of license agreements to accept the conditions; and finally, click Finish. Next, program starts installing files instantly; in this case, it takes a long time to process, depending on speed of internet network. Please wait until the installing process is complete.

ETT CO.,LTD

-14-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-15-

WWW.ETT.CO.TH

Example connection between USB Host and Android

Testing Example Application 1. Copy the example program that has been developed by ADK; paste and save in the Hard Disk as shown in the example below;

2. Run Program Eclipse; and set location of program in the blank of Worksheet according to the location that saved the example file; in this case, it is the location “C:\DEMO_MEGA2560_ADK” as shown in the example below;

ETT CO.,LTD

-16-

WWW.ETT.CO.TH

Example connection between USB Host and Android Click Menu File  Import…; choose Existing Projects into Workspace; click Next and finally, click “C:\DEMO_MEGA2560_ADK”



ETT CO.,LTD

-17-

WWW.ETT.CO.TH

Example connection between USB Host and Android After user has already set Directory successfully, the program shows lists of all Project File in the Directory; in this case, user can tick check box in front of the Project File that user requires Import to test the operation.

After user has chosen Import Project successfully, click Menu Windows  Preference to set location of Program SDK Compiler for Program Eclipse. When window Preference appears, click Tab Android; set the location that has installed Program SDK in the blank of SDK Location as “C:\android-sdk-windows” and then click OK. Next, click Menu Windows  Preference; window Preference appears and click Tab Android again to check values. If everything is correct, it shows lists of Compiler; in this case, user can choose and click the preferred list; and then click Apply and OK, respectively.

ETT CO.,LTD

-18-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-19-

WWW.ETT.CO.TH

Example connection between USB Host and Android

ETT CO.,LTD

-20-

WWW.ETT.CO.TH

Example connection between USB Host and Android Next, click Menu Project  Properties and choose Tab Java Compiler. User has to choose the Compiler version according to the Operating System of the device that is used with program development; in this case, user has to choose Enable Project Specific Setting and set the value as Compiler Compliance Level completely.

After user has already set the Compiler version successfully, user can compile program instantly; click Menu Project  Clean… to erase the old file that may be compiled by other unwanted values. Finally, click Menu Project  Build All.

ETT CO.,LTD

-21-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-22-

WWW.ETT.CO.TH

Example connection between USB Host and Android After user has compiled successfully, it displays the operating result in the format of File and it is saved the Folder “Mega2560ADKV233Demo.apk” “C:\DEMO_MEGA2560_ADK\Mega2560ADKV233Demo\bin“; in this case, user can install this file into the Android device instantly. If user has already installed Driver of Android device into computer PC and connected USB Cable between computer PC and Android device completely, user can run the operation from Program Eclipse instantly. Program transfers files to Android device automatically.

If user has not interfaced with Android device yet, user can build model to test the operation instead. Program SDK Kit has included the part of model building instead of using the actual device. In this case, user can set specifications of program as same as the device that is used with program development; moreover, user can use this model building to virtually test operation of program that has been developed by user. Click Menu Windows  Android SDK and AVD Manager; choose Visual Devices if user requires using the model building; or choose Installed Packages if user requires installing program into Android deice that is actually connecting.

ETT CO.,LTD

-23-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-24-

WWW.ETT.CO.TH

Example connection between USB Host and Android

ETT CO.,LTD

-25-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-26-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-27-

WWW.ETT.CO.TH

Example connection between USB Host and Android



ETT CO.,LTD

-28-

WWW.ETT.CO.TH