0
\$\begingroup\$

I'm working on a project in which I need to be able to toggle the power to a USB device connected to my laptop. My original intention was to reduce the 5V USB power to 3V, and then toggle the USB on and off with a program I would write. However, after some research it would appear that it is not possible to turn USBs on and off with code.

With that in mind, I'm wondering if it would be possible to use the D+/D- lines as a togglable "power source" for my device. I've read in several places that the data lines on USB's are 3.3V? Is that true for all data USBs, or am I missunderstanding? If its true, then I could theoretically reduce those 3.3V to 3V and it would solve my issue (as I could send/not send data).

I'd also like to importantly point out that I say "power source" because it doesn't have to be constant, just a short on/off pulse with a high enough voltage.

Also I realize that there are products that exist on the market that I could buy to simplify my issue, but the idea of my project is to use things I already have available to me (just the usb device, resistors and cables).


I also should have noted exactly what my project is - its very much a patchwork project. I've hijacked the remotes for two strings of Christmas lights. I've hardwired one to be permanently on and other permanently off. Each remote originally contained a 3V Lithium coin battery (CR2025). Instead of hijacking the IR system, I decided it would be easier to hijack the power one. So I decided to replace the battery with USB power, which is where I ran into my problem I stated above.

Pulsing the USB power to the ON remote will simulate me pushing the ON button, and likewise for the OFF remote.

\$\endgroup\$
  • \$\begingroup\$ you are correct about the data voltage level .... LOW data bit is between 0.0V and 0.3V .... HIGH data bit is between 2.8V and 3.6V \$\endgroup\$ – jsotola Dec 10 '17 at 3:04
  • \$\begingroup\$ What are you trying to power? Data pin drivers just aren't going to be very grunty... \$\endgroup\$ – ThreePhaseEel Dec 10 '17 at 3:07
  • \$\begingroup\$ @ThreePhaseEel an IR transmitter \$\endgroup\$ – thearchitector Dec 10 '17 at 3:09
  • \$\begingroup\$ the controller, that you choose for the IR transmitter, probably has a sleep mode that you can use to limit the standby power draw \$\endgroup\$ – jsotola Dec 10 '17 at 3:12
  • 1
    \$\begingroup\$ You could buy a USB-uart dongle, the ftdis have gpio pins you can control from host pc \$\endgroup\$ – sstobbe Dec 10 '17 at 3:33
4
\$\begingroup\$

Most likely not...

USB output impedance is high. It's designed to match a 90-Ohm differential impedance in the cable. That means there is (the effect of) a resistor in series to match this cable impedance. Driving through that "source impedance" results in a voltage drop that increases with current draw. You will only have the appearance of ~3V when your current draw is almost nothing. After that it will fall quickly.

This is a microcontroller output curve. This microcontroller is much stronger (voltage drops less for given current) than most dedicated USB outputs, but it illustrates the problem you'll face.

enter image description here

You have limited control

You do not have complete control over the state of the data lines in a USB port. The protocol requires periodic state changes to those lines, for things like checking if the device is connected, enumerating (listing) all the devices on the bus, etc. So if you have a (very) low current device attached and it otherwise works, it will cycle on and off unexpectedly from your perspective as your computer operates normally.

Pull-up resistors interfere with control

USB requires the data line to be pulled high in the nominal case, so it may not be possible to operate (depending on your load and configuration) in a manner where you can turn off the device as doing so would signal to the port controller that something is wrong, or that no device is connected.

enter image description here

Control is packet based

Devices on a USB bus must announce themselves when asked (part of bus enumeration) and if you do not respond correctly, data sent to the port will not actually change the pins (the driver will just send your program an error code instead). USB pins sit behind a bus/port controller and follow a rather elaborate protocol. It's not like a GPIO pin in a microcontroller.

Further, if you successfully communicate with the USB host controller, you will still not be able to hold the line in a dedicated state. Data is transmitted in packets (defined sequences) and the protocol uses a non-return-to-zero encoding scheme, which is not inherently self-clocking. To correct for this limitation, USB controllers enforce a run-length limiting (RLL) scheme that limits the number of 0's or 1' that can come in an uninterrupted chain. That means even if you send all 1's to the USB controller, the line will not stay in that state uninterrupted.

\$\endgroup\$
  • \$\begingroup\$ Actually, every USB port has test modes. If you can manage to initiate SET_FEATURE(TEST_MODE) = 1H transaction on a particular USB port ( = Test_J), the port will set D+ = High until instructed otherwise. Usual FS hardware driver has internal ("single-ended") impedance of 45 Ohms, so the J signal can deliver about 6 mA at 3.0V. \$\endgroup\$ – Ale..chenski Dec 10 '17 at 18:14
1
\$\begingroup\$

From your description, the hijacked "IR transmitter" doesn't qualify for "the USB device" by a long mile. As I understand the problem, you want to turn power on and off on this IR transmitter using a PC with USB ports. Unfortunately, your way of thinking is not implementable. While there are indeed means to control port VBUS power on certain hosts and hubs, the control is deeply embedded in the host controller driver at the kernel-level, and is not accessible from user space. Using D+/D- will face the same difficulties (there are USB test modes that can drive the lines on and off permanently, but they need a special USB test stack-up, which doesn't have programmable user interface).

Assuming that you have hijacked the transmitter correctly and it operates simply by power-on and power-off, you need a real USB device that has control over a GPIO signal, which can be used either to control a transistor, or even directly your IR dongle if the GPIO has enough power (20-30 mA I would guess will be enough to simulate the coin battery on-off, but it needs to be researched).

As an example, this demo board (MCP2221) does have four GPIOs available (in addition to I2C and/or UART. (It even can be a small DAC and ADC.) The board comes with configuration software and a USB host driver that allows to toggle these GPIOs. The GPIO can sink or source 25mA of current at 3.3V level. It costs $20, difficult to beat this price. I am sure there are other demo devices that can do the same function.

CORRECTION: MCP2221A can't drive 25 mA at 3V, sorry. You will likely need a transistor switch to drive your IR device.

\$\endgroup\$
  • \$\begingroup\$ Ahh, I see. Well fortunately I was digging through some old boxes in hopes of finding something else and stumbled across an Arduino, which I'm going to use as a buffer between my laptop and the remotes. \$\endgroup\$ – thearchitector Dec 11 '17 at 0:36
0
\$\begingroup\$

I've read in several places that the data lines on USB's are 3.3V?

Yes and no. Yes, they are supposed to have a signal between 0 and 3.3V on them.

No, they cannot be used as a power source. The lines are both connected to ground on the host side via a 15kOhm resistor each. The host will detect a connected device once one data line is pulled up to 3.3V with a 1.5k resistor.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.