close

ArduinoADK_R3_Front_450px  

現今多種外接於行動裝置的 App 或 Accessory 如 SquareUp 等,覺得雖然未必這些應用有多大用處,但他一定有許多不同的固定使用群眾,哪怕是很小眾。其實近兩年也一直想將 Arduino 接至 iPhone/Android Phone 以尋求更多的行動應用,光看看別人做的 project、腦中胡思亂想的 idea 就覺得是很興奮的事情。 其實 iPhone 早就能透過 Dock breakout 雙向傳輸資料,但必須要 Jailbreak 還是無法給一般使用者使用。不過所幸之前有找到走 Audio Jack 的方式,就如同麥克風錄音一樣將訊息傳進 iPhone,再透過 App 去解析這些訊息。不過 Audio Jack 的方式目前實驗還不是太順利 (還有其他更重要的事 XD),因此之後有成功再將心得和程式分享出來。

最近正好實驗室中另一位 PhD 要做一個 Tactile feedback for Eyes-free 的 project,讓我有名正言順的機會摸索 Arduino+Mobile,但因為平台選定為 Android,因此我只好半推半就的測試一下 Google ADK 了 XD
 
首先先看看 Google 官方文件要我們怎麼做:

Installing the Arduino software and necessary libraries

To install the Arduino software:

  1. Download and install the Arduino Software as described on the Arduino website.

    Note: 如果是 Mac 平台,需另行安裝 FTDI USB Serial Driver,他應該附於官方的 Arduino.dmg 裡面。

  2. Download 下載與解壓縮 ADK package。你應該會得到 app, firmware, 和 hardware 三個資料夾。
  3. 下載與解壓縮 CapSense。
  4. 安裝上述使用 ADK 必要的 Arduino Library:

    On Windows:

    a. Copy the firmware/arduino_libs/AndroidAccessory and firmware/arduino_libs/USB_Host_Shield directories (the complete directories, not just the files within) to the <arduino_installation_root>/libraries/ directory.

    b. Create a CapSense directory in the <arduino_installation_root>/libraries/ directory

    c. Copy CapSense.cpp and CapSense.h from the unzipped CapSense download to the CapSense directory.

    On Mac:

    a. Create, if it does not already exist, an Arduino directory inside your user account's Documents directory, and within that, a libraries directory.

    b. Copy the firmware/arduino_libs/AndroidAccessory and firmware/arduino_libs/USB_Host_Shield directories (the complete directories, not just the files within) to your Documents/Arduino/libraries/ directory.

    c. Create a CapSense directory in your Documents/Arduino/libraries/ directory.

    d. Copy CapSense.cpp and CapSense.h from the unzipped CapSense download to the CapSense directory.

    On Linux (Ubuntu):

    a. 動作與 Mac 差不多,但需:

    b. Install the avr-libc library by entering sudo apt-get install avr-libc from a shell prompt.

你需要安裝以下 Arduino Library: AndroidAccessory, USB_Host_Shield, 與 CapSense.

出處:http://developer.android.com/guide/topics/usb/adk.html#installing

CapSense:http://www.arduino.cc/playground/Main/CapSense

 

DemoKit Fix w/ Arduino 1.0

由於Arduino 1.0 正式推出,許多 header file 名稱被改,也統一了許多 method name (Wire.recieve()--->Wire.read()),所以若使用 Arduino 1.0 直接 Compile 可能會跑出很多問題,相關解法可以直接下載 USB_Host_Shield_2.0 覆蓋至 Arduino\libraries\ 或是手動 Fix

由於手動 Fix 後,DemoKit sketch 還需要逐一修改,於是這邊我們選用 USB Host Shield 2.0 作法。

進入 Arduino 1.0 後,我們選 File -> Examples -> USB_Host_Shield -> adk -> demokit_20

Screen Shot 2012-03-13 at 下午3.02.40  

請至上方工具列的 Tools 裡面,選正確設定的 Board 與 Serial Port,即可 Verify & Upload 了!

 

Open ADK 似乎發表於 Android 3.1 時,但向下兼容到 2.3.4,因此 DemoKit 範例程式若跑在 API Level 10 與 API Level 12+ 平台會有所不同(import 的 package name 改了),code 需要手洞修改可參照官網 USB Accessory

雖然正在寫實戰心得,但其實在下試了 Nexus One (2.3.6), Sony Ericsson X10 (2.3.4) , Acer Iconia (3.2.1) 等產品都不能正常運作,不過聽台大實驗室的學弟們試了 Moto Xoom (4.0), Galaxy Nexus (4.0) 都成功了,暫時無法釐清是 Android 裝置的問題還是我用的 3rd party ADK 問題 (TBC),真該將原廠 ADK 帶在身上的。

Anyway,既然我是用 3rd party ADK 無法正確運作 Google 提供的 Sample code,只好轉向去 Seeeduino 官網找原因了。沒想到在官方 Wiki 中很順利的找到解答與 Sample code,也一切運作成功,更顯得前面浪費了一個下午顯得有點...嗯。

不過一直撞牆的好處就是能意外在腦中意外連結了一些鬼點子,也發現 USB Host Shield for Arduino (ADK 本身內建) 無論硬體或軟體真的都很有趣,例如 Collin's Lab 早在兩年前就拿它 Hack 過 USB Device。

 

 

To be updated: Demo | Code

 

Reference & Useful Links

Demo:http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/

http://stackoverflow.com/questions/6355031/how-can-i-get-the-adk-demokit-example-working-on-a-google-i-o-galaxy-tab-10-1

http://resources.upverter.com/android-usb-accessory-mode

arrow
arrow

    DK 發表在 痞客邦 留言(0) 人氣()