Turning off USB port or on

January 28, 2024, 08:35

eriklavr

Hello! I wanted to ask how can i turn off an USB port or turn it off on the rpi in python? It would really help, thanks!

k9t33n

just asking, why?

eriklavr

I have an USB fan for extra cooling

eriklavr

Would be nice if i would be able to turn it on / off remotely

k9t33n

ah ok

k9t33n

one second

k9t33n

pi4 or pi5?

eriklavr

Pi5

eriklavr

Srry for a late response because i was eating lol

k9t33n

its alright

k9t33n

https://raspberrypi.stackexchange.com/questions/5407/how-can-i-cut-power-coming-out-of-the-pis-usb-ports nothing specific to the pi 5 but the responses are very controversial

k9t33n

one person says just straight up no > No, the usb power is hardwired straight to the RPi power. > > You can interrupt the power to the fan with a transistor or a relay, but you'll have to cut the red wire.

eriklavr

what about this thing https://github.com/mvp/uhubctl

k9t33n

whilst another gives you ways to do so: > > > You can use my tool uhubctl, it supports Raspberry Pi models B+, 2B, 3B, 3B+ and 4B - these models have hardware ability to turn USB power off and on. > > Use it like this: > > Turn off power to all USB ports (must use port 2): > >
sudo uhubctl -l 1-1 -p 2 -a 0
> > Turn on power to all USB ports (must use port 2): > >
sudo uhubctl -l 1-1 -p 2 -a 1
> > Turn off power to Wifi+Ethernet (must use port 1): > >
sudo uhubctl -l 1-1 -p 1 -a 0
> > Note that Raspberry Pi 4B is very different from previous models as it has USB3 chip. It doesn't support turning off power to Wifi+Ethernet, and for USB you will need to use something like that to turn off (this turns off all USB ports - RPi 4B hardware does not support individual port power control): > >
sudo uhubctl -l 2 -a 0
> > If your Raspberry Pi does not support USB power switching, you can connect external USB hub that does (see list of compatible models), and control power on that external hub using uhubctl.

k9t33n

was just gonna mention that

eriklavr

yh

eriklavr

should i like do os.system("cmd")

eriklavr

cmd as the command

k9t33n

no clue

k9t33n

and these arent dont even specify that it works with the pi 5 your reaching for it

eriklavr

Im going to try

eriklavr

1 sec

k9t33n

ok

eriklavr

what does the 1 - 1 do

eriklavr

Is there a cmd that finds all the things that are connected

oops.se

The one USB bus should be seen as a branch on a tree, visual by lsusb -t

oops.se


eriklavr

/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/0p, 480M
Prints that

eriklavr

How can i find out which port it is in bc i dont know in which one they start / which order its in

eriklavr

on the rpi

oops.se

 lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 4: Dev 4, If 0, Class=Mass Storage, Driver=uas, 480M

eriklavr

I forgot to format it

eriklavr

whoops

oops.se

So sudo uhubctl -l 1-1 -p 4 is my SSD (class=Mass storage"

eriklavr

So it doesnt recognize mine

eriklavr

ig

eriklavr

Im going to try with the pi 4

oops.se

That was from my Pi4

eriklavr

1 sec

eriklavr

Looks like its an problem from the Rpi5 itself

eriklavr

On the pi 4 it works

oops.se

Probably a driver issue

oops.se

I don't remember if Pi5 has an different USB chip than Pi4

eriklavr

Dont think so

oops.se

Pi 4 - Broadcom BCM2711 Pi 5 - Broadcom BCM2712

eriklavr

Ohh

eriklavr

alr then

eriklavr

Ill try to make something

eriklavr

That works

eriklavr

But do you know if k3s is supported on the rpi 5 or no

k9t33n

doesnt it use the secondary chip for usb and gpio?

oops.se

Correct, "their own" but normally you buy "IP blocks" that you implement on your chip

oops.se

RP1 is their own chip

k9t33n

no i dont mean the RP1 chip but dont they have 2 chips now? i know the secondary is connected to the gpio so you cant overvolt the main chip but not sure if its also for usb

k9t33n

RP1 is the main chip right?

oops.se

RP1 is a chip with for example IP blocks from Synopsys for the USB. https://datasheets.raspberrypi.com/rp1/rp1-peripherals.pdf Controls: - GPIO - UART - RIO - PWM - I2C - SPI - I2S - TICKS - SDIO - USB - PCI Express endpoint controller - Ethernet - Displays and cameras - DMA

k9t33n

oh so the RP1 chip isnt the main?

k9t33n

ignore me then

oops.se

main? No its not the MCU that controls RAM, HDMI

k9t33n

ok i just learnt something new

oops.se

RP1 is the I/O chip

k9t33n

ah

k9t33n

ok ignore me.

oops.se

So to get an understanding if the USB supports power on/off the driver for "Synopsys IP dwc_usb3, v3.30b" needs to be checked

oops.se


oops.se

This is the main chip

k9t33n

yes

oops.se

<@1071178789939331253> And you are correct, Pi5 have a Broadcom BCM2712 that has USB I/O but that is not used. Pi uses its own RP1 as you reminded me off

oops.se

Thx

k9t33n

you taught me something too