I have a USB device I want to turn off and on via a Pi or NodeMCU device. I tried the trick “echo 0 > /sys/devices/platform/soc/20980000.usb/buspower” on the PiZero, but it didn’t work.
Could someone suggest a component or software solution to be able to turn on/off a USB power source? I could build something for 5v and wire a USB cable, but I had hoped there was something already out there.
Here is a link where some methods to pull this off are available, but they are using a RPI 3B+:
This one also has some less specific Linux methods to give a try:
If those don’t work you could always trigger a relay to shut off USB power externally.
I have to ask Why? Is the USB used just to provide power or something else? If it’s just power, hack the lead from a USB charger and put a relay in it.
Thanks Stephen, I’ll have a look.
Yes, it is just for power. Would you be able to suggest a relay device for this method that would be controllable by the Pi?
have a look at https://core-electronics.com.au/raspberry-pi-relay-board-v1-0-seeed-studio.html .
This has 4 relays on a Pi compatible board, but have a look around for “Raspberry Pi relay board”.
Thanks. This would work, but I’d need to have a think about how to wire in USB ports. I don’t want to cut the USB cables for the devices I want to switch on/off.
Great suggestion Dave! Before this conversation I wasn’t aware that there was a way to remove power from a USB port via software.
John, I would take a USB hub and wire that up to the relays for power, then you could shut your devices off without compromising the original USB cords.
Interesting… The bind/unbind work on the Pi3B+. Cool.
Unfortunately, it turns off ALL usb ports and ethernet.
To shut off power on USB ports (this shuts power on ethernet as well):
echo ‘1-1’ |sudo tee /sys/bus/usb/drivers/usb/unbind
To turn power back on
echo ‘1-1’ |sudo tee /sys/bus/usb/drivers/usb/bind
I have no idea what this ‘bind’ and ‘unbind’ are doing…