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.
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 have a third party usb device, that when plugged into a Windows machine, is recognized as a serial device and assigned to the COM 4 port. I can communicate with the device just like I would with a device connected via a serial port. For instance, I can write "abc" serially to the device via the USB connection.
I have been searching for a way to do a similar thing in Android. If I try the Usb Host method, and use a UsbManager to open the UsbDevice, I can get one interface, with 2 endpoints. I have tried sending control messages using the method in UsbDeviceConnection, but the method returns -1 for everything (though I don't know what I should use for the parameters of that method).
Is there a way to get an OutputStream that I can write to that will send bytes to the USB device? Right now I am looking at recompiling the kernel to include a virtual COM port driver and write some native code to be able to do this.
Thanks!
Edit: I am using the FTDI serial to USB converter circuit. Is this compatible with Android?
If linux kernel in your device supports FTDI, you can access this device as normal COM port. It will be named something like /dev/ttyUSB0.
If your kernel does not supports this type of devices, you can write your own driver using UsbHost interfaces. Check kernel's FTDI driver source code for guide.
You can use 3rd party drivers for this purpose,
this driver from SlickDevLabs works so nice,but cost you 100$.
http://slickdevlabs.com/slick-usb-2-serial-library/
If you don't mind rooting your phone and writing some C, you can communicate with the FTDI in Android using the Android driver here:
http://www.ftdichip.com/Drivers/D2XX.htm
There is a libftd2xx-jni.so in there that you can link with your C code - I've tested it and it works.
Rooting device is strongly unrecommended in common case, because i can do this for my device but i can't do this for public app, which is distributed on android market. In that case i think controlTransfer() is the only way to deal with it.
I am working on this Android application that needs to communicate over USB. I have an Archos 101 Tablet (specifications here: http://www.archos.com/products/ta/archos_101it/specs.html?country=us&lang=en). It has a full USB host port. I can put a flash USB drive in the USB port and copy files to and from the flash drive onto internal storage.
I have this Arduino Fio board, with an XBee attached to it. I have an XBee Explorer Dongle with another XBee that I plan to hook into the Archos 101 tablet into the USB port.
As of right now, I can put the XBee Explorer Dongle into my computer and send/receive data to and from the Arduino Fio, no problems.
Is there a way for Android to talk over USB? I know there has to be drivers somewhere in the tablet allowing USB communication, but I cannot find a way to access them or use them.
I can see Android recognizing the XBee Explorer Dongle. I downloaded a terminal emulator, and I can type "dmesg" and see that it sees the dongle hooked up. But I cannot do anything with it.
I seem to need a FTDI driver for Android.
I would greatly appreciate any help in getting my tablet to communicate with the XBee Explorer Dongle.
If you have root and can hack your kernel, FTDI offers its D2XX driver for Android OS. Check its website, please.
If your Android device is 3.1+, you should be able to use Android USB host to talk with Arduino. However, I met some issues on this.
If you have ADK/UHS at hand, your Arduino can act as USB host and talk to Android USB device. Even in same hardware, if your Android OS is quite old like 1.5/1.6, you have to use ADB interface rather than ADK (Accessory Developer Kit) protocol.
If you have Bluetooth, you can write your own Bluetooth SPP in your app.
If you can handle WiFi, you can write app to communication with socket, or via latest WiFi direct mode in Android.
Communication is various. However, it depends your hardware.
There is a solution by Inopiaaardbei using Arduino and a USB host shield with an Android Debug Bridge running on Arduino.
Using this solution you can use serial communication between the Android phone and the Arduino board.
See my post and the link inside for more info.
You can use an android adk or the android ioio connected to an xbee module as I did in this article. I have published the code on my github and another guy is going to implement the gui currently.
USB is not easy to programm, and it would be much easier with ethernet or rs232. However, if you insist, then take a look at V-USB (SW USB), LUFA (HW USB) and Lufaduino (HW USB). If Android has USB CDC drivers already embedded then it could be the easiest path for you if you implement it in AVR too. Slow, cheap and software only AVR USB CDC implementation is here.
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.
I would like to use Android phones as a way to do some processing and visualization of a sensor that would be attached to the USB port on the phone. The sensor would plug into the micro/mini USB, and then I would need to read the incoming data from the USB serial port.
Is this possible? I have heard of people using Android to steer robots and other applications, but I have never seen Android being used as a host for a USB sensor. I can't seem to find any official documentation on the subject either, but it seems like it would be a very useful tool. Any thoughts, links, or information on this matter? Thanks.
What you're looking for is USB Host support.
There's an open issue in Android's issue tracker here for it:
http://code.google.com/p/android/issues/detail?id=738&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
and it's actually ranked 7th, in terms of "stars" (think votes, by the people), at 1110 stars. You can log in and star it yourself, both to vote for it, and to receive email updates.
There was also work on a patch back in February, 2010:
http://groups.google.com/group/android-kernel/browse_thread/thread/c8471573d7553331
and there's info on using a USB keyboard here:
http://www.tombom.co.uk/blog/?p=124
Perhaps you can find something for your sensor there?
This is cool =):
http://www.technologyreview.com/biomedicine/25286/?a=fb
Cheers,
Victor
should be possible, look up android.hardware.usb.UsbDevice # http://developer.android.com/reference/android/hardware/usb/UsbDevice.html
This support has been added since Android 3.1.
Look at http://developer.android.com/guide/topics/connectivity/usb/index.html
This guy has modded his Nexus One to work as a USB host and has done several cool things.
He uses a USB keyboard and runs a movie from his USB stick. Then he runs a webcam through the phone and displays it on the computer and even runs an entire desktop-based Linux distro from his phone onto his computer monitor.
Pretty amazing stuff.
http://sven.killig.de/android/N1/2.2/usb_host/
The USB defines two type of equipment 1 usb host 2usb device .A device can only be attached to a host,no host to host or device to device connection.,in the beginning usb hosts were computers to which a usb device is attached.but with increase in popularity of usb interface a number of equipments come as usb host ie you can attach your pendrive and other usb device to it.In the starting mobile phones were manufactured as usb device ie you can attach your phone to usb host only typically a computer.but there also revolution come in now we have phone which can act as host and device when it is working as host we can attatch printer to it and when it work as device it can be attatched to a computer.only high end phone has this support.low end phones are still usb devices.
so we have two options
phone in usb host mode and your senser as usb device(you will need microcontroller that can act as usb device for this purpose-eg pic 18f2550 microcontroller);
your phone as device and your senser circuit as usb host here you will need high end microcontrollers that can act as usb host
in both cases there involves coding at both phone and senser circuit microcontroller
i dont know anything about phone side coding but i think this helps you to get a direction to what to do.
Have a look at You Are Here GPS.
https://play.google.com/store/apps/details?id=com.agbooth.usbgps