How can I use adk Library - android

I'm new to android and trying to learn hardware interaction in android
have to root to install driver of hardware.
can I use adk library for custom hardware development.
As shown here,
if using accessory mode, then accessory must power the bus.
But as specified here,
accessory can be anything as keyboard too.
So i got confused: how can a keyboard power the bus?
Please help me out.

You misinterpreted those sites.
When you want to connect something like a keyboard, your android device must be in host mode. It will provide power to the keyboard.
The android device will only attempt to draw power from the other device if the other usb device acts as host.
In USB host mode, the Android-powered device acts as the host.
Examples of devices include digital cameras, keyboards, mice, and game
controllers.

Related

How to make android device as slave and read the slave data from iot hardware as Electric Imp, Arduiono or even PC?

I am looking for a solution where my Android Device is connected to IoT devices such as Electric Imp, Arduino or Windows PC via USB.
So the requirement here comes that I want to write some data(text or binary data) at my Android USB port so that the other IoT devices which are connected via USB are able to read that data.
Android Device will act as a slave and IoT devices will act as master which will read the information.
Note: There is no connection with WiFi or Bluetooth, only via USB it is needed.
This is in practical terms likely a bad idea as an architecture, but if you want to pursue it is is exactly what the Android USB Accessory Protocol was designed to enable.
You need an embedded device capable of being a USB host, the reference implementation was the Android Accessory Development Kit (ADK) thought that hardware was never a great choice and obsolete as even in it's era ARM MCU's with native USB host support were already common.
Note that this method is opposite that of "USB OTG" where the Android devices is the USB host. Although Accessory mode requires a more capable embedded hardware (with host vs only device support) Accessory mode is more widely supported by Android devices, some of which cannot function in OTG mode, and many of which rapidly run down their battery when doing so. But both suffer from the physical USB connection to a sculpted-for-a-hand phone often making an intermittent and easily damaged connection in comparison to the sorts of connectors typically chosen for interfaces which will be semi-permanently connected.
You would probably also be able access the usb data lines directly as a serial connection that carries the raw information.

Is it possible to use OTG Host Negotiation Protocol to change modes while connecting two devices?

I have two android phones connected with an OTG cable. Obviously, the cable forces once phone into host mode and the other becomes the peripheral. I would like to be able to dynamically alternate the host/peripheral status of the devices without switching the cable around and the OTG HNP spec seems to indicate that is possible. I found some further information on it here but I'm not sure where to go with it - https://android.googlesource.com/kernel/msm/+/android-msm-bullhead-3.10-marshmallow-dr/Documentation/usb/msm_otg.txt
Yes, it is possible. Good find on the very technical documentation. However the Developer.android.com site and the USB.org has more information regarding implementation:
USB accessory and host modes are directly supported in Android 3.1 (API level 12) or newer platforms. USB accessory mode is also backported to Android 2.3.4 (API level 10) as an add-on library to support a broader range of devices. Device manufacturers can choose whether or not to include the add-on library on the device's system image.
Link
As far as I can tell Host negotiation always favors traditional Host controllers like computers. Android devices have traditionally been USB accessories. However a very complicated situation arises when you have a hub with a host (like a PC) and another accessory plugged in. It seems like there is no way to settle the dispute about which device should be a host the Android or the PC. For instance I plugged in a host PC to a Android device with a HUB attached and a gigabit ethernet dongle. I could never establish a connection with the dongle. In fact the HNP never seemed to take place.
Finally, the documentation seems to suggest that the Host is responsible for operating the USB Stream. What seems most promising is the documentation Here which establishes the direction of a USBEndpoint.

How to detect USB port on android?

I'm developing printer application based on Android phonegap.Now i hard coded the data and sent it to the printer.It's working fine.But my requirement is data will come on from the taxi meter via USB cable.How can i detect that data coming port?
What you're most likely looking for is the Android Open Accessory Development Kit. Keep in mind the following:
Note: Accessory mode is ultimately dependent on the device's hardware
and not all devices will support accessory mode. Devices that support
accessory mode can be filtered using a <uses-feature> element in
your corresponding application's Android manifest. For more
information, see the USB
Accessory
Developer Guide.
Another thing to be aware of is that if your other device does not support Accessory mode, you can either make it support accessory mode (you haven't mentioned if this a homebrew or commercial device), or root your Android device and then pretty much anything is possible.

How to generate a video signal from Android device via USB?

Is it possible to create an application for Android, which can generate a video signal (HDMI or VGA) via USB?
Any Android device has miniUSB port. Theoretically it's possible to create a small commutator device on microcontroller or microscheme, which will be a USB-host for Android device. You'll connect Android device with commutator and then connect commutator with monitor.
For example, the scheme looks like: Android phone -> commutator (USB-host) -> TV/Monitor.
Summary, I need to connect android phone with TV via miniUSB port. I found soft which can use miniUSB -> HDMI cable, but those apps only for Motorolla Droid and HTC Evo.
I'll glad to get links to existing apps or projects on that theme, to info about software generation HDMI-signal and connecting Android devices with another devices.
Thank you and sorry for my bad english!
Not much chance of that working out: lacking an appropriate converter chip there is no way you will be able to generate an HDMI or DVI signal using only the 4 pins on a standard USB or mini-USB port. You will need to look into building a converter box that does the right thing: something like http://wiki.chumby.com/index.php/What_is_NeTV.
Those cables are not doing 'HDMI' generation - basically, some phones use the extended standard which has more than just USB in the socket.
Specifically, OMAP3/OMAP4 based phones (Droid, Evo) have an onboard HDMI/DVI chip - the cable just breaks out the pins.
I'd look at Open Accessory Development Kit for inspirations about what can be done in hardware.

Android USB host-to-serial connection?

Apparently with Android 2.3.4 and 3.1 one can now access USB accessories.
I have a Ardupilot Mega (based on Arduino) board with a USB cable connected to my laptop, and I can connect to it using a simple serial communications program over COM7 and 115,200 baud. This allows me into the command-line interface, and I can issue commands and get logs.
Is it possible to write an Android app that will communicate over USB to my Ardupilot Mega board?
I've seen many similar threads, but most of them were pre-USB host.
usb-serial-for-android is my open source library written for exactly this need. It supports FTDI and CDC-ACM usb serial devices using Android's USB host support; no root or ADK necessary. It can talk most Arduinos.
The project is still in its early days, but the basic support has worked well enough for several projects. There is also a discussion list where you can get help.
Unfortunately the library from mik3y's answer (see here: mik3y/usb-serial-for-android) seems to be long dead. It has many problems and waiting pull requests. Also the LGPL licence prevents anybody to fork it and maintain it.
But don't lose your hope, there's a working replacement and it's under the MIT licence. felHR85/UsbSerial.
EDIT: I found a maintained fork of mik3y's library. But the licence or readme is not updated, so I suppose the owner doesn't have a connection to mik3y and simply took it and improved it. I hope he won't get into any trouble because of the licence, because we need this library. See kai-morich/usb-serial-for-android
EDIT2: It seems that all of these libraries are maintained again, mik3y joined forces with kai-morich and they're working together now.
EDIT3: mik3y/usb-serial-for-android is under MIT license now. And still maintained in 2022.
Maybe. Check out the Android Open Accessories announcement on the Android Developers Blog. The Arduino Mega ADK is compatible. Not sure about the Ardupilot Mega.
From their page:
The Android 3.1 platform (also backported to Android 2.3.4) introduces
Android Open Accessory support, which allows external USB hardware (an
Android USB accessory) to interact with an Android-powered device in a
special "accessory" mode. When an Android-powered powered device is in
accessory mode, the connected accessory acts as the USB host (powers
the bus and enumerates devices) and the Android-powered device acts as
the USB device. Android USB accessories are specifically designed to
attach to Android-powered devices and adhere to a simple protocol
(Android accessory protocol) that allows them to detect
Android-powered devices that support accessory mode. Accessories must
also provide 500mA at 5V for charging power. Many previously released
Android-powered devices are only capable of acting as a USB device and
cannot initiate connections with external USB devices. Android Open
Accessory support overcomes this limitation and allows you to build
accessories that can interact with an assortment of Android-powered
devices by allowing the accessory to initiate the connection.
Note: Accessory mode is ultimately dependent on the device's hardware
and not all devices will support accessory mode. Devices that support
accessory mode can be filtered using a "uses-feature" element in your
corresponding application's Android manifest. For more information,
see the USB Accessory Developer Guide.
The following list of distributers are currently producing Android
Open Accessory compatible development boards:
The Arduino Store provides the Arduino Mega ADK (in EU nations or
non-EU nations) that is based on the ATmega2560 and supports the ADK
firmware. DIY Drones provides an Arduino-compatible board geared
towards RC (radio controlled) and UAV (unmanned aerial vehicle)
enthusiasts. Microchip provides a PIC based USB microcontroller board.
Modern Device provides an Arduino-compatible board that supports the
ADK firmware. RT Corp provides an Arduino-compatible board based on
the Android ADK board design. Seeed Studio provides an
Arduino-compatible board that supports the ADK firmware. SparkFun's
IOIO board now has beta support for the ADK firmware.
You can check out the library described in Slick USB 2 Serial Library.
It enables common USB-to-serial adapters to work with Android devices that have USB host mode without needing to root.
http://slickdevlabs.com/
I am currently using the library in my own app, however I think you can get away with just the app that slick has on the market. There are two free apps and one is the "pro" version of one of the free ones; search slick usb in Google Play.
It does use HOST mode and you can change the baud rate to whatever you need.

Categories

Resources