I have 2 Android devices, which I would like to connect with a USB OTG cable and have back-and-forth communication between the two devices. From what I understand, one Android device will act as the USB Host (Nexus 7 running 4.4) and the other Android device will act as a USB Accessory (Galaxy Nexus running 4.2.2). I've tried googling around for an answer, but I can only seem to find articles explaining how to connect an Android device to a USB accessory (like a USB mouse or keyboard), not how to treat an Android device as the USB accessory itself.
So, following this page, I have configured an app on the Nexus 7 to be the USB Host. I can find the connected Galaxy Nexus based on its product id & vendor id, form a connection to the Android Open Accessory Protocol and successfully connect over USB. From what I can tell, the Nexus 7 can successfully send bytes to the Galaxy Nexus.
My question is how to access this connection on the Galaxy Nexus side. I have added permissions and the USB filter into the manifest, so the desired app opens on the Galaxy Nexus once the USB connection is established, but I can't figure out how to receive the data coming in from the Nexus 7 or how to send data from the Galaxy Nexus back to the Nexus 7.
Any help would be greatly appreciated! Thanks!
See my SO answer here.
If you want the Galaxy Nexus to act as the USB Accessory, then it must implement the Android Open Accessory protocol. An Android Accessory is a usb host, so technically you would have two hosts (assuming you managed to implement correctly the AOA protocol on the Galaxy Nexus), which is clearly a deviation of the USB spec.
Related
I want to build a device with sensors (either with an Arduino or a homemade circuit with a microcontroller) and I want to send data from it to an Android device via an USB cable. What is the library required to connect devices via USB? Is there any documentation I could read for it? The problem is that whenever I search for this I only get results about the ADK and their board, not for other devices.
Are there things I should know beforehand? I'm not new to either field, but it's my first project with the two connected.
Thank you.
The first thing to check is if your Android device is equipped with USB host interface. In such case you can connect a regular USB device to your Android and use this API to communicate with the device.
However, typical Android device (virtually every mobile phone) is only equipped with USB device interface, for connecting to PC or another USB host. In such case you have to use the Android's USB Accessory support. The most important idea behind Android Open Accessory protocol is that it swaps (logically) USB device and USB host roles. It's the USB host that looks for the device with particular vendor/product ID, selects particular USB protocol interface, and then simply uses the in/out bulk endpoints found to communicate - pretty smart, isn't it?
To build Android Open Accessory compatible device you then need a CPU with USB host interface. If you want to use Arduino, this shield is probably a good starting point, given its firmware implements Android Open Accessory Protocol already. There are some example applications as well.
This works great on my Nexus7 which is connected over the OTG to Arduino Mega.
Android USB host serial driver library for CDC, FTDI, Arduino and other devices.
Hope it helps!
You have two solution
1: Your Arduino board act as a USB host and power the Android device.
With this solution you have to implement and USB Host stack on your Arduino board and must implement Android Open Accessory Protocol. Your Arduino board must power the Android device. Then you app must use the USB Accessory API to communicate with your board.
Avantage:
work with almost all Android Devices (no need for an USB Host port on Android device)
Disavantage:
The device board is more complicated (must provide power for both devices)
Firmware is more complicated (must implement USB Accessory mode)
2. your Arduino board act as a USB device and the Android device powers
you board.
With this solution your do not have to implement a specific USB protocol. Your board will act as a standard USB device. Since you act as a device you can power your board directly from the USB cable (the Android device will power itself and your baord). To communicate with your board you will use the USB host API of Android.
Avantage:
the device board is very simple
the firmware is simple and easier to debug (you can even test it with you PC)
Disavantage:
Works only with Android devices that have an USB Host port
On most device you will need a specific cable or adapter (ex :otg usb host cable)
I have experience with solution 2, and it works pretty well. All source code for the Android source is available from the link below. I have verified that it works with sensor devices from the company where I work on the following Android devices:
Samsung Galaxy S3
Acer Iconia tab a200
Asus Tranformer Pad TF300T
But it should work on most tablets and recent phones you can see this post if you want look at our experience.
I was wondering if the sprint galaxy nexus supports the usb host mode? As stated here it is supposed to be available on android versions above 3.1. The galaxy nexus uses ice cream sandwich(version 4+) so it should have it. This video shows someone using the galaxy nexus with a usb mouse attached, so the stock galaxy nexus version should have this capability. I was just wondering if Sprint changed the kernel in someway that disabled the usb host mode functionality. This site states that the galaxy s from sprint has "Mass storage device, USB Host, USB charging" as a feature but for the galaxy nexus from sprint the only feature listed is "USB charging."
I only realized this might be a missing feature because when I tried to set up a small test app using the Usb host mode api no device that I connected was ever recognized. I tried pluggging the device in after device startup and before device startup. I was reading the logcat wirelessly as is defined here so I could moniter what would happen when I was plugging a usb device in and removing it. Logcat displayed nothing. Any explanation or links to other sites saying that the Sprint galaxy nexus does or does not support usb host mode would be much appreciated(only Sprint, I beleive Verizon does support it, but I have a Sprint test device). Thanks.
Stock Galaxy Nexus works for me with USB Host mode. Been able to use the Ant+ receiver with no problems.
we know the Samsung Galaxy S3 will have USB host but do you guys have any knowledge if also the USB APIs will be public/accessible or blocked on the Samsung Galaxy S3 to allow developing apps requiring access to these APIs?
It will be similar to other SGs.
Same access through the android OS/(Linux if rooted) as normally.
I have a galaxy S3 and apps like 'USB Host Viewer' and 'USB Host Controller' are able to see slave devices just fine with an OTG host adaptor connected.
I'm going to assume this means that the APIs are enabled but as I'm yet to find a usb driver that will l
We're looking to start some development which will require USB Host functionality on Android. We were going to use the Samsung Galaxy 10.1, but this question suggests that Samsung have removed this api.
What tablets definitely have this working fully?
The US version of the Motorola Xoom Wifi-only (MZ604) is your best shot. This is a GDE (Google Device Experience) which means that it is a clean Android version. In other words Motorola has not done any modifications to Android and the USB-host API is intact.
Check my thread on the motodev forum.
I can't verify the Samsung has removed the USB API from the Galaxy Tab 10.1 with OS 3.2, but I can verify that its full functionality is not present.
The Tab apparently has a special handler for HID devices, and a number of USB devices do not enumerate at all.
I use two:
Google Galaxy Nexus OTG works, while I initially assumed it does not by using the wrong cable. There is OTG cable and there is micro USB device cable, both fit into connector but they are not the same.
Lenovo Thinkpad tablet just has the additional normal size USB connector, same as ordinary laptop. It is for USB host devices, and these devices work when connected.
I have a general and quick question and since you can never get a hold of a developer at Google, I thought I would post the question here...
Can anyone tell me, if we want to use our phones to connect via USB to a missile launcher made by dream cheeky As suggested on the USB or ADK section of the developer's website, would we still need and Arduino board or a board that Google presented at Google I/O 2011?
I guess I am asking, in short, can we directly hook our phones to another device via USB, and compile a program via eclipse or with the ADK to have it run? or will we still need a board in between the phone and the device we want to connect USB...
Thanks in advance,
Richard
In ADK, the Android device acts as a USB Device and the Android accessory acts as a USB Host. When an Android accessory is attached to the Android device, the Android devices switches to "accessory mode (as described in ADK)". If your Android device has USB host already, still it will switch to accessory mode and acts as USB Device instead of USB Host. Actually, the motivation behind ADK is to make each Android device to work with any Android accessory. Accessory mode eliminates the need for USB host, since only few devices has USB host feature (It is costly).
So, if you want to work with ADK, you need an development card with USB host.
you do not need an ADK board if the device that you are connecting to your Android device is acting as the USB Device and your Android device is acting as the USB Host. This is the case with the Dream Cheeky USB missile launcher. You can connect a missile launcher directly to the device and control it. USB Host is only supported on Android 3.1 devices and later.