Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save takeshiyako2/5b78f21814b68d75de3674dde3fffe13 to your computer and use it in GitHub Desktop.
Save takeshiyako2/5b78f21814b68d75de3674dde3fffe13 to your computer and use it in GitHub Desktop.
Raspberry Pi 4 - USB power ON/OFF by uhubctl

Issue

I want to USB power ON/OFF on Raspberry Pi 4.
Raspberry Pi 4でUSBパワーをON/OFFしたい。

Raspberry PiのUSBポートに直接LEDライトを接続してオンオフを試しました。
ここでは、https://github.com/mvp/uhubctl というユーティリティを使います。
https://github.com/codazoda/hub-ctrl.c も、だいたい同じことができるようですが、こちらの uhubctl の方が扱いやすそうだったので、こちらを選びました。

個別のUSBポートのパワーのON/OFFはできないようで、全てのUSBポートのパワーを一緒に操作しています。

How it works

Install uhubct

$ sudo apt-get install libusb-1.0-0-dev
$ git clone https://github.com/mvp/uhubctl
$ cd uhubctl/
$ make
$ sudo make install

Show status of devices

$ sudo uhubctl
Current status for hub 3 [1d6b:0002 Linux 5.4.83-v7l+ dwc2_hsotg DWC OTG Controller fe980000.usb, USB 2.00, 1 ports, ppps]
  Port 1: 0000 off
Current status for hub 2 [1d6b:0003 Linux 5.4.83-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 3.00, 4 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
  Port 2: 02a0 power 5gbps Rx.Detect
  Port 3: 02a0 power 5gbps Rx.Detect
  Port 4: 02a0 power 5gbps Rx.Detect
Current status for hub 1-1 [2109:3431 USB2.0 Hub, USB 2.10, 4 ports, ppps]
  Port 1: 0100 power
  Port 2: 0100 power
  Port 3: 0100 power
  Port 4: 0100 power
Current status for hub 1 [1d6b:0002 Linux 5.4.83-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 2.00, 1 ports, ppps]
  Port 1: 0507 power highspeed suspend enable connect [2109:3431 USB2.0 Hub, USB 2.10, 4 ports, ppps]

-> hub 1-1 is USB.

All USB power OFF

$ sudo uhubctl -l 1-1 -a 0

All USB power ON

$ sudo uhubctl -l 1-1 -a 1

Gadget

Buy a Raspberry Pi 4 Model B – Raspberry Pi
https://www.raspberrypi.org/products/raspberry-pi-4-model-b/

AC充電器(Type-Cケーブル一体型+USB 3A) - MPA-ACCFW154WF
https://www.elecom.co.jp/products/MPA-ACCFW154WF.html

Raspberry Pi4 Case
https://www.physical-computing.jp/product/1829

Amazon | USB LEDライト パソコン スマートフォン バッテリー アクセサリー インテリアライト (ホワイト) | jolifavori | USBライト 通販
https://www.amazon.co.jp/dp/B06XDGD18R/

References

uhubctlでUSBをON/OFFする
http://nopnop2002.webcrow.jp/USB-SW/USB-SW-4.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment