Raspberry Pi B+ turn usb power off


35 posts   Page 1 of 2   1, 2
by strawberry » 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+?
Posts: 39
Joined: Tue Oct 30, 2012 10:44 am
by DougieLawson » Mon Dec 08, 2014 9:42 am
There isn't.

Use an in-line hardware switch.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.
User avatar
Posts: 27875
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by Paul Webster » 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
Posts: 657
Joined: Sat Jul 30, 2011 4:49 am
Location: London, UK
by mahjongg » 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.
User avatar
Forum Moderator
Forum Moderator
Posts: 9137
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands
by jdb » 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
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1640
Joined: Thu Jul 11, 2013 2:37 pm
by beta-tester » 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 Model B (rev1, 256MB) & B (rev2, 512MB) & B+, RPi2B (1GB), 64GB microSDXC1 class 10, HDMI 1920x1080, keyboard-mouse-combo (wireless), PiCamera, ethernet-cable, 5V/1.2A power supply, Wifi dongle (rt5370)
Posts: 857
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE
by rpdom » 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.
User avatar
Posts: 10669
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK
by strawberry » 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
Posts: 39
Joined: Tue Oct 30, 2012 10:44 am
by NicoVanDerDussen » 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
Posts: 74
Joined: Sat Aug 24, 2013 2:41 pm
by cancunia » 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
Posts: 21
Joined: Wed Dec 26, 2012 5:12 pm
by strawberry » 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).
Posts: 39
Joined: Tue Oct 30, 2012 10:44 am
by cancunia » 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.
Posts: 21
Joined: Wed Dec 26, 2012 5:12 pm
by Tarcas » 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.
Posts: 739
Joined: Thu Jan 09, 2014 5:38 am
Location: USA
by max_rome » 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
Posts: 3
Joined: Fri Mar 13, 2015 7:52 am
by strawberry » 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.
Posts: 39
Joined: Tue Oct 30, 2012 10:44 am
by mahjongg » 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.
User avatar
Forum Moderator
Forum Moderator
Posts: 9137
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands
by jctlmm » 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...
Posts: 11
Joined: Fri May 08, 2015 12:22 am
by edo1 » 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.
Posts: 136
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia
by polioman » 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 28097 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.
Posts: 26
Joined: Tue Aug 25, 2015 1:33 pm
by emueyes » 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.
Posts: 5
Joined: Sun Oct 04, 2015 6:23 am
by GTR2Fan » 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.
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.
User avatar
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK
by emueyes » 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.
Posts: 5
Joined: Sun Oct 04, 2015 6:23 am
by hoodwinked » 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!
Posts: 1
Joined: Tue Feb 23, 2016 8:38 am
by DavidVTaylor » 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.
Posts: 7
Joined: Mon Oct 12, 2015 5:16 pm
by DougieLawson » 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.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.
User avatar
Posts: 27875
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK