0

I am using a Raspberry Pi Zero W running Raspberry Pi OS (32-bit) Lite (Aug 2020).

This is an IoT project where, I have a USB modem that makes my internet connection. When the modem is powered on it draws nearly 100 mA. The modem is connected to the RPi via a USB Mini Hub, where a few other low power USB peripherals are connected to it.

(https://www.digikey.com/htmldatasheets/production/1879845/0/0/1/2991.html)

There is no command to sleep or power down my USB modem. The RPi zero cannot disable the Micro USB since it is in line a 5V trace. In an attempt to power off the modem I would want to disable the drivers or unbind the ports of some sort to the USB Mini Hub, in hopes of cutting power to the USB Modem.

Any idea on how to do this, I saw this posted but, I don't think it is the solution.

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

Thanks

1 Answer 1

2

I've not been able to test this on a PiZero, but it does work on other RPi hardware. It may be worth a try - I'll leave that to you. In either case, please give us the courtesy of some feedback: either you did not try it, or you did & the result.

1. install uhubctl

$ sudo apt update && sudo apt full-upgrade -y
$ sudo apt install uhubctl

2. list USB hubs

$ sudo uhubctl 

# NOTE: my output shown (w/ 1 USB device connected @ Port 2) for illustration

Current status for hub 2 [1d6b:0003 Linux 5.4.51-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 3.00, 4 ports]
  Port 1: 02a0 power 5gbps Rx.Detect
  Port 2: 0203 power 5gbps U0 enable connect [1058:0748 Western Digital My Passport <numeric string>]
  Port 3: 02a0 power 5gbps Rx.Detect
  Port 4: 02a0 power 5gbps Rx.Detect
Current status for hub 1 [1d6b:0002 Linux 5.4.51-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 2.00, 1 ports]
  Port 1: 0507 power highspeed suspend enable connect [2109:3431 USB2.0 Hub, USB 2.10, 4 ports]

If uhubctl finds a USB hub that supports power switching, it will be listed here. It will not list hubs that do not support power switching.

If I understand your setup correctly, you have connected an external hub to your Pi Zero. According to the uhubctl docs, you should be able to power-switch an external hub if that hub supports power-switching.

3. power your hub up or down

Assuming your external hub is listed in Step 2 above, you should now refer to the uhubctl docs for further instructions. As an outline, I would suggest:

  • check the status of the hub of interest using the hub # from above; e.g. for port 2 of my hub 2 from above:
$ sudo uhubctl -l 2 -p 2
Current status for hub 2 [1d6b:0003 Linux 5.4.51-v7l+ xhci-hcd xHCI Host     Controller 0000:01:00.0, USB 3.00, 4 ports]
  Port 2: 0203 power 5gbps U0 enable connect [1058:0748 Western Digital My Passport <numeric string>]
Current status for hub 1 [1d6b:0002 Linux 5.4.51-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 2.00, 1 ports]
  • turn off power to a port (NOTE 1: RPi hardware does not support powering individual ports - all ports are either ON or they are all OFF. NOTE 2: This limitation may or may not apply to an external hub - that will depend on the manufacturer's implementation)
$ sudo uhubctl -l 2 -p 2 -a off 
...
Sent power off request
# more output...
  • check status of powered-off port
$ sudo uhubctl -l 2 -p 2 
Current status for hub 2 [1d6b:0003 Linux 5.4.51-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 3.00, 4 ports]
  Port 2: 0080 off
Current status for hub 1 [1d6b:0002 Linux 5.4.51-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 2.00, 1 ports]

4. Conclusion:

This works on my RPi 4 (as shown above), and has also worked on my Rpi 3B+. AFAIK, it should also work on the RPi Zero - we await your feedback.

EDIT: Have just realized that while uhubctl appears to work on my RPi 4B, it does not. However it does work on my RPi 3B+, and I am told that an upgrade to ver 2.2 of uhubctl will resolve issues with the RPi 4B.


REFERENCES:

  1. Power Management for USB; p/o Docs > The Linux driver API guide > Linux USB API

  2. What is sysfs?

  3. How to turn USB port power on and off in Raspberry PI 4

  4. Raspberry Pi USB Hardware Documentation

  5. GitHub site for uhubctl

  6. GitHub site for hub-ctrl.c

6
  • Great answer! I will be in the lab tomorrow and I can hopefully give this a try or over the weekend. I will let you know my outcome. Cheers.
    – Beaker
    Sep 30, 2020 at 22:42
  • uhubctl author here. To make it work on RPI 4B, you need to make sure to use version 2.2.0 or later, you need to upgrade RPI 4 firmware, and you should use command sudo uhubctl -l 2 -a 0 (turn off all 4 ports).
    – mvp
    Oct 1, 2020 at 7:43
  • 1
    Also, worth noting that RPi Zero USB hub does not support power switching. You will have to use external usb hub supported by uhubctl
    – mvp
    Oct 1, 2020 at 7:48
  • @mvp: 1st comment: Yes - thanks - I covered the version issue in my edit, and linked to the issue on yr github page. Wrt to 0 vs off - just going by your documentation! Plus - I learned that off works exactly the same as 0. :) LOL 2nd comment: Yes - if you read his question, that's exactly what he wants to do - control an external hub.
    – Seamus
    Oct 1, 2020 at 14:17
  • @mvp Ah well, I tried anyways, no luck using the current USB hub I showed above. Are you aware of any similar hubs like the one I have? It seems the Amazon Basic is the only one close, would have to get a micro to 2.0 adapter. How should I update to version 2.2.0 of uhubctl, I am on 2.0.0
    – Beaker
    Oct 6, 2020 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.