Sunday, June 8, 2014

Make USB OTG work on Nexus 4

It's not a trivial stuff to make thumb USB drive / speaker / keyboard work on Nexus 4 since USB host / OTG is not supported by Nexus 4. It needs hacking from both hardware and software aspects to make it work.

Hardware

In order to use USB OTG devices on Nexus 4, you have to use a special USB OTG Y-Cable like this one:
 
Because Nexus 4 Micro-USB host doesn't have power supply to the USB devices, so we need to use external power supply. We bought an 3000mah power bank like this one:
 

 That's it. Next we need to take care of the Android system.

Software / Android ROM

The built-in kernel of Android system doesn't have USB-OTG support. Yes, you are right, I don't understand why they cut off such useful feature, either. Maybe for power saving, lower cost? Anyway, it's not a problem for the hackers!

WARN: The following operations needs some basic hacker skills such as flashing a now system ROM, use of adb and fastboot. Even you do have that kind of skills, you may also turn your Android to a brick. So read carefully before you start hacking.

  1. Install the recovery image
    The recovery image is used to take care of the operations such as wiping the data partition, install a new ROM/zip file when your Android phone is in recovery mode. I followed some tutorials online, then I decide I'll use the CWM recovery. You may also try TWRP recovery which is also frequently used.
    Download recovery image for your device: http://clockworkmod.com/rommanager
    Open a terminal, reboot the device into fastboot mode by typing
    adb reboot-bootloader 
    Or power off your device then press volume up, volume down and power simultaneously.
    Then flash recovery image onto your device by using the following command:
    fastboot flash recovery recovery.img

  2. Install Cyanogen system from recovey
    In order to get a rooted system (which is not necessary in my case), we downloaded and installed Cyanogenmod system: http://download.cyanogenmod.org/?device=mako&type=stable. At first I download newest/nightly ROM, but it doesn't let me using the WiFi after I flashed the ziddey-OTG kernel. Then I just use the stable Cyanogenmod version: cm-10.2.1-mako.zip (Android 4.3.1). Then use the recovery to install the new ROM.
    Reboot to recovery mode. Then select wipe data/factory reset. Then you can install zip from sdcard or from sideloading. You just keep the system image on your PC and issue the following command after you select install zip from sideload:
    adb sideload cm-10.2.1-mako.zip
    

    Then you'll have a Cyanogenmod system.
  3. Install ziddey USB OTG kernel
    ziddey-OTG kernel is a patch to the Franco-CM system to enable kernel OTG support. You can download the right version on this page: http://forum.xda-developers.com/nexus-4/orig-development/usb-otg-externally-powered-usb-otg-t2181820. And use adb sideload install the zip file.
  4. Try OTG!

Show Cases

Now it's time to show off your OTG devices!  First I use thumb USB drive on my Nexus 4.
Displaying photo.JPG
After plug in, you can check your storage from Settings->Storage->USB Storage.
The main reason I want to use OTG feature of Nexus 4 is for my fingerprint reader project. We have U.ARE.U Fingerprint Development Kit and need to use digitalPersona 5160 fingerprint reader on Nexus 4. Here is the screenshot showing it works on my Nexue 4:


Debugging with ADB from Wireless Connection

Want to debug the USB device using gdb but the micro-USB I/F has already been occupied? You can use the wireless network to make the connection from your PC to Nexus 4. First you need to turn adb to tcpip mode instead of using USB. Connect your phone to PC using USB cable, issue 'adb usb' to set adb running in USB mode first. Then 'adb tcpip 5555' to setup adb in internet mode. Then check the IP address of your android device on: Settings->About phone->Status->IP address. Connect adb host to device 'adb connect IP_addr'. If succeed, you'll see
$ adb devices
List of devices attached 
#.#.#.#:5555 devic
Details about adb wireless usage, please refer to: http://developer.android.com/tools/help/adb.html

Acknowledgement

Cyanogen Team:
[1] Install recovery image and Cyanogen system, http://wiki.cyanogenmod.org/w/Install_CM_for_mako
[2] Cyanogenmod ROM: http://download.cyanogenmod.org/?device=mako&type=stable

AndroidCentral
[1] USB OTG on Nexus 4: http://www.androidcentral.com/android-advanced-usb-otg-nexus-4
[2] Nexus 4 Unlock & Root: http://forums.androidcentral.com/nexus-4-rooting-roms-hacks/224861-guide-nexus-4-unlock-root.html

XDA Developers
[1] Externally powered USB OTG - Nexus 4: http://forum.xda-developers.com/nexus-4/orig-development/usb-otg-externally-powered-usb-otg-t2181820

No comments:

Post a Comment