Intro: Android OTG Development Interface
I am developing a micro-controller based hardware which will connect to an Android phone using the On-the-Go (OTG) mode and would be powered by the phone.
The micro-controller is programmed using embedded-c and I have on the bread-board made an arrangement to change over from 'Program Mode' to 'Run' mode. I have used a set of DIP-switches to do this, as the D+/D- in 'USB-Mode' and the Program 'Data/Clock' on the processor use the same pins.
I find this convenient to quickly make changes in the software and immediately check out the functionality of the hardware.
On the Android phone end I found that it is often necessary to change over from the 'PC-Connected-Mode' where the APK program is downloaded from the PC to the device using 'Android Studio IDE' and the 'OTG-Mode' where the phone needs to be connected to the micro-processor hardware.
As the program development is an iterative process using the phone as a 'Hardware Emulator' the number of 'Connect/Disconnect' cycles was becoming excessive and I was very worried about damaging the connector at the phone end. This is very important as the phone is the most expensive hardware in the setup!
I have come up with a simple 'OTG Development Interface' which is presented here wherein the connection at the phone end is made permanently during a development session and the PC/micro-processor can be alternatively connected for 'loading the APK'/ 'executing the application'.
Safety is built-in to the hardware so that +5V from the PC cannot be fed to the Phone when it is in OTG mode.
Step 1: Hardware
The schematic shows the connections between the USB-Micro-B Plug which connects to the Phone Socket, the USB-A-Socket which connects to the micro-processor OTG hardware and the USB-Micro-B Socket for the PC-USB cable to connect.
The D+, D-, and Gnd lines are interconnected at the corresponding pins on all three connectors.
When JP2 is connected the USB-Sense wire is connected to ground putting the Android phone in OTG-Mode. When JP1 is connected +5V from the PC can be fed to the Android phone which along with D+/D- activates the Phone-PC connection-Mode.
It is not advisable to connect both JP1 & JP2 simultaneously as +5V from the PC /Charger would feed the phone when in OTG-Mode. (+5V can be fed only to Android devices that don't supply power to the micro USB port, but would otherwise be OTG capable.)
This is avoided by not using slide-switches and providing only one removable 'Jumper-Shunt-Bridge' so that the system would be in only one of the two modes.
This is a simple Safety built into the interface.
The pictures show the top/bottom views of the interface and the jumper connections.
While keeping the connection to the phone fixed , using this interface connect/disconnect can be made at the bread-board / PC end or at the Interface connectors as desired.
Step 2: Getting the Connectors
The USB-A Socket is fairly easily available but I found it difficult to get the Micro-B connectors.
Finally I succeeded in removing one connector from a scrap mobile phone card and the other from a PC-phone cable.
Interestingly the USB-Micro-B Plug from the cable uses only four of the five connections and the sense pin was cut away. I had to dig into the plastic to get at the sense contact. I soldered a wire to this to bring out this pin which is necessary for the OTG-mode.