strawberry
Posts: 71
Joined: Tue Oct 30, 2012 10:44 am

Raspberry Pi B+ turn usb power off

Mon Dec 08, 2014 9:37 am

Hi all,

Does anyone know if there is a command (or some way in software) to turn off the power for any of the attached USB devices on the Raspberry Pi B+?

User avatar
DougieLawson
Posts: 42772
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Raspberry Pi B+ turn usb power off

Mon Dec 08, 2014 9:42 am

There isn't.

Use an in-line hardware switch.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
Paul Webster
Posts: 871
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK

Re: Raspberry Pi B+ turn usb power off

Mon Dec 08, 2014 7:11 pm

This might be enough (all USB off - including the built-in Ethernet)

Disable
echo 0x0 > /sys/devices/platform/bcm2708_usb/buspower
Enable
echo 0x1 > /sys/devices/platform/bcm2708_usb/buspower

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 15100
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Raspberry Pi B+ turn usb power off

Mon Dec 08, 2014 8:11 pm

the PI (B+) has NO hardware in place to disconnect power to the USB ports!

it can detect a short, (USB power Fault) and then the USB power controller (P2553W6) will automatically block the USB power, but the PI cannot turn off the USB power using software. What it can do is bring the LAN9514 into sleep mode, but that does NOT turn the power off!


post edit, I learned the designers used a hack, so that the same signal that monitors an overload status can also be used to disable the power monitor, thus shut off USB power, so by previous remark was incorrect!

Its a single current monitor, so shutting it down affects all USB ports.

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2988
Joined: Thu Jul 11, 2013 2:37 pm

Re: Raspberry Pi B+ turn usb power off

Mon Dec 08, 2014 10:58 pm

mahjongg wrote:the PI (B+) has NO hardware in place to disconnect power to the USB ports!

it can detect a short, (USB power Fault) and then the USB power controller (P2553W6) will automatically block the USB power, but the PI cannot turn off the USB power using software. What it can do is bring the LAN9514 into sleep mode, but that does NOT turn the power off!
Yes it can.

Issuing a USB Hub class request (CLEAR_FEATURE PORT_POWER) to port 2 on the LAN9514 will deactivate the USB output power switch.

There's an app for that:

https://github.com/codazoda/hub-ctrl.c
Rockets are loud.
https://astro-pi.org

beta-tester
Posts: 1593
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Raspberry Pi B+ turn usb power off

Tue Dec 09, 2014 6:02 am

by watching the schematics of old modle A and B, the ubs powerline is hardwired directly without any possible control.
the schematic of the computer module shows, that the usb power seems to be not controled as well.

the full schematic of model A+ and B+ i can not find on the documents github at schematics section :o :x

what i see on my Modle B compared to my Modle B+, when i "sudo poweroff" it is, that connected usb devices on a Modle B stays powered on and at Modle B+ they turned off. so i think it is like "jdb" told, it is possible to control the power on a RPi Modle B+ (Modle A+).
jdb wrote:Yes it can...
PS.: does anybody know, why there is no full schematic on the github.com/raspberrypi/documentation/hardware/raspberrypi/schematics
section available for RPi Model B+ and A+ ? :? :?:
(the partial schematics of Modle B+ is a kind of joke)
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
rpdom
Posts: 22820
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Raspberry Pi B+ turn usb power off

Tue Dec 09, 2014 6:44 am

beta-tester wrote:PS.: does anybody know, why there is no full schematic on the github.com/raspberrypi/documentation/hardware/raspberrypi/schematics
section available for RPi Model B+ and A+ ?
Because no one has had the time to generate the full schematics in a generally usable format yet.

strawberry
Posts: 71
Joined: Tue Oct 30, 2012 10:44 am

Re: Raspberry Pi B+ turn usb power off

Tue Dec 09, 2014 4:56 pm

jdb wrote:
mahjongg wrote:the PI (B+) has NO hardware in place to disconnect power to the USB ports!

it can detect a short, (USB power Fault) and then the USB power controller (P2553W6) will automatically block the USB power, but the PI cannot turn off the USB power using software. What it can do is bring the LAN9514 into sleep mode, but that does NOT turn the power off!
Yes it can.

Issuing a USB Hub class request (CLEAR_FEATURE PORT_POWER) to port 2 on the LAN9514 will deactivate the USB output power switch.

There's an app for that:

https://github.com/codazoda/hub-ctrl.c
Thanks for the information! This will be usefull to reset my 3G modem if it stops responding :D

NicoVanDerDussen
Posts: 74
Joined: Sat Aug 24, 2013 2:41 pm

Re: Raspberry Pi B+ turn usb power off

Thu Dec 11, 2014 5:12 pm

Won't

sudo udevadm trigger

not be easier to reset an errant 3G modem?
Setting up your Raspberry Pi to work with a 3G dongle http://nvdd.info/11gKrsZ

cancunia
Posts: 21
Joined: Wed Dec 26, 2012 5:12 pm

Re: Raspberry Pi B+ turn usb power off

Mon Jan 05, 2015 2:12 pm

I came across this thread yesterday and can confirm that hub-ctrl with '-h 0 -P 2 -p 0' will turn off ALL of the USB ports and by the looks of things the Ethernet port off too. If there's any finer granularity than all or nothing possible, please let me know. Thx

strawberry
Posts: 71
Joined: Tue Oct 30, 2012 10:44 am

Re: Raspberry Pi B+ turn usb power off

Mon Jan 05, 2015 4:46 pm

For me this works 'hub-ctrl -h 0 -P 2 -p 0', it turns off only 1 port.
But you can turn off the Ethernet port with this command (if you another -P value).

cancunia
Posts: 21
Joined: Wed Dec 26, 2012 5:12 pm

Re: Raspberry Pi B+ turn usb power off

Mon Jan 05, 2015 4:51 pm

Interesting, that looks to be the exact same thing that I did, but I'm certain that all of my USB ports went off (or at least 2 of them), plus the Ethernet would no longer work. I had to power cycle to get back in again.

Tarcas
Posts: 741
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: Raspberry Pi B+ turn usb power off

Sun Jan 11, 2015 12:10 am

cancunia wrote:I came across this thread yesterday and can confirm that hub-ctrl with '-h 0 -P 2 -p 0' will turn off ALL of the USB ports and by the looks of things the Ethernet port off too. If there's any finer granularity than all or nothing possible, please let me know. Thx
The Ethernet going off too does not surprise me at all, since it is actually a USB device being driven by the USB hub chip.

I was aware that the B ran the USB power directly from the 5v rail, but was not aware that this was changed in the B+. If it is controllable on a port-by-port basis, this could be very useful. In addition to the obvious abilities to shut off USB devices to save power, or to power cycle them, you could power certain 5v non-USB devices from a USB port and switch them on and off at will, essentially providing four outputs running at 5v. Potentially very handy! I'll definitely have to remember that.

max_rome
Posts: 3
Joined: Fri Mar 13, 2015 7:52 am

Re: Raspberry Pi B+ turn usb power off

Thu Mar 19, 2015 1:00 pm

Why not use a mosfet to switch on/off the usb 5v? I think you could control the mosfet with a GPIO pin

strawberry
Posts: 71
Joined: Tue Oct 30, 2012 10:44 am

Re: Raspberry Pi B+ turn usb power off

Fri Mar 20, 2015 5:10 pm

Yes that is how I did it on the Raspberry B but then you need to cut an USB cable for each device you want to control.
So if the mosfet is already there in the USB hub it is much easier to turn the device on/off with a command to the hub.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 15100
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Raspberry Pi B+ turn usb power off

Fri Mar 20, 2015 7:36 pm

the USB current monitor can be turned off by disabling the current monitor, the LAN9512 has its own I/O, and the signal PRTCTL2 (pin 14) that normally monitors an overload can be programmed as output, and then can turn of the current monitor, which cuts USB current.

Another thread in this forum taks about this in detail, including a piece of schematic.

jctlmm
Posts: 11
Joined: Fri May 08, 2015 12:22 am

Re: Raspberry Pi B+ turn usb power off

Tue May 12, 2015 1:56 am

It is my understanding that on the B+ if you turn off the USB HUB you will turn Ethernet as well. You can not disable one or the other.

You can use the following commands to achieve this:

Code: Select all

echo 0 > /sys/devices/platform/bcm2708_usb/buspower;
echo 1 > /sys/devices/platform/bcm2708_usb/buspower;
I have tried them by myself and unfortunately when I keep turning the USB HUB ON/OFF constantly, at some point the R-Pi hangs and I have to manually reboot it.

I'll try the hub-ctrl.c to see if it is more robust...

edo1
Posts: 169
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia

Re: Raspberry Pi B+ turn usb power off

Fri Aug 07, 2015 2:47 pm

I tried hub-ctrl.c:

Code: Select all

while (true) do hub-ctrl  -h 0 -P 2 -p 0 ; sleep 3; hub-ctrl  -h 0 -P 2 -p 1; sleep 57; done
it worked for 24hrs without any problem.

polioman
Posts: 26
Joined: Tue Aug 25, 2015 1:33 pm

Re: Raspberry Pi B+ turn usb power off

Wed Sep 09, 2015 2:29 pm

I tried hub-crtl.c with some success on a Pi 2 :

Reset ETH 0, and I lost my connection (have to reboot)

Code: Select all

sudo ./hub-ctrl -h 0 -P 1 -p 0 ; sleep 3; sudo ./hub-ctrl  -h 0 -P 1 -p 1
Reset all USB and ETH

Code: Select all

sudo ./hub-ctrl -h 0 -P 2 -p 0 ; sleep 3; sudo ./hub-ctrl  -h 0 -P 2 -p 1
Reset USB 4

Code: Select all

sudo ./hub-ctrl -h 0 -P 3 -p 0 ; sleep 3; sudo ./hub-ctrl  -h 0 -P 3 -p 1
Reset USB 2

Code: Select all

sudo ./hub-ctrl -h 0 -P 4 -p 0 ; sleep 3; sudo ./hub-ctrl  -h 0 -P 4 -p 1
Reset USB 3

Code: Select all

sudo ./hub-ctrl -h 0 -P 4 -p 0 ; sleep 3; sudo ./hub-ctrl  -h 0 -P 4 -p 1
raspberry_pi_Pi_USB_side_noted-2.jpg
USB side with annotations
raspberry_pi_Pi_USB_side_noted-2.jpg (45.38 KiB) Viewed 118136 times
I didn't find how to reset USB 1.
I want to reset USB connection on USB modem, I think I can do it with that tool but it doesn't work well at the moment.

emueyes
Posts: 5
Joined: Sun Oct 04, 2015 6:23 am

Re: Raspberry Pi B+ turn usb power off

Mon Jan 25, 2016 1:33 am

I know this is an old thread but I'm hoping an answer has been found for it. I'd like to attach an Arduino to my Model 2 Pi, but I don't want the Arduino to draw power from the USB port on the Pi (its default action). If the Arduino is supplied with 7+ volts on its RAW input, it will use that instead of USB power, but the power curve is terrible, the Arduino wastes a lot of energy.

It (the Ardiuono) has a 5V in, and will use either that or the USB port for power, whichever has the higher voltage. There's already a 5V rail in my circuit, but I can imagine the Pi flipping around if the voltages vary a bit between say 5.04V and 5.06V, for example.

So, is it OK to split open a USB cable and disconnect its power wire, then expect it to work properly ?

The reason for all of this is the Pi's USB power output isn't very strong, powering a USB WiFi dongle and 2 Arduinos won't work.

User avatar
GTR2Fan
Posts: 1968
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Raspberry Pi B+ turn usb power off

Mon Jan 25, 2016 1:42 am

I don't know if this will help you or not, but your Pi2B (assuming that's what you mean by "model 2 Pi") can supply up to a total of 1.2A via its USB ports if you add...

Code: Select all

max_usb_current=1
...to your config.txt file. That's assuming that your Pi PSU can supply the extra current of course.
Pi4B 2GB Rev1.4 Mini-PC/Media Centre: ARM=2.25GHz @1.1v, Core=600MHz, GPU=850MHz. Raspberry Pi OS with KODI on 128GB Sandisk Extreme Pro A2 microSD card in Integral card reader in USB3.0 port (138MB/s read). Geekworm P173 case with copper shim on SOC.

emueyes
Posts: 5
Joined: Sun Oct 04, 2015 6:23 am

Re: Raspberry Pi B+ turn usb power off

Mon Jan 25, 2016 3:23 am

Thanks, I didn't realise that, it should be more than enough for my needs. Yep, it is a RPi2B.

hoodwinked
Posts: 1
Joined: Tue Feb 23, 2016 8:38 am

Re: Raspberry Pi B+ turn usb power off

Tue Feb 23, 2016 8:48 am

Hello,
I have a Raspberry Pi 2 B and I am experimenting witih hub-ctrl for power cycling the USB. For my applicatoin, I need to power on and off certain USB ports.

I found this code, contrary to what a previous poster said, power cylces all USB ports but NOT the ethernet. It successfully cuts the +5v power to all the USB.

Code: Select all

sudo ./hub-ctrl -h 0 -P 2 -p 0 ; sleep 3; sudo ./hub-ctrl  -h 0 -P 2 -p 1
This works as a crude method of cycling the power, except I would rather use per port switching if possible. If I switch the -P flag for hub-ctrl to "-P 4" or "-P 5" it works individually for USB ports 2 and 3 as desired, but it only cuts the DATA signal from the USB and not the +5v power, so the devices don't fully power on and off.

Does anyone know of a solution to cycle the +5v power on individual ports via software? Thanks for any help!

DavidVTaylor
Posts: 12
Joined: Mon Oct 12, 2015 5:16 pm

Re: Raspberry Pi B+ turn usb power off

Sun Mar 06, 2016 4:11 am

Just tested this with the Pi 3 in case anyone is interested. Here is what I am seeing. The USB port numbering from the picture posted above:

Hub:Port -- Controlled port(s)
0:1 -- Controls the Ethernet port
0:2 -- Controls all four USB ports (not the Ethernet)
0:3 -- Controls USB Port 4
0:4 -- Controls USB Port 2
0:5 -- Controls USB Port 3

As best I can tell, USB Port 1 cannot be controlled individually. I was expecting 0:2 to map to USB Port 1, but it is being used to control all of the USB ports.

User avatar
DougieLawson
Posts: 42772
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Raspberry Pi B+ turn usb power off

Sun Mar 06, 2016 7:39 am

You get a better picture by running a lsusb -t (ell, ess, you, ess, bee, space, minus, tee) command.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Return to “Advanced users”