i'm trying to communicate with Arduino board (Duemilanove) from Android 3.1 device with USB-host support using Android USB Host API.
The goal is to communicate with the board in the same way as via Serial.
I follow this manual (http://android.serverbox.ch/?p=427) but have few problems (f.e. failed to claim interface) and of coarse dev guide (http://developer.android.com/reference/android/hardware/usb/package-summary.html) but no luck.
The questions are:
how to prepare arduino board (modify firmware) - interruptions or smth?
how to check if it's okay with arduino board (f.e. enumerate USB interfaces and verify that it supports needed. what tools can be used?
how to find needed interface (what are interface class/protocol/subclass)
what can be the reason when interface cannot be claimed? (faced with that)
The arduino Duemilanove board has only a build in FTDI FT232RL USB serial converter. So you don't have to deal with the USB device side. From the AVR controller point of view it is simply an asynchronous serial port. Find out to which UART it is connected to and use it. Maybe you want to implement a simple echo (transmit all received characters again) as a first test.
Use lsusb command under linux to check out the usb device descriptor.
Read about USB in USB in a nutshell or in the official specification to find out how it works (especially chapter 9). Without doing so you can't go on. You would not understand anything.
Then go on and read about CDC class devices in the usb class section.
It might not exist (if you rely on the interface index without checking the device descriptor) or the android kernel has claimed the interface because there is a native driver for that interface. In this case you can call UsbDeviceConnection.claimInterface with true as second argument to disconnect the kernel driver first.
Related
Hereby the situation: I'm working on a Android Tablet that must work in Accessory mode. Reason why is because the tablet can't provide enough power to perform the communication with a Serial USB microcontroller and remain charging it's battery.
In order to achieve a successful communication, I must be able to set a few serial conditions for Modbus/RTU
Serial Port Address (i.e. COM1, COM2...)
Baud Rate (19200 bps)
Data Bits (8)
Stop Bits (1)
Parity (None)
An excellent example in Delphi would be Modlink.
A good guidance would be UART https://github.com/ytai/ioio/wiki/UART
Meanwhile, I've found some useful projects but they were intended to work on Host mode.
https://github.com/mik3y/usb-serial-for-android
https://github.com/ksksue/Android-USB-Serial-Monitor-Lite
I'm looking for any valuable information, guidance and references on how should I proceed to create an Android Application that can communicate with Serial USB.
How can I achieve this?
Note: I'm using Android Studio.
There's an excellent source code made by FTDI Chip, so if you ever need to perform USB/ftdi connections with Android try this application:
FTDI UART TERMINAL
Source code: http://www.ftdichip.com/Android.htm
I have a MR400s taximeter hardware. I want to communicate with this taximeter using RS232 cable and I have already achieved this connection and communication in windows. But I wanted to make connection using android device.
How can I achieve this?
Thanks
Ishan jain
I use the USB to serial library, you can find it here: USB Serial for Android.
It doesn't require any root access. You'll need to check if your Android device supports USB host mode. Then, using a usb OTG cable and a USB to serial adapter cable you can start communicating with your serial device via RS232. There are code examples to get you started on the Github page of the USB to Serial library.
An alternative to a cable connection to the Android device (using the "USB Serial for Android" library, see the other answer) is a converter from RS232 to Bluetooth.
Such a converter will use the serial connection profile of Bluetooth, and ways access such a connection in Android are discussed in this question.
You can build such a converter based on an Arduino by adding a Bluetooth shield and simple code that converts incoming data from the serial port to outgoing data on the Bluetooth connection. (I could not find detailed instructions for this right now.) When you want to connect the Arduino's serial port to a RS232 device you would need another shield for logic level conversion (RS232 is ±12 V, Arduino is 5 V or 3.3 V).
There is also a commercial product implementing this Photologic Text Streamer (ca. 265 USD !!!). It seems that this provides a read-only connection for Android (not totally sure about that, though). A read-only connection is still ok for cases where you only want to read sensor values.
Finally, you could do a similar thing using an Arduino and a wifi shield.
I'm trying to figure out how to connect two Android powered devices,
namely a smartphone (Android 4.1.2) and an android developer
board (Android 4.0.4) with apps running on each, via USB and get them
to communicate with each other.
Right now the developer board is running as the host and the phone as
an accessory. The hosts app is searching for connected devices and is
able to identify the phone as a device, but the app running on the
phone isn't able to find the host.
I've searched the web for quite a while now (!!) but I didn't come
up with anything helpful yet that solved my problem.
For my project it is crucial that I use an USB connection, so please
don't propose that I use bluetooth, WiFi, or anything else...
Regards
USB is host initiated, so it's not surprising that this is not working. Your device that is functioning as the USB device should respond to requests initiated from the USB host. You will probably have to create some sort of vendor specific protocol around this. I don't know what you are trying to do with this connection, but if the device needs to know things on the host you will need to bake this in to your protocol definition and send that information directly to the device.
What you could try doing is using both devices as a host and connecting a USB to UART bridge device between them, then you can transmit data generically in any direction by using the serial connection (through USBManager if the USB protocol is available, or some Android Java Serial class if it is not), plus you don't have to worry about the host-device connection. This would look something like this:
[Android 4.1.2 Device]<--USB Connection-->[USB to UART Bridge]<--Serial Connection-->[USB to UART Bridge]<--USB Connection-->[Android 4.0.4 Device].
Use OTG Cable to interact with your board and phone. Its easily available in the market.
Is it possible to write an app in Android using the wifi API which will act like a hotspot (so granting network access to wifi clients) while still allowing the local wifi device to connect to another wifi network ?
The one I've tested are disabling local Wifi connection in order to create a hotspot.
I post here after a few months so people that would like to implement this on an Android device might be helped.
There is a way to have one wireless chip working in hybrid mode, with both station mode (STA) and access point mode (AP) enabled.
To do this, I replaced the wireless driver of my chip with a multi-role wireless driver. Luckily enough, my chip was supporting this mode, it is however not the case for every wireless chips. My chip being a TI based chip (wl1271), multi role was supported, though it was not available with the previous driver.
Once I got this new driver, I had to recompile it along with my kernel in order to have the .ko of the wireless driver and the related mac80211 and cfg80211 modules (providing the APIs needed by the new driver) generated. The last step was to upgrade wpa_supplicant and hostapd with a custom patched version provided by TI.
Again, for people interested in wl1271 only here are the corresponding drivers/tools I used and reported working on Android 4.0.4 ICS :
https://github.com/TI-OpenLink/hostap/tree/ol_R5.SP3.01
https://github.com/TI-OpenLink/iw/tree/ol_R5.SP3.01
https://github.com/TI-OpenLink/ti-utils/tree/ol_R5.SP3.01
https://github.com/TI-OpenLink/wl12xx_target_scripts/tree/ol_R5.SP3.01/sta
https://github.com/TI-OpenLink/compat/tree/ol_R5.SP3.01/
https://github.com/TI-OpenLink/compat-wireless/tree/ol_R5.SP3.01/
If there is a multi role driver for your wireless chip, it might be worth it finding out what version or patches of wpa_supplicant and hostapd you shall use, and compile/try them.
At the end of the process, I had access to two network interfaces (wlan0 and wlan1), and could launch wpa_supplicant on wlan0 and hostapd on wlan1.
What you are describing is called WDS (Wireless Distribution System). I think that this functionality is not implemented in Android wifi API. It is used in wireless APs to enable a wireless link upstream.
I a trying to connect my Nexus One with Android version 2.2.1 with my pc and use a terminal program such as windows terminal or hyper terminal to communicate. To do this I believe I need to set up an outgoing serial com port. I have paired the devices. When I go on my PC to Bluetooth -> settings -> "add com port" the android device does not display.
What am I missing?
Does android 2.2.1 support spp? The documentation says it does.
Do I need to root the android to add spp?
Has anyone succeeded in this?
My final goal is to write an android app that communicates with an old school bluetooth device that requires com ports? Getting the android to communicate with the pc is an interim step.
I have tried everything I can think of in my android app to connect to my pc and android device but have not been successful. My android app is essentially the same as Serial over Bluetooth submitted by xCaffeniated but with fewer comments. Any suggestions?
Try beginning with the BluetoothChat sample application. You will then have to alter the UUID used to the generic SPP UUID,
00001101-0000-1000-8000-00805F9B34FB
From this point you pretty much have everything you need.
I have had issues pairing in the BluetoothChat program. So I was required to pair to my computer using the settings menu and then entering the BluetoothChat Program. In BTChat go to the menu and hit connect to a device, choose your computer. I can only speak for windows XP SP3 which is what I'm using. At this point on my machine I receive a task bar pop up asking me if I would like to allow my device to connect as a serial port. I allow it to. Now your phone is associated as the serial port profile on the computer, which you can associate with a specific com port.
Based on bluetooth spec,
http://www.bluetooth.com/SiteCollectionDocuments/SPP_SPEC_V12.pdf,
2.3 User Requirement, "... Any legacy application may be run on either device, using the virtual serial port as if there were a real serial cable connecting the two devices (with RS232 control signalling)." In 4.3 Remote Port Negotiation, "...There is a requirement to do so if the API to the RFCOMM adaptation layer exposes to those settings (e.g. baud rate, parity)... RFCOMM as such will not artificially limit the throughput based on baud rate settings,..."
In my opinion, since Android (2.2) offers no APIs to set up and open a serial port, they may not be necessary as long as you can discover the remote BT device and make a connection to it. I have tried it and it seems working with:
...
sock = device.createRfcommSocketToServiceRecord(myUUID);
sock.connect();
...
where final UUID myUUID= UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); You may need to take care of Bluetooth Permission and Setup in your application as described in
http://developer.android.com/guide/topics/wireless/bluetooth.html
There might be some issues with the connect() call, i.e. Service is not available or connect is refused, which could be resolved by making sure:
The remote BT device be discovered, and
It must be set to use PIN code (for instance 0000), and
It must be paired successfully with your Android device
These steps must be completed prior to running your application (which has connect call).
Hope this help.
George
There is definitely some funny business regarding how the AT set is implemented on the AOS. The problem is that it is hard to know if you're actually talking directly to Modem or through several abstraction layers (more likely). For a best up-to-date review of the AT Commands available on the AOS platform, plus HW, please see the post:
"How to talk to the Modem with AT commands"
http://forum.xda-developers.com/showthread.php?t=1471241