5

From a year ago, Is there a way to communicate with USB devices on Android? this didn't look like a common requirement, but tablets have evolved, and hopefully, the OS has, as well.
I need to operate a simple USB relay card from my Curtis LT8025 tablet, currently running 2.1 patched.
I'm also a newcomer to both Android and java, so relatively clueless!
No need for bi-directional communication, just a simple serial command out to the device.

Any suggestions?

Thanks!
Dave

Community
  • 1
  • 1
DBell
  • 61
  • 1
  • 1
  • 6
  • 1
    The ADK was released a few days after you asked this - http://developer.android.com/guide/topics/usb/adk.html – James Moore Aug 05 '11 at 15:35

3 Answers3

2

Sadly, there is currently no standard API to achieve wired communication with Android devices. I was facing a similar issue a while back (see Android: Communicating with a USB device which acts as host ).

I was able to successfully implement the solution provided by CommonsWare. Leave a comment if you need more help regarding this and I can provide details.

  • Edit (more details) -

Basically, I narrowed down to two possible solutions for this problem:

  1. Modify the Android source itself to include custom drivers for whatever purpose you need and install this in your tablet. Since its mostly based on Linux, if you develop the drivers for Linux, the same can be used in Android with a little modification. This solution is simpler to develop, but not practical commercially if you are not providing the tablet/phone yourself.

  2. Make your USB device act as an host and implement the ADB driver/command-set in your device. When connected, you can issue "adb forward" to forward tcp ports so you can interact with your Android apps and have two way communication between the device and the app.

I used the second method and it works flawlessly. But its only practical if you are making USB host devices. for USB slaves, first method is the only way I recon.

Community
  • 1
  • 1
Vaayu
  • 466
  • 4
  • 8
  • @Vaayu - yes, please! I'd appreciate any pointers you can offer. The tablet has a detachable USB (and Ethernet) hub. I use it for a flash drive, so presumably, some driver-level support is there, if I can locate it. Dave – DBell May 09 '11 at 14:21
  • 1
    Copy /proc/config.gz off the device and gzip -d it, then look and see what (if any) usb device drivers beyond mass storage are provided to go with the tablet's shipped USB host capability. Also look in /lib/modules/whatever. For a device not supported there you'll have to compile a driver - which is plausible if you have root and kernel sources. If the tablet supports usb keyboards, and you have root, maybe you could do something by pretending to be a keyboard and then talking SPI by bit-banging the keyboard LED's, and thus avoid compiling a driver? – Chris Stratton May 09 '11 at 17:59
  • @chris - Is it possible to talk directly to a \dev port? My tablet implements \usb1 \usb2 \usbdev1.1 \usbdev1.3 and \usbdev2.1 – DBell May 09 '11 at 21:39
  • That may be something to look into - for example the adb driver for talking to phones from linux development machines seems to work in userspace using /dev/bus/usb - adb is in the "core" package on android.git.kernel.org if you want to have a look (both host and client side are built from the same tree with a lot of conditional compilation) – Chris Stratton May 09 '11 at 21:50
  • @chris Counldn't locate /proc/config but under /proc/devices I found the following character devices: 180 usb 188 ttyUSB and 189 usb_device – DBell May 09 '11 at 23:09
  • I guess what I am wishing for is something as simple as I just saw here: [link](http://labs.ti.bfh.ch/gecko/wiki/tutorials/gecko3com_simple_tutorial) -- 'echo "*idn?" > /dev/usb_device' and 'cat /dev/usb_device' – DBell May 10 '11 at 04:50
2

If you are using a serial device and have the ability to talk to it over native serial, you might want to consider IOIO (see http://ytai-mer.blogspot.com/2011/04/meet-ioio-io-for-android.html for more details).

Femi
  • 64,273
  • 8
  • 118
  • 148
  • 1
    They seem to be using the second method I mentioned. Nice idea; packaging a host module with ADB embedded. Looks well polished. Very excellent if you don't want to include your own USB host module. – Vaayu May 10 '11 at 01:01
0

I'm building an Android custom system. I did connect several devices on the USB. I looked to connect a device on the OTG port, the one that usually gets out of a tablet on which you use ADB. I gave up. This is a nightmare. I don't think you can use ADB on the OTG USB that is currently a device and expect to be able to use another device like a USB to serial converter. That means that you loose the whole ADB toolchain for debugging when you want to use the port as a host. On top of that, the USB OTG drivers you have for your tablet was probably not very well tested in host mode since it's not really used that way. So lots of headakes.

The simple way that I found was to use the second USB port on the CPU. This one is a plain HOST port (unfortunately limited to 12 Mbit/s). Unfortunately, I don't know if there are any tablet out there with 2 USB port available from outside (One OTG and one host).

If you get a set-up with two USB port (one HOST) then it's possible to compile as a module (drivername.ko), a usb to serial converter. There are several chipset supported in the kernel source tree and I already used a few of them and it works.

hope this bit of info is helpful.

Sylvain Huard
  • 1,378
  • 6
  • 18
  • 29