• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

USB communication between Device and App

mkm89

Lurker
Apr 16, 2018
6
2
I am creating a device that communicates with an Android application (which I'm working on) through usb. The app has to send a signal to the device (it can be as simple as a high or a low). I wanted to know if it's possible to do so. What kind of signal would it send? Also, if someone can post any references that I can check out, I'd really appreciate it!

Thank you
 
  • Like
Reactions: Daniel Thomas Brown
I am creating a device that communicates with an Android application (which I'm working on) through usb. The app has to send a signal to the device (it can be as simple as a high or a low). I wanted to know if it's possible to do so. What kind of signal would it send? Also, if someone can post any references that I can check out, I'd really appreciate it!

Thank you

Do you wish to implement serial comms over USB with the attached device?
There are some useful suggestions here

https://stackoverflow.com/questions/21800932/communicating-with-serial-usb-device-over-android

Some other links:

https://developer.android.com/guide/topics/connectivity/usb/host.html
https://developer.android.com/guide/topics/connectivity/usb/index.html
https://stackoverflow.com/questions...icating-with-a-device-plugged-in-the-usb-port
 
Upvote 0
No. First of all you should know, USB is not logic level interface. Actually USB exploits differential signalling with voltage levels 0.3/2.8V for FS and 0.01/0.4V for HS devices.
With the high probability your device is HS, USB D+ line is switched between 0.01/0.4V and D- between the same levels but in opposite phase.
Even, if it was possible, you need differential receiver to distinquish low state from high state of USB line.
But, as I said, USB interface does not provide direct access to USB lines to programmer, even via Android device driver.
So the only way to solve your task is to use have MCU(microcontroller) with USB OTG interface like STM32.
This MCU is connected to USB interface of your device via it own USB-OTG interface and, to driver of relay via GPIO (general purpose IO).
Be sure that you do not connect MCU to relay directly. You should use some MOS or BJT device to control your relay.
The simplest way, if you are novice in hardware, is to use Arduino Board for this task.

With the MCU or Arduino Board yes, you can solve this task like you want.
 
Upvote 0
Yes you can send data over USB in a standard way. The best way is to use examples for Android.
Data over USB is transmitted via packets. You can send these data from Android device. And receive and see them on MCU side in the endpoint buffer.
Android does not provide access to physical level of USB interface. You can only put data into USB interface via some procedure and get them on the other side again via some procedure.
If you want to see what's going on USB lines you should use oscilloscope or USB scanner device. This is quite complex task to get access to USB line and not loss the data.
As a programmer you can't do anything on physical level of USB.
 
  • Like
Reactions: Daniel Thomas Brown
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones