[LINUX] Power on/off the USB port on the RaspberryPi 4 Model B

What I wanted to do

I wanted to detect anomalies with a webcam connected to the Raspberry Pi and turn the patrol lamp in an anomaly case. (To be exact, I plan to do it from now on) As a result of various investigations, it seemed that turning the power on/off in conjunction with USB was the easiest and without electronic work, but there are some concerns.

--There is no article on Raspberry Pi 4 in the world --In Raspberry Pi 3, is the USB port parent-child relationship? There seems to be various troublesome --As a workaround, it seems to be good to insert another USB-Hub that supports individual power supply ON/OFF.

What I want to do is to rotate the "USB camera" to monitor and move another device with "USB power control", so it is fatal to not be able to turn it on and off individually. However, the Raspberry Pi 4 has a USB3.0 port, which is a big change in hardware, so I wonder if it can be done ...? So I tried it.

Conclusion: I felt like I was able to do it ~~

~~ I was able to turn it on and off completely individually! complete victory! ~~ I felt like I was able to do it, but the connected devices do not work together. .. .. investigating USB per-port power switching - Qiita GitHub - mvp/uhubctl: uhubctl - USB hub per-port power control

1/13 postscript After all, I couldn't do it without inserting another USB hub. Retry to turn on/off the power of the USB port on RaspberryPi 4 Model B -Qiita

I will leave the following as a memo

What you have prepared

Verification procedure

--Connect the camera to one of the USB ports and open Vedeo Stream to view In the state of --, connect the USB power supply gadget to the remaining ports and turn off the power. --VedeoStream does not stop = Confirm that the power supply to the camera does not stop --Verification of the above for each port

Actual procedure

hub-ctrl introduced

sudo apt-get install libusb-dev
wget http://www.gniibe.org/oitoite/ac-power-control-by-USB-hub/hub-ctrl.c
gcc -O2 hub-ctrl.c -o hub-ctrl-armhf-static -lusb -static
sudo cp hub-ctrl-armhf-static /usr/local/bin/hub-ctrl

Check the status of the USB port

in this case. A camera is stuck in port 2 and a mouse is stuck in port 4.

sudo lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 027: ID 05ac:0304 Apple, Inc. Mighty Mouse [Mitsumi, M1152]
Bus 001 Device 026: ID 1e4e:0100 Cubeternet WebCam
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

You can see that it seems to have different roots for USB 2.0 and 3.0.

sudo hub-ctrl -v
Hub #0 at 002:001
 INFO: ganged switching.
 WARN: Port indicators are NOT supported.
 Hub Port Status:
Hub #1 at 001:002
 INFO: ganged switching.
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0103 power enable connect
   Port 3: 0000.0100 power
   Port 4: 0000.0303 lowspeed power enable connect
Hub #2 at 001:001
 INFO: individual power switching.
 WARN: Port indicators are NOT supported.
 Hub Port Status:
   Port 1: 0000.0503 highspeed power enable connect

Hub # 1 seems to be USB related, Hub # 2 seems to be Ethernet. After all, USB 2.0 and 3.0 belong to the same Hub here. The physical arrangement looks like this. In Raspberry Pi 3, it's a little nice that it started from Port 2 but now from 1.

 LAN
+---+  Port1 Port2(USB3.0)
|   |
+---+  Port3 Port4(USB2.0)

Try power supply control


sudo hub-ctrl -b 1 -d 2 -P 4 -p 0 -v
 Hub Port Status:
Hub #1 at 001:002
 INFO: ganged switching.
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0103 power enable connect
   Port 3: 0000.0100 power
   Port 4: 0000.0303 lowspeed power enable connect
 Hub Port Status:
   Port 1: 0000.0503 highspeed power enable connect
Send control message (REQUEST=1, FEATURE=8, INDEX=4)
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0103 power enable connect
   Port 3: 0000.0100 power
   Port 4: 0000.0000

Command options

-b Bus No Hub#1 at 001:002 to 001
-d Device No Hub#1 at 001:002 002 * Device that appears in lsusb is irrelevant
-P PortNo (USB port number)
-p 0:OFF 1:ON
-v Advanced display option (usually not required)

Reference article

Play with raspberry pi 3 b \ + and patrol lamp -Real estate information bot Turn on/off the USB port on the RaspberryPI 3 Model B: PC Bird Blog

Recommended Posts

Power on/off the USB port on the RaspberryPi 4 Model B
Retry to turn on/off the power of the USB port on RaspberryPi 4 Model B
Step 2 to install Xenomai on RaspberryPi 3 model B +
Procedure for installing Xenomai on RaspberryPi 3 model B + Part 1
Power on/off the USB port on the RaspberryPi 4 Model B
USB boot on Raspberry Pi 4 Model B
Step 2 to install Xenomai on RaspberryPi 3 model B +
Procedure for installing Xenomai on RaspberryPi 3 model B + Part 1
Control power on / off of USB port of Raspberry Pi
Could not install python3.8.1 grovepi module on RaspberryPi Model 3B (solved)
Let's simulate the Izhikevich neuron model on the web!
Customize the model page on Django's admin screen