Android reading data via USB & UART - android

I am student and currently working on a project for my university. I am trying to write an app which is capable of reading date by using the TUSB3410(http://www.ti.com/product/tusb3410) and its USB to connect it with the C2500(http://www.ti.com/product/cc2500) connected via UART. Something like USB to serial.
I can get information off the TUSB3140 like its vendor id or its endpoint so I can use the normal USB API. But it is rather tricky to receive the information of the cc2500. I don't know which methods I should use or which parameter are correct. So maybe you have an idea how the methods like controlTransfer() etc. should look like.
I hope you can help me with this problem!

I'm afraid the answer isn't quite as simple as all that.
According to the linked datasheet and associated documentation, the TUSB3410 is not a fixed function device. It's basically a USB device on one side, a UART on the other side, and an MCU applications processor in the middle. In order for that chip to do anything useful, it has to have a firmware application loaded into it to govern how the data moves from one side to the other. So you get to define in the firmware how the data moves through the USB (interrupt transfers, bulk transfers, etc.) and that will govern how an Android application interacts with it.
Also, the chip does not seem to support having its firmware burned in, it always loads the firmware externally from I2C EEPROM or from the USB Host. If your device setup does not already have the EEPROM on it, you will likely have a difficult time because the Android USB APIs don't really give your application access to the device during the enumeration process, which is when the firmware would need to be sent if downloaded from the Host. It also would require you to detect your device twice (once with the standard bootcode VID/PID, and once again after the firmware file takes over and the device reconnects to the bus).
If you are just looking for a simple embedded implementation to get UART, SPI, etc. data into an Android application, you are probably better off with something like the FTDI FT311, which implements the Open Accessory protocol and comes with library code to get you started on both sides of the equation: http://www.ftdichip.com/Products/ICs/FT311D.html
EDIT: From your comment
So if your device conforms to the CDC USB Device Class, then there are basically three points of interest:
Every device has an "endpoint 0" for configuration, and this is accessed in the Android APIs using the controlTransfer() method. CDC devices use this endpoint for changing items like baud rate, stop bits, etc.
CDC Devices like a VCP have two interfaces, one for communications and one for data. The data interface (usually enumerated second) has two bulk endpoints (one in and one out) where the serial data is usually transferred. You can transfer the data back and forth on those endpoints with the bulkTransfer() method, or using an asynchronous UsbRequest.
As a starting point, perhaps take a look at the source of this open source project, which implements CDC basics using the host APIs. You should be able to get a good idea of how to roll your own driver from there (specifically the CdcAcmSerialDriver):
http://code.google.com/p/usb-serial-for-android/

I think apart from the FT311D which is using the AOA protocol, you may also consider to use FT231X, via FT231X, you can use the APK of android hyperterminal which you can easily find in google search/ google play. This is using by OTG method. You may also have a look.

Related

Can an Android device pretend and connect as a Bluetooth controller?

Can an Android device pretend and connect as a Bluetooth controller?
Can Android devices connect as a device to, say, a PC and act as a gamepad or similar device?
Is it allowed and doable in code without root access?
I tried this code: Connect Bluetooth devices. But it can not get it to pair.
Short answer, yes.
I recommend looking at Google's example project on Bluetooth communication BlueToothChat initially. Based on what you've written, I think you're missing several important steps.
You need all of the following components / steps:
General Overview
Set up Bluetooth
Set Permissions
Scan for other Bluetooth devices
Query the local Bluetooth adapter for paired Bluetooth devices
Connect to a remote device as client or server
Transfer data over Bluetooth
If you have access to the device your attempting work with as a controller, then you can create your own communication setup. Define a set of parameters to write and read on both sides that emulate the functionality you're looking for.
If you do not have access to creating your own read/write setup, or you want to use standard interaction methods for the industry, then the best bet is the Bluetooth HID Device profile mentioned by #Morrison Chang.
The HID profile basically establish an industry standard of required device features, read/write formats, combinations of features equaling a controller type (ie: "this is a keyboard"), and data mappings for what read/write numbers mean on either side of the client / server connection.
From the linked comment thread, the Kontroller project on Github has source available for your peruse.
There's also a reasonable Intro to Bluetooth HID that covers some of the topics on what Bluetooth HID is actually doing.
Finally, also recommend looking at Google's own BluetoothHidDevice page.

In Android, is it possible to get permission for class in interface 2 on a composite device

I have developed two usb devices of different classes that I can connect to an Android phone through a hub. They are both recognized and once permissions are granted, I can access both of them. One uses only bulk end points and the other uses only control transfers. My Android programs can talk to both of these devices without trouble.
I decided to put both functions in one usb device as a composite USB device with two interfaces. This saves real estate and power on the hardware side. This composite device connects correctly to a PC and the drivers are loaded correctly.
When I connect this composite device to Android, I can get permission for the device. Then, I can use the bulk end points that are associated with interface 1. I can read descriptors on the control interface. However, I can not read or write successfully to the class on interface 2 through the control interface.
I know that the control interface is working because I can detect the class commands from inside the firmware of the device. Therefore, it appears to be an issue of permissions.
After reading the Android documentation, I have been unable to figure out how to ask for permission for the second (and additional) interface class.
Does anyone know how to get such permission? Or perhaps I am wrong about the cause and there is a different reason for this behavior?
Many thanks.
I found the answer to my issue. It did not have anything to do with Android permissions. It seems that for a composite device, you only need to get Android permission once for the "device" and it is possible to access the internal classes.
My issue was with the actual control transfer. I had set up a control write with a buffer but the response from the firmware was a ZLP. Apparently, Android waits for the buffer and times out. In doing so, it seems that subsequent control transfers fail. Once I changed the buffer to null and the buffer length to 0x0 in the control transfer call, the issue was resolved.

android app to send a signal through the data pin of the usb cable

I need to send a signal (basically some current) via my android phone through the usb data pin.
Is there any way to do this.
I have the basic knowledge of app development and am ready to create my own app.
Any help would be appreciated :)
Unlike some older port designs (serial and parallel ports), USB does not provide for any arbitrary electrical control. Every pin serves a specific function in the USB protocol and cannot be arbitrarily set.
Some devices may have support for switching to an alternate non-USB mode, but nearly all such modes will similarly not allow for direct control.
If your Android phone supports USB host mode, then you could connect a USB-serial (RS232) adapter. This has two control pins that can be set arbitrarily, RTS and DTR, as well as the actual serial data line.

Wifi Direct (Wifi P2P) peer data exchange - sensors

I am trying to emulate this app - Wifi Direct sensors (https://play.google.com/store/apps/details?id=esnetlab.apps.android.wifidirectsensors)
I have gone through the demo of wifi-direct from android samples.
I am able to get sensors data on a individual device, but i need to get them from the peers in a wifi-direct group.
So I wanted to know if someone could suggest on how to go about the design/process of getting the sensors data from 'remote sensors' on one device (as shown in the screenshot of that app).
There are basically three components you are going to need...
If you're going to want to plot the results, need a plotting library like Androidplot.
You're going to need to establish a Wi-Fi direct connection between the devices. There is sample code for this in the android SDK, but it isn't in the newest SDKs, I think it's in levels 14 to 18, or something like that. In the samples, they show you how to open a socket connection and send a file. You just need to leave the socket connections open.
The sensor event class is not serializable, and I think its constructor is either protected or private. This makes it difficult to send over a socket since it is difficult to reconstruct the sensor event on the peer. A library like Gson might help with this, but an easier way would be to pick a subclass of information that is important to you and to just send that info.
What you want to do will be a lot of work.

Bluetooth + simulating mouse

anyone know if its posible to make an application to simulate a touchscreen mouse or trackpad by bluetooth??
How can I make that the PC (or MAC) knows me as a mouse device?
Regards,
Juan
You should have a look at the Bluetooth HID specification. It may be possible, depending on the stack of the device that you are using to emulate a mouse/trackpad. I'm not familiar with the stack on Android (assuming that's the platform you're using from the tag on your question) so I don't know if it's possible from there.
Essentially, you create a HID service on the L2CAP protocol. The service record specifies the HID descriptors which describe the data being sent from emulating device. The HID driver on the host computer should be able to interpret that data.
It might be useful to try to connect to another Bluetooth mouse/trackpad from the desktop (Bluecove on a stack other than Microsoft is a good way to hack around in Bluetooth). Have a look at the service record for the HID service on the mouse/trackpad. Also, look at the data coming from the mouse/trackpad for an idea of what needs to be sent and when.
Alternatively, you could write a server application on your computer that communicates via another Bluetooth protocol (e.g., RFCOMM/SPP) to the input-device emulator app running on your phone. The server application would simulate the input device (e.g., move the mouse pointer around on the screen, etc).
Instead of creating your own project why dont you contribute to the remotedroid project?
I'm assuming you know your bluetooth api's well. Remote droid uses Wifi and OSC messaging to communicate with the PC.
Yes you may use GlovePie with the wiimote connected to BlueSoeil, It will alow you to do anything with you computer with the wiimote. It also has a Language it uses
I think you want this:
Serverless Bluetooth Keyboard & Mouse for PC/Phone
It's even open-source!
Unfortunately it is not open source, it just has a GitHub readme for some reason.
But still the app is quite good!

Categories

Resources