Shipwright
Posts: 1
Joined: Mon Jun 20, 2016 7:02 pm
Location: London, UK

Re: Raspberry Pi B+ turn usb power off

Mon Jun 20, 2016 7:38 pm

Is someone able to give me the text for turning one hub on/off, please? I have read this and other posts and concluded that this should turn USB 4 off:

Code: Select all

./hub-ctrl -h 0 -P 3 -p 0
but I just get:

Code: Select all

-bash: ./hub-ctrl: No such file or directory
The problem I am trying to solve is connecting two 2.5" HDDs to a Pi and powering them from an external USB source. I am using a pair of these connectors with a 2.1A USB source (an original iPad charger) and no matter how I mess with the cables I can only ever get one of them to work, presumably because the Pi is saying to itself that it needs to power the discs and it can’t.
SATA.jpg
2.5" SATA Data and supplementary power connector
SATA.jpg (8.88 KiB) Viewed 9860 times
I have thought that I need to start making cables using Banana Pi connectors and SATA data convertors. However, if I can turn the power off to the USB I can use the cables I have, powered from the 2.1A USB power supply. This would be altogether simpler and neater.
banana.jpg
Banana Pi SATA and power cable
banana.jpg (2.17 KiB) Viewed 9860 times
Lastly, does the command persist after a shutdown or do I need to re-enter it on every boot? Can it be made to persist?

Thanks.
Raspberry Pi 3 model B
Open Media Vault (OMV) 2.1 Stone Burner
Logitech Media Server (LMS) 7.9

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

Re: Raspberry Pi B+ turn usb power off

Tue Jun 21, 2016 4:09 pm

You must first download the source code and compile the hub-ctrl program before you can use the command:

Code: Select all

sudo apt-get update
sudo apt-get install git gcc libusb-dev
git clone https://github.com/codazoda/hub-ctrl.c
gcc -o hub-ctrl hub-ctrl.c -lusb
After that you can use sudo ./hub-ctrl ...

Highlander88
Posts: 8
Joined: Fri Aug 22, 2014 4:20 pm

Re: Raspberry Pi B+ turn usb power off

Mon Aug 29, 2016 1:26 pm

Hello, I own a Raspberry Pi Model B 1st gen and I've succesfully compiled and used hub-ctrl to turn off my usb devices, I've discovered that:

Turns off Ethernet

Code: Select all

hub-ctrl -h 0 -P 1 -p 0
Turns off top USB port

Code: Select all

hub-ctrl -h 0 -P 2 -p 0
Turns off bottom USB port

Code: Select all

hub-ctrl -h 0 -P 3 -p 0
I hope that's useful for other users.

Barlow111
Posts: 1
Joined: Mon Dec 19, 2016 9:50 pm

Re: Raspberry Pi B+ turn usb power off

Mon Dec 19, 2016 10:02 pm

Hi!

I have been trying these hub-ctrl commands in my Raspberry 2B and 3, and I think it's not true you can turn the usb power off.
If you connect a USB wifi in port USB 2 and you type

sudo ./hub-ctrl -h 0 -P 4 -p 0

yes, it doesn't work anymore. But the USB port has power. If I connect my mini speaker to that port, I can charge my mini speaker. The port has power.

The same with USB 3, and 4. They "don't work", but they have power.

But, if you type

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

then, yes. You don't have power in any of the USB ports. So, as pointed out in a previous message, it seems it's not possible to turn the power off of a single USB port.

For my project, I need to turn the power off of a single USB port (completely off), and I think it's not possible.

Best,
b.-

georgestewart88
Posts: 83
Joined: Fri Apr 15, 2016 6:19 am

Re: Raspberry Pi B+ turn usb power off

Thu Jan 12, 2017 6:04 pm

DavidVTaylor wrote: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.
Could you help me out? I'm trying on my Pi 3, and I keep getting the following...

./hub-ctrl: 1: ./hub-ctrl: 1: not found

Here's my output of lsusb -t

