VifyrV
Posts: 1
Joined: Thu May 06, 2021 11:42 am

Is it possible to add a command to the shutdown and boot to turn off the USB ports

Thu May 06, 2021 12:23 pm

Hi. I have a Raspberry Pi 4b and I have wired an arcade button to GPIO 5 and 6 to shutdown and start up. However. It would be nice to have an indicator to show that the Pi is running. I’m using a very short 5 LED usb light strip as part of my enclosure.

Is it possible to add a command to the shutdown and boot to turn off the USB ports and turn them back on when the PO starts running again?

If so how would I go about doing that? I am pretty new to the Rpi ecosystem so laymen’s terms would be much appreciated. Also can I just load up the microSD card to my pc and edit boot and shutdown scripts? This is the first place I would look if I’m trying to figure out how to do this own my own. But somebody stop me if that’s the wrong way to go about it.

User avatar
thagrol
Posts: 4941
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Power down USB ports on shutdown

Thu May 06, 2021 4:41 pm

Edit:
Sorry, I completely misunderstood what you were asking.

While the below is a couple of way to provide a power on indicator it doesn't work with USB connected LEDs. Leaving it here as an alternative approach.

IIRC, there is a mechanism to turn off power to USB ports under linux but on pre 4B Pi it would turn off all the ports. I've no idea what a 4B will do.

This link may be of interest:https://stackoverflow.com/questions/597 ... berry-pi-4

Once again, sorry for my misunderstanding.

End edit.




I'm assuming you're referring to the physical pin numbers on the connector not the BCM (broadcome) numbers used elsewhere.

While it is possible to add code to do what you want to, there are a couple of simpler hacks that will do it:
    1. Using sudo raspi-config make sure the serial port is enabled. Whether a login is available or not via it isn't important.
    2. Connect an LED with a 330ohm resistor in series between the TX (physical pni 8, BCM pin 14) pin and any ground pin.
    On boot, the OS will bring up the serial port which will turn on the LED. On shutdown, it brings down the serial port turning off the LED.
    1. Pick a GPIO.
    2. Find out it's BCM number
    3. Open /boot/config.txt in your favourite text editor (on RPiOS not windows). You'll probably need to be root or use sudo
    4. Add the following to the end of the file replacing N with the pin number from step 2:

      Code: Select all

      gpio=N=op,dh
    The LED will be turned on during boot and off at shutdown.
    See https://www.raspberrypi.org/documentati ... xt/gpio.md for more on GPIO and config.txt
You might want to check the resistor vaule depending on the LED in use.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Return to “Beginners”