24

On a Raspberry PI 3B+, it's simple to turn power on its four USB ports off and on. Simply write a "0" to /sys/devices/platform/soc/3f980000.usb/buspower to turn power off and a "1" to turn power on.

The same method doesn't work on Raspberry PI 4B, 4GB (the hex number before ".usb" is different, that's NOT the problem). I have tried uhubctl and hub-ctl as well without any success. I have used a USB power meter to measure the voltage on the ports. It doesn't change. Un a PI 3B+ it changes as expected.

Does the PI 4 support turning USB power off and on in software at all? If it does, how to do it? Or is there a bug somewhere that has to be fixed to make it work? I use the newest Rapbian on both the Pi 3B+ and the Pi 4.

  • There is one generic option using `/sys/bus/usb/drivers/usb/unbind` mentioned in this SO question: https://stackoverflow.com/questions/18765725/turning-off-a-single-usb-device-again Not sure if Pi 4 does have this functionality in hardware. Technically, it should not unpower the device, but just unbind the driver. Which may save You some power. – Kamiccolo Jan 16 '20 at 15:24
  • 3
    uhubctl author here. It does, just build from master branch – mvp Jan 16 '20 at 16:46

3 Answers3

34

Yes, uhubctl supports RPi4B, I have recently added support for it - you need to use uhubctl version 2.4.0 or later (or build it from master branch). It is also necessary to update USB firmware using sudo rpi-eeprom-update to make power switching actually work.

Note that you are missing out by using sysfs method to turn USB off on RPi3B+ - using uhubctl you can control either all 4 ports, or 2 of them independently. RPi4B only supports turning off all ports at once.

mvp
  • 111,019
  • 13
  • 122
  • 148
  • 2
    Thanks. The newest USB firmware together with the newest uhubctl solves the problem. /sys/devices/platform/soc/3f980000.usb/buspower no longer exists after the firmware update and /sys/bus/usb/drivers/usb/unbind doesn't (as pointed out by Kamiccolo above) turn off the USB power. – Jørgen Frøjk Kjærsgaard Jan 27 '20 at 11:48
  • Thanks for confirmation @JørgenFrøjkKjærsgaard. If this has solved your issue, consider accepting this answer :-) – mvp Jan 28 '20 at 01:33
  • This looks very interesting - thank you. One question however: there was no `man page` in my RPi 4 installation just now. I've looked at the README on your GitHub site, but it doesn't seem to address a couple of basic questions: how to turn port power off, then back on? –  Sep 30 '20 at 18:05
  • 2
    After the eeprom update (rpi-eeprom package version 11.0), I can turn off the power via `echo '1-1' > /sys/bus/usb/drivers/usb/bind` again. – Hermann Dec 20 '20 at 20:01
  • @Hermann on the Pi 4 you just use the echo to usb bind and all the power on the USB hub shuts off? I tried this with no luck. Did you do anything else (my rpi-eprom is latest)? – Jairus Oct 08 '21 at 16:28
  • @JairusMartin: does uhubctl version 2.4.0 not work for you on RPi4B? – mvp Oct 08 '21 at 17:19
  • It did not, my issue might be that with the Argon One V2 case, the USB might be powered through the header. – Jairus Oct 12 '21 at 13:05
  • Is there a way of making this work on the new Raspi Zero 2? – Thomas W. Nov 27 '21 at 22:08
  • @mvp I'm assuming RPi4B still only supports turning off all ports. Any workaround to do just a single port? Thank you – dataflow Aug 22 '22 at 18:49
  • is it ok to do it frequently? I have fan connected to the usb. and I turn it on every time my raspi got over 60 degree celcius and turning it off when the raspi cool down. – BlueBeret Aug 05 '23 at 19:39
  • I have done it very frequenty (e.g. turn off/on once every few minutes) and on a large scale (hundreds of devices) and never had any issue – mvp Aug 07 '23 at 17:32
3

As far as I read Raspberry Pi and Linux issues on GitHub, it seems that there was a bugfix released for uhubctl on 2019 July. Patch I'm refering to: mvp/uhubctl@4aae44c. It should be merged to master. So...

Another thing to have in mind, it seems that RRi 4B hardware only supports "ganged power switching", which means... that You can only turn on and off ALL the USB ports. Not every single one in particular.

Kamiccolo
  • 7,758
  • 3
  • 34
  • 47
  • I'm not sure I understand your answer wrong now. Can I only with the Raspberry Pi 4B not control all USB ports individually or can I generally not control all ports individually? Because otherwise you could go back to a 3B+. – Micha93 May 09 '22 at 09:38
  • It can not control ports individually. Only all the ports at once. At least COULD NOT. Need to check official references, maybe they have upgraded some hardware or whatnot. Don't fully remember if that was the case only regarding firmware or both, firmware and hardware. – Kamiccolo May 10 '22 at 08:32
1

To shut off power for USB ports and Ethernet type the following into the Raspberry Pi Terminal and press enter:

echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/unbind

For that you need to install:

sudo apt-get install uhubctl

For turn on again use this command:

echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/bind
Luca Ziegler
  • 3,236
  • 1
  • 22
  • 39
  • 1
    Aaaand and actual, complete example to round things off. Thanks! Was thinking of buying a GPIO power relay hat to control a small USB aquarium pump so I could schedule watering of my house plants with crontab; but this is way simpler & cheaper. – Reece Jul 28 '23 at 17:15