Tuesday, February 4, 2014

Android USB Host Mode, step-by-step

When your Android-powered device is in USB host mode, it acts as the USB host, powers the bus, and enumerates connected USB devices. USB host mode is supported in Android 3.1 and higher.

To use Android devices as Host, a USB OTG (On-The-Go) cable is needed, to be connected to Android side.

I'm do some exercise on Android USB Host Mode, here is the list of the related posts.


Anonymous said...

Muy buenos tutoriales, te queria hacer una pregunta:
Estoy realizando un proyecto con arduino y android y tengo un problema, resulta que cuando conecto el arduino a la tablet esta lo reconoce pero si desconecto el arduino y conecto otra vez ya no lo reconoce, como logro que reconozca automaticamente el arduino sin salirme de la aplicacion.

Saludos desde colombia

Javier Redondo said...

Hello Andr.oid Eric,
You have a nice examples!!
Have you considered an application to pass data from the arduino to smartphone?

Andr.oid Eric said...

Hello Javier Redondo,

I have tried. But unfortunately, I fail to program Android to receive data in USB Host mode.

May be I will try later.

sunny teki said...

Thanks buddy helped a lot

Judy said...

hey, blogger thank u so much for posting these fantastic posts. Currently I'm trying to read out Arduino serial data to Android phone as a monitor. I used part of ur code, and can read out some data, but the usb connection is very unstable. It shows connect and disconnect all the time. I just put a new thread to get the data and use message to send the data to handler to update the ui,
like this,
public void run(){

byte[] buffer=new byte[4096];
final int ret=usbDeviceConnection.bulkTransfer(endpointIn, buffer, buffer.length, 0);
byte[] buffer2=new byte[ret];

String data = new String(buffer2);

//String data=buffer2.toString();
Message m=new Message();
Bundle b=new Bundle();
b.putString("data", data);
b.putInt("length", ret);
//b.putByteArray("abc", buffer2);
mHandler.postDelayed(this, 200);
} }
Handler mHandler=new Handler(){

public void handleMessage(Message msg){


Bundle b=msg.getData();
String data="";
//int length=b.getInt("length");

Andr.oid Eric said...

hello Judy,

I'm not sure your case. In my trial experience, the problem of connection unstable may be caused by power consumption. Maybe you have to check how much current needed for your Arduino device.

Or you can try on different device, and also charge-up the device before test.