# USB OTG with occasional charging

I'd like to use a mobile phone together with a barcode scanner as a poor-man's version of a computerised barcode scanner, something like this: http://www.thebarcodewarehouse.co.uk/pdas-and-handheld-computers/handheld-computers/motorola-MC9190-G/

My phone is capable of USB OTG, and that works well but it uses the same micro USB port for charging the phone and I'd like to avoid unplugging the barcode scanner to charge the phone.

I'd essentially like to combine the phone and scanner into a single device with a a socket that I can use to charge it.

I know that there are Y cables available, but these seem to provide power to the peripheral (scanner) rather than the phone. I have also seen various micro hubs but these again seem to provide power to the peripheral devices only.

I have seen various suggestions for a scheme similar to the one below but with the addition of a resistor to pull the ID line in the phone's connector low with specific values. I have been unable to find an easily digestible list of these, and there are suggestions that it is against the standard. I also don't know how it would handle the connection and disconnection of the charger.

In the OTG cable that I use to connect the phone and scanner, I believe there is a short between ID and GND. This tells the phone that it should be in host mode and provide power. When I plug the charger in, the phone needs to stop powering the 5v line and accept power instead.

I considered a simple switch to open circuit the ID pin, thus taking the phone out of OTG mode, and allowing it to charge. But, I believe it takes a short while for the phone to realise that the OTG device has been unplugged and to stop providing power, during that time the phone and the charger will be trying to supply power at the same time which doesn't sound good.

I also had a look for a chip that will handle this switching for me. They seem either to want to switch the data lines only which I don't think I need (unless the charger signals its presence this way), or be a charge controller for a battery (I don't need this since the phone will handle charging of its own battery).

The barcode scanner doesn't have to work while it's charging but that would be a nice-to-have feature.

• Welcome to EE.SE. So what is your question? – Sparky256 Jul 12 '16 at 16:44
• OTG Charging is completely dependent on the phone. It's not supported by many. – Passerby Jul 12 '16 at 16:57
• Consider finding a phone that's QI wireless charging compatible. – Passerby Jul 12 '16 at 16:57
• I'm sure you are probably already aware of this, but there are a bunch of pretty decent barcode scanner apps for smart-phones with cameras. You can also purchase various clip-on lenses if needed. – Tut Jul 12 '16 at 17:06
• "I'm sure you are probably ..." $sure \times probably = ?$. ;^) Good point though on using the camera instead. – Transistor Jul 12 '16 at 18:42

This is a fundamental problem. When the ID=GND, your phone assumes the role of HOST, and therefore will SOURCE VBUS. And it will not charge its internal battery. When ID = open, the Phone will assume the role of device, will charge itself, but there will be no communication with your barcode scanner, since USB does not support device-device communication.

What you might need is to implement so-called "accessory charging adapter". See Section 1.4.1 and Section 6 of "USB Battery Charging Specification 1.2", which can be found on usb.org website link.

You might want to check with Texas Instrument offering as TSU6721 link for application ideas.

This all assumes that your phone really follows/supports the BC1.2 specification. If not, you are out of luck.

• Thanks for the chip suggestion. I'll look into to that a bit further, it certainly seems to do a lot. Wish it didn't have so many pins / wasn't so tiny! :-) – user3210218 Aug 2 '16 at 20:18
• I've also ordered a TS3USB32008RSVR from TI, similar to the chip @Ali Chen suggested but less pins. Unfortunately it's smaller than my breakout board will take so I may have to make my own... – user3210218 Aug 2 '16 at 20:28

Some phones / tablets allow battery charging during USB OTG mode. I've seen documentation for two different schemes.

1) Normal OTG mode (no battery charging): ID pin is connected to the ground pin.

2) OTG mode with battery charging v1: ID pin connected to ground via 20k resistor.

3) OTG mode with battery charging v2: ID pin connected to ground via 120k resistor.

These mode work with a small subset of all the OTG-capable devices. But it's pretty easy to try with your particular device to see if it might work with it.

• Thanks for the suggestion. I'm not too concerned with being able to charge the phone while it's being used with the scanner. The main problem I need to overcome is switching from OTG mode to being charged mode. It may be possible to just change the resistance on the ID pin when the charger is plugged in but I don't like the idea of the phone and the charger trying to drive the 5v line simultaneously until the phone realises a charger has been plugged in. – user3210218 Aug 2 '16 at 20:25