Is it possible to access the USB port on Android phones? (Droid X for example)
Here is my usage case:
Have a USB device attached to the Android phone. The phone listens for data on this USB device. (The USB device is connected to a USB->RS-232 converter that has I/O attached to it)
This would be slick if possible. Does anyone know if this is possible?
Would be slick, yup. Not possible though. There's a feature request for it: http://code.google.com/p/android/issues/detail?id=738
Actually it is possible on a lot of the phones if you are able to install a new kernel with a USB host driver and rig up a custom cabling scheme to provide usb bus power to the device as the phone won't. A few phones even shipped with this capability already live.
I don't know if the Droid X specifically ships with this already, can have it added (if you are able to flash kernels), could have it added but no one has written the host driver yet, or is missing the hardware capability.
You also would need to enable the appropriate usb serial converter device driver (identified by experimenting with the device on a desktop linux box), but that's probably already in the kernel sources and just needs to be selected in the config. You may also need to create a device file for the /dev/ttyUSB0 or whatever and give it permissions appropriate to the application that wants to access it. (This requires root, but if you can reflash the kernel, you can get root)
If you want to pursue this, search the android kernel google group for posts about USB host mode.
One serious downside to putting the USB into host mode is that you loose the adb interface into the phone, which makes working on your projects hard. You'll probably need to either build an adapter for the low voltage debug serial port if there is one (as on G1, mytouch, etc) so you can get a console shell (or just use that instead of USB to talk to your peripheral) or at a minimum set up an ssh and sftp server on the wifi.
Since you want serial anyway, another option people have used is to get a bluetooth-to-serial module from an outfit such as sparkfun.
A bluetooth to serial adapter might solv your problems.
You can find one at https://www.sparkfun.com/products/582. Boards from other companies are also available for example on ebay.
Related
Device : Google Nexus 5 (Un-rooted)
Host Machine : Window 7
I want to Access Android Device as a Modem (using COM or Modem Port) and eventually pass AT Commands using HyperTerminal/Teraterm.
So after connecting the device to a Windows Box, The Device gets detected under Device Manager, but doesn't show any COM Port (other than the default COM0).
On right click and update driver, It shows it cannot find drivers.
I have tried the following options, but no luck with any.
Tried this on a rooted Nexus 5, but doesn't expose which /dev/smdX to use. Tried all combinations, didn't work.
Tried the Google USB Drivers from the Google Android's Website. No changes.
From here. I Installed drivers from LG Electronics, No changes in COM Port.
Universal Naked Driver helped me get to ADB Shell interface, but
thats not what I want.
In all of the Above procedure USB Debugging was enabled (Just saying).
I also heard the phone has to put into Modem mode to fire AT Commands.
If so, How do I do that ?
Or Is this a device driver Issue ?
Conclusion:
I want to access the Modem of the Android Device and fire AT Commands to it.
Could you please tell what am I missing ?
Any help on this would be really appreciated.
It's difficult to give an exact answer to this question, because it depends on how the manufacturer has implemented the device drivers. Unfortunately, there is a lot of information that isn't in the public domain.
It is possible, that the manufacturer has implemented some code to convert the device to a modem. Doing this yourself is device-specific, and proprietary. You might be able to get hold of a converter, for example bundled with the manufacturer's dashboard application for the PC, if such a thing exists.
Some devices don't expose the modem port at all. They may be visible as a network adapter, or as an always-connected LAN connection. If the device is visible as a network adapter, then you can access it via Windows Mobile Broadband API, or via MBIM for some newer devices.
To check if the device is visible as a network adapter, and get information about it, open a cmd box and type
netsh mbn show interfaces
Windows Mobile Broadband API doesn't give as many details as a good AT command set, but performs basically the same functions. MBIM is an industry standard interface with similar functionality, available on the Windows 8+ desktop via the Mobile Broadband DeviceServices API, for devices that support it.
If the device shows as an always-on LAN connection, there is probably a proprietary, high level interface for mobile functionality.
Driver behaviour can differ for different operating systems. If you have the chance to try the device on Windows Vista, 7 and 8, you may see different behaviour.
Hello fellow programmers,
I've got a question regarding the realisation of an app which should be able to send AT commands via USB to a connected hardware.
Is it possible to send these commands over USB without root? I would not want to have rooted phones as target market as I want the application to be useable for the average Android platform. Is there any solution out there which you know and can give some links to that?
cheers
herom
If the phones support the optional usb host api then likely yes. You will probably need a USB-OTG style adapter cable which grounds the extra pin to help put the phone in host mode.
If not, no, unless you have one that can be made a usb host via kernel modifications (requiring root, likely kernel reflashing, and possibly a special cable to inject power)
I would like to turn my computer into an Android accessory using my application. So instead of a specialized hardware this will be just PC that will switch the phone into accessory mode, thus launching some Java app on the phone associated with the host hardware and create a communication channel.
I've found a sample code (plus some Java Android app) to do this on Linux using libusb. It works by "opening" the phone using the standard VID and PID. Then it sends a command to turn on the accessory mode, along with the metadata like model, version etc.
If the phone supports accessory mode it'll then disconnect and reenumerate with a different PID. The sample code then checks if it did and opens the new device.
However, I'm trying to get this running on Windows. I've found a few USB libraries, like LibUsbDotNet, but they all seem to require the device using a WinUSB/libusb driver. I've used a tool in LibUsbDotNet to generate a libusb driver for my phone, installing it over the old generic removable drive one. But this means I now can't access the phone as a removable drive when I want to, so this is not a solution.
Is there a way (preferably a library) that can open any connected USB device based on VID and PID, and then send a few raw commands to it?
After that the device will reenumerate with a different PID, which I can use to create my own WinUSB driver, so that is not an issue. I just need to inject some commands through/around the default driver to turn the accessory mode on.
(I would prefer .NET solution, but anything Windows is fine and I can write my own interop wrapper)
I am also searching for a similar solution. I tried the Linux version, with libusb, with little hickups, was able to communicate with the device.
While searching for the solutions on windows I tried many hacks.
If need to communicate with device in ADK mode, I need to send several Vendor Commands, now this I need to do while its connected in Mass Storage mode. This is impossible using Mass Storage driver. I tried to get the Node handle of connected USB device to see if could send vendor command, but there I could only file Get Descriptor requests. So I went ugly method, replaced mass storage driver with libusb-win32, to see it could do the same, YES, it worked, but not at all a good solution.
Still searching..
I want to make a remote control for my tv using my android phone. I plan to connect my external infrared device to the phone via usb. An application on the phone should do the processing and send out commands to the infrared device via usb. Is it possible to explicitly access the phone's usb interface from the application to send/receive data? The data will just be short binary strings. In one instance, the phone should be the host and in the other instance, the phone should be a client.
For this to be possible, I believe you will need a USB host driver for your phone. While these drivers are available for some devices (see link), you'll need to have root access to install them, and it won't be easy. For instance, here's a description of how to install a USB host driver for the Nexus One.
Given how few devices support USB host, there seems to be very little documentation one how one would actually go about accessing a specific USB device. The second link above, to the Nexus One driver, provides some sparse details. Beyond that I can only assume that you'd need to write your own driver for the specific device, which would probably be similar to standard Linux USB driver development. This XDA thread (started by the author of the N1 USB host driver) is probably the best source of information you'll find.
Unfortunately the short answer is that what you want to do will be very difficult, and you certainly won't be able to distribute your work easily if you do manage it. Good luck!
What would be the best way to access the USB as a serial port on an Android device (HTC Magic)?
I am thinking about an OBD-II interface. Can I do this on a standard phone or more likely will I need a modified firmware?
According to this post, Matt Porter presented a review of Android at the Embedded Linux Conference Europe. I mention this mostly because of the example used to describe the current state of Android.
"Just one more practical example: You cannot even plug a USB drive to an android system, since /dev/sd* is not an expected device name in their hardcoded hotplug management.
Executive summary: Android is a screwed, hard-coded, non-portable abomination."
I'm sure someone's working on it, but I'm afraid for now you're out of luck unless you're willing to go low-level and edit the OS.
PSFreedom (project to jailbrack Playstation 3) has list of controllers which support usb host mode which then translate to supported Android devices.
My own expirience is that usb host works on HTC Dream/G1 without problems.
For OBD-II I would suggest bluetooth ODB-II dongle which side-stepps problem with usb host adapter.
Depending on the USB chip in your particular phone, it may be possible to rebuild the kernel to support USB Host mode or USB On-The-Go (Host + Gadget modes) instead of the normal USB Gadget mode. I've found some people speculating that it could be possible on the HTC Dream. Assuming you could reconfigure the USB port in Host mode a USB to serial, ODB-II, or CAN should be doable.
From what I can tell Android is Linux of some sort, to have USB device which would apear as serial port, you should write a driver for that device. I don't know much about OBD-II interface but i am guesing they use some sort of USB driver for windows, same is for android, not mentioning the application to handle the driver.
I don't think the current Android devices can act as a USB host only as a USB device when attached to a host. So using the USB port as a serial port is not likely.
Get a hostmode kernel for your device and you can use python for android and the pyserial library to talk to the serial over USB. I did this with Huawei Ideos U8150 (here is the post) for a loopback test.