19

I have a simple device connected to the Raspberry Pi, a small USB fan. The problem is that the fan does not have a on/off switch so I must unplug the fan every time I want it to stop.

My question is: is there any way I can cut the power coming from the Pi's USB ports?

nc4pk
  • 1,378
  • 1
  • 13
  • 25
opc0de
  • 654
  • 5
  • 11
  • 18

5 Answers5

34

You can use my tool uhubctl, it supports Raspberry Pi models B+, 2B, 3B, 3B+ and 4B - these models have hardware ability to turn USB power off and on.

Use it like this:

Turn off power to all USB ports (must use port 2):

sudo uhubctl -l 1-1 -p 2 -a 0

Turn on power to all USB ports (must use port 2):

sudo uhubctl -l 1-1 -p 2 -a 1

Turn off power to Wifi+Ethernet (must use port 1):

sudo uhubctl -l 1-1 -p 1 -a 0

Note that Raspberry Pi 4B is very different from previous models as it has USB3 chip. It doesn't support turning off power to Wifi+Ethernet, and for USB you will need to use something like that to turn off (this turns off all USB ports - RPi 4B hardware does not support individual port power control):

sudo uhubctl -l 2 -a 0

If your Raspberry Pi does not support USB power switching, you can connect external USB hub that does (see list of compatible models), and control power on that external hub using uhubctl.

mvp
  • 519
  • 5
  • 10
4

No, the usb power is hardwired straight to the RPi power.

You can interrupt the power to the fan with a transistor or a relay, but you'll have to cut the red wire.

John La Rooy
  • 12,005
  • 9
  • 48
  • 77
4

You can use one usb fan with "on/off" switch.

enter image description here

David
  • 244
  • 1
  • 5
1

You can turn of all USB ports with their power:

sudo tee /sys/bus/usb/drivers/usb/unbind

Data transfer will not be possible too.

To turn USB ports bak you can use:

sudo tee /sys/bus/usb/drivers/usb/bind

I have stolen this solution by user faceofbo from Raspberry Pi forum

Roman Matveev
  • 433
  • 6
  • 16
1

This also works for me on the Raspberry Pi 3. It was copied from here.

   sudo apt-get update
   sudo apt-get install libusb-dev
   git clone https://github.com/codazoda/hub-ctrl.c
   cd hub-ctrl.c
   gcc -o hub-ctrl hub-ctrl.c -lusb

This will create an executable named hub-ctrl. You can then run it to do the following:

  • Turn off power to all USB ports

    sudo ./hub-ctrl -h 0 -P 2 -p 0
    
  • Turn on power to all USB ports

    sudo ./hub-ctrl -h 0 -P 2 -p 1 
    

Follow the link to also turn on/off the Ethernet port.

psiphi75
  • 119
  • 3