Code: Select all

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
        |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
        |__ Port 4: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
            |__ Port 1: Dev 7, If 0, Class=Video, Driver=uvcvideo, 480M
            |__ Port 1: Dev 7, If 1, Class=Video, Driver=uvcvideo, 480M
            |__ Port 1: Dev 7, If 2, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 1: Dev 7, If 3, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 2: Dev 8, If 0, Class=Video, Driver=uvcvideo, 480M
            |__ Port 2: Dev 8, If 1, Class=Video, Driver=uvcvideo, 480M
            |__ Port 2: Dev 8, If 2, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 2: Dev 8, If 3, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 3: Dev 9, If 0, Class=Video, Driver=uvcvideo, 480M
            |__ Port 3: Dev 9, If 1, Class=Video, Driver=uvcvideo, 480M
            |__ Port 3: Dev 9, If 2, Class=Audio, Driver=snd-usb-audio, 480M
            |__ Port 3: Dev 9, If 3, Class=Audio, Driver=snd-usb-audio, 480M

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

Re: Raspberry Pi B+ turn usb power off

Fri Jan 13, 2017 9:10 am

Hi,

Did you follow the instructions from here https://github.com/codazoda/hub-ctrl.c?

It seems you do not have it installed or you're in the right folder.

wildplay
Posts: 2
Joined: Tue Feb 21, 2017 6:20 pm

Re: Raspberry Pi B+ turn usb power off

Wed Feb 22, 2017 7:27 pm

Hi, all. I tried this code for my usb modem.

Code: Select all

sudo ./hub-ctrl -h 0 -P 4 -p 0
But! Power blinking for a moment and comes back again.

When I type

Code: Select all

lsusb
I see my modem in the list with a different Devices number. How can I fix it?

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

Re: Raspberry Pi B+ turn usb power off

Fri Feb 24, 2017 8:54 am

wildplay wrote: I see my modem in the list with a different Devices number. How can I fix it?
You can not change this number by yourself, the system does it automatically (as far as I know).

Why do you need this USB ID, or what do you want to do with it?

If you've got others USB peripherals connected, they might swap their ID during boot.

wildplay
Posts: 2
Joined: Tue Feb 21, 2017 6:20 pm

Re: Raspberry Pi B+ turn usb power off

Sun Feb 26, 2017 5:41 pm

The modem does not go off. It is automatically recognized by the system as a new device.

Adrian-Rosoga
Posts: 4
Joined: Sat Jan 11, 2014 1:12 pm

Re: Raspberry Pi B+ turn usb power off

Thu Mar 16, 2017 3:02 pm

Hi there.

After reading this thread and experimenting myself it looks like there is really no possibility to turn off the power on the Pi USB ports.

Does anyone know though an USB hub available in UK right now that can be controlled via the mentioned programs? I googled the ones mentioned but cannot get hold of one from Amazon/Ebay/etc.

Or an inline USB switch that can be controlled via the Pi?

Thanks.

Adrian

User avatar
ibshar
Posts: 22
Joined: Sun Jul 31, 2016 3:00 pm

Re: Raspberry Pi B+ turn usb power off

Sun Aug 27, 2017 9:23 am

Adrian-Rosoga wrote:
Thu Mar 16, 2017 3:02 pm
Hi there.

After reading this thread and experimenting myself it looks like there is really no possibility to turn off the power on the Pi USB ports.

Does anyone know though an USB hub available in UK right now that can be controlled via the mentioned programs? I googled the ones mentioned but cannot get hold of one from Amazon/Ebay/etc.

Or an inline USB switch that can be controlled via the Pi?

Thanks.

Adrian
As an alternative, you could use a Relay switch, connect a USB power adapter and control that. But that's only for USB light or something which just needs power, not data.

roycejp
Posts: 19
Joined: Sun Oct 27, 2013 7:48 am

Re: Raspberry Pi B+ turn usb power off

Sun Sep 03, 2017 8:01 am

It seems you can control individual devices connected to the USB ports.

The hub-ctrl.c github page at https://github.com/codazoda/hub-ctrl.c says:
You can also specify the USB device based on the BUS and DEV numbers. Use the following command the list the currently connected devices. It's useful to run this with the device disconnected and then again with the device connected so that you can tell which device is the one you are trying to target (the Targus in my case).

Code: Select all

lsusb
Now that we know the BUS and DEV numbers, we can control the power using those numbers as well. Here's the command for that.

Code: Select all

sudo ./hub-ctrl -b 001 -d 005 -P1 -p 0
This time we are controlling the device on BUS 001 (-b 001) device 005 (-d 005) port 1 (-P 1) and turning the power off (-p 0).

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

Re: Raspberry Pi B+ turn usb power off

Sun Sep 03, 2017 8:27 am

