Send AT command from Android to USB port - android

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)

Related

Android phone usb

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!

Android USB HID Device

Does anyone know how to configure an Android device (tablet) to appear as a USB HID device when connected to a PC?
Is there any other way of getting data from the tablet to the PC (via USB) other than writing it to a file, and have the PC retrieve the (updated) file from the tablet which is acting as a 'mass storage device' for the PC?
Can USB carry a TCP/IP end-end connection?
Using a tablet as a high-end intelligent 'keyboard' or 'mouse' or similar device would be immensely powerful, and open up lots of possibilities. Controlling a model railway layout is the end I have in mind.
Thanks
It's possible to do this using the linux gadget framework http://www.linux-usb.org/gadget/ using a custom composite USB device. The gadget framework is part of the Android kernel source tree by inheritance from Linux.
Unfortunately, Android has its own customizations that restrict the ability to dynamically register new USB gadgets so you will need to patch the kernel source tree for your particular device and add your HID gadget (otherwise you could create a module and load it that way) to the supported Android list.
I have done this before and will update this answer to contain more detail if there is interest. Unfortunately I lost the code so I will have to start from scratch.
If I set up a web server on my phone and enable usb tethering, I can access that server from my PC. If that's not enough for you, this might help: https://market.android.com/details?id=usbwebcam.application&hl=en
I'm running cyanogenmod on a Desire CDMA (BravoC)
Let me know what you find out; it would be pretty handy to use my phone as a USB keyboard in the field. An android server with a PC client is gonna be easiest though.
Have a look at Android Open Accessory Protocol 2.0. This could help you out.

USB Android I/O

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.

Android: Communicating with a USB device which acts as host

We have made a device which can act as an USB host or slave and processes the data it receives. I want to use the Android phones to send the data to it via USB.
My research leads me to conclude that we cannot use Android devices in USB Host mode without modifying the hardware or OS. Doing so is not an option as this is going to be a commercially deployed device.
However, I couldn't find any information on using the Android phone as a slave. This is already technically possible because it can connect to the PC in a similar configuration. Can we do the same via an application? If so, any information on how to achieve this will be greatly appreciated. I have full access to our device's embedded system, so custom code there should not be a problem.
This is already technically possible
because it can connect to the PC in a
similar configuration.
Only for things baked into the firmware. Your SDK application cannot invent new Linux device drivers, nor does it have any access to the Android device side of the adb connection.
Can we do the same via an application?
Since you have not said what you are trying to do, this is impossible to answer in a definitive fashion.
Say, for example, the "device which can act as an USB host or slave and processes the data it receives" wants screenshots off of the Android device. That is eminently possible via adb, because adb has a protocol for that built in. All you would need to do is have your device connect to the Android device via the adb protocol and request screenshots, no different than does DDMS or hierarchyviewer.
So, I would look at the problem from a different perspective: if you can accomplish it via DDMS, you can do it via your custom device. If you can accomplish it via adb shell commands, you can do it via your custom device. If you cannot accomplish your goals via existing interfaces, though, since you have no way to invent new ones over USB, you will be stuck.
Conceivably, you could plug your custom device into a Bluetooth or WiFi dongle, then use those on Android for communication.

Data collection with Android via USB

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.

Categories

Resources