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.
Related
Require a method of connecting an android app with a C++ program on PC via USB, which would allow the android app to send a constant stream of real time data (mostly integer values) to a c++ program on PC via USB and carry out actions accordingly. I know it is easier to do this by wifi or bluetooth, but I want to carry out the connection using USB.
I have searched the net alot for similar questions, and tried many code, but non of them have worked for me. I would greatly appreciate an example code for the c++ portion, and it's android counterpart that allow for this to be done easily.
You could use the USB Tethering option on the phone. This should work with Android 4.4 and the most popular Linux Distributions out of the box. Then you are able use TCP/IP between Android and the PC. You could use an UDP multicast based protocol for service discovery (e.g. Multicast DNS, NSD or SSDP) if you need to avoid entering IP addresses on one side.
One way of doing this is to setup your pc application to talk to the android device as an android accessory. http://developer.android.com/guide/topics/connectivity/usb/accessory.html
This will allow both applications to send whatever data they want over usb, Google do provide source code for doing this with the accessory development kit http://developer.android.com/tools/adk/index.html
I don't have any example source code but there might be some out there if you search.
You can use ADB and call custom commands on your Android device. This commands should just type integers to stdout. As an option, you can use standard shell commands like cat and make your Android app write output integers to files in some directory where ADB can read it.
You can have Android behave like a USB device with a USB CDC (ACM) interface, which is seen as a serial port on the PC (COMx on Windows, /dev/ttyXXX on Linux). On C++ (PC) side, this would be "regular" serial port handling, while on Android there are several libraries for such purposes, though I never used one so I can't recommend any.
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!
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.
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.