roycejp wrote:
Sun Sep 03, 2017 8:01 am
It seems you can control individual devices connected to the USB ports.
I doubt it. The power control on the Pi's USB is common to all four ports. You can switch them all on/off at the same time but not individually.

drgeoff
Posts: 9808
Joined: Wed Jan 25, 2012 6:39 pm

Re: Raspberry Pi B+ turn usb power off

Sun Sep 03, 2017 8:30 am

You CANNOT control the individual 5 volt power feeds to the USB sockets on any model of RPi. The 5 volt contacts on all the USB ports are joined together by PCB tracks *. That is a hardware thing and no software can change it.

Yes on some RPis you can turn off the 5 volt feed to ALL the USB sockets. And yes, with the appropriate software commands directed to the LAN & USB chip you can enable and disable the individual USB ports. That may well affect the power consumed by a USB device plugged in to a port, but it does not necessarily power it down completely.

(Except on the first version of the B which had polyfuses in the 5 volt lines to the two USB sockets. But that doesn't change the argument.)

PlanB
Posts: 102
Joined: Tue Oct 28, 2014 6:44 am

Re: Raspberry Pi B+ turn usb power off

Wed Oct 25, 2017 1:22 am

I can't seem to compile this program on a Pi0 with Jessie. Get an error 'undefined reference to `main'
collect2: error: ld returned 1 exit status' and after that the hub-ctrl.c program is gone?!

SlySven
Posts: 6
Joined: Fri Nov 20, 2015 3:39 am

Re: Raspberry Pi B+ turn usb power off

Thu Dec 21, 2017 6:40 am

There is a separate Github based project that is also working on software for the very small proportion of USB Hubs that actually meet the USB specifications about control of the power on their output/downstream ports. Take a look at uhubctl - I (and a Foundation engineer) helped them update their documentation about the RPi family where the B+ and later models allow ALL the USB ports to be controlled by using the control for the second port (and the control for the first one can switch off the wired Ethernet). For power sensitive projects with several USB devices users may want to use a hub from their list that does have the control so that one can switch off only the un-needed ones.

I am still working on a home-automation project with a couple of RFID tag readers to control the electric lock I had included in my replacement front door - and I would like such a hub so that they and other devices can be switched off as appropriate when I am away from home overnight and have the key-operated deadlock in use that prevents electric unlocking or when the Mains Power has failed and the system is running from a home-made UPS.

Hambarde
Posts: 6
Joined: Fri Jun 16, 2017 5:24 am

Re: Raspberry Pi B+ turn usb power off

Tue Apr 03, 2018 1:12 pm

I know this is very very old thread, but got one idea to fix OP's issue without modifying anything in RPi,

Take the usb cable connecting to HDD---RPi USB,

cut the USB cable in between, solder a LED to +ve and -ve coming from USB end,
so when RPi wants to power on HDD, only LED will glow.
to the other cut's +ve and -ve connect your power source,
this way pi will he happy giving power and HDD will be happy with taking power from your external source. :lol: :lol:
__________________________________________________________________________________________
:arrow: mail me - [email protected]

sameenashaikh29
Posts: 7
Joined: Thu Jan 11, 2018 7:15 am

Re: Raspberry Pi B+ turn usb power off

Thu Apr 05, 2018 1:40 pm

Hi,
I am able to run the commands sudo ./hub-ctrl -h 2 -p 0 and sudo ./uhubctl -h 2 p 1 as commands and they work fine on my terminal, they work fine after i installed the hub-ctrl from github
and even tried using uhubctl and the commands sudo ./uhubctl a 0 p 2 and sudo ./uhubctl a 1 p 2 work fine for powering on and off through terminal through these commands.
Now i am trying to use it in my python code and i don't find them stable
The instructions i used in my code are
os.system("sudo ./uhubctl a 0 p 2") and os.system("sudo ./uhubctl a 1 p 2") at different instances in my code along with some other instructions. But the code is not stable. Can anyone help me with this. How should i use hub-ctrl or uhubctl in my python code on raspberry pi so as to make my code stable and working at all times.
my camera is connected to one usb port on raspberry pi
I want to power off the usbs, click images on camera, power on the usbs back, and access the camera memory card .
For all this i need to enable and disable the usb..
Any help would be appreciated.
Hoping for a quick response


Thanks & Regards
Sameena Shaikh

sameenashaikh29
Posts: 7
Joined: Thu Jan 11, 2018 7:15 am

Re: Raspberry Pi B+ turn usb power off

Fri Apr 06, 2018 12:37 pm

This is kind my sample code i'm trying to work on, if this works i can add the things i want. But this needs to work first. And in my all in one code, it's mostly not working.
But this doesn't work. Like it does work sometimes, sometimes doesn't. and when its not working every part of my code works except the powering back on

import signal, os, subprocess, sys
import time
import RPi.GPIO as GPIO
from subprocess import call

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(12, GPIO.OUT)

i=0
call(["sudo", "./hub-ctrl", "-h", "0", "-P", "2", "-p", "0"])
time.sleep(2)
while i<5:
print("triggered")
GPIO.output(12, True)
time.sleep(1)
GPIO.output(12, False)
time.sleep(1)
print("done")
i=i+1
print i

print("enabling usb")
#os.system("sudo ./uhubctl -a 1 -p 2 -R")
call(["sudo", "./hub-ctrl", "-h", "0", "-P", "2", "-p", "1"])
time.sleep(2)


I've tried with os.system as well as subprocess.Popen
None of them have given me stability and has ran properly always

sameenashaikh29
Posts: 7
Joined: Thu Jan 11, 2018 7:15 am

Re: Raspberry Pi B+ turn usb power off

Fri Apr 06, 2018 12:38 pm

What i am trying to do
I need to power off the usb so that i can click pictures from my camera and i click pictures once its powered off and then power on back the usb so that i can access the images on my raspberry pi. But these commands when used in code aren't working.

I have tried using subprocess calls

how can i use these commands in my python code?
these commands work fine for me one the terminal, but when i use it with os.system("sudo ./hub-ctrl -h 0 -P 2 -p 1") and os.system ("sudo ./hub-ctrl -h 0 -P 2 -p 0") for power on and off respectively my python code becomes unstable. Could you tell me a solution for this??
Hoping for a quick response.
Thanks & Regards
Sameena Shaikh

ghj
Posts: 1
Joined: Fri Apr 12, 2019 8:04 pm

Re: Raspberry Pi B+ turn usb power off

Fri Apr 12, 2019 8:48 pm

I just started working with 3B+ and had the need to cut power to USB ports as discussed above. Power needs to cut, not just disable port, for power/heat considerations. I came up with this solution, which is sort of easy since RPi is only USB2. You need a couple of parts from Mouser (1 ea. FDC6330L, TNPW0805100KBEEA, UP2-AH-1-TH, USB-A-S-F-W-TH; 2 ea. TNPW08052K00BEEA for each board), and you need to make a small PCB (I would add the Eagle files but this forum won't let me attach them), but it works nicely by running a wire from the pinhole to a GPIO pin on the RPi. There is a pullup on the load switch so that you don't have to have a pin to GPIO for the USB to work. Just need to pull it low to turn the USB port power off. (Sorry the SOT6 is a bit challenging to solder.) Good luck.

nielsbaloe
Posts: 7
Joined: Mon Apr 15, 2019 2:07 pm

Re: Raspberry Pi B+ turn usb power off

Mon Apr 15, 2019 2:35 pm

I'm not sure whether this is the same, but I found out that "udisks --detach" makes my USB-sticks to really shut down. I'm not sure whether it is the power, maybe it is. When I do not detach the drive Windows10 always nags that the stick has to be checked for errors.

Unfortunately the "eject" thingie at the right top does not detach the drive, so I have to do this a lot.

To install:

Code: Select all

sudo apt-get install udisks
and then to unmount disks

Code: Select all

sudo udisks --unmount /dev/sda1
and then to really detach the drive (which is nót the same as eject):

Code: Select all

sudo udisks --detach /dev/sda

mamadero
Posts: 2
Joined: Wed Oct 16, 2019 7:13 am

Re: Raspberry Pi B+ turn usb power off

Wed Oct 16, 2019 7:18 am

At least on the raspberry pi 3 b+ (likely all 3s) the hub is 1, not 0.

The following should turn the power off:

Code: Select all

sudo ./hub-ctrl -h 1 -P 2 -p 0
I suggest you try:

lsusb

and use `bus` and `device` as like suggested on the README:

Code: Select all

sudo ./hub-ctrl -b 001 -d 005 -P1 -p 0

Return to “Advanced users”