Raspberry Pi 4 Model B: External Power Button With USB Fan

How I Got Here

I recently built a Printer-box enclosure for my Prusa i3 MK3S. My mantra is go big or go home, so I went for the whole package with low-voltage LED’s, exhaust fan, 4Gb Raspberry Pi 4B, Logitech C920 camera and modular control panel. My electronics skills are weak at best, so I followed a combination of the printer-box wiring diagrams and Colin Hill’s awesome videos.

After everything was done, I discovered the problem. The Pi 4 Rev 1.1 doesn’t power off the USB ports when it goes into standby. I’d click the pushbutton to stop the Pi, then have to unplug the Pi or buck converter to stop the fan. I found an alternate config that would stop the fan, but it also prevented the Pi from rebooting when the button was pushed again.

If you’re interested in the details, you can read all about WAKE_ON_GPIO and POWER_OFF_ON_HALT.

How To Fix It

pi@octopi:~ $ sudo apt-get install libusb-1.0-0-dev
pi@octopi:~ $ git clone https://github.com/mvp/uhubctl
pi@octopi:~ $ cd uhubctl
pi@octopi:~ $ sudo make install
  • Edit the bootloader configuration:
pi@octopi:~ $ sudo -E rpi-eeprom-config --edit
    • Verify WAKE_ON_GPIO and POWER_OFF_ON_HALT are configured as follows:
WAKE_ON_GPIO=2
POWER_OFF_ON_HALT=0
    • Save the configuration, reboot and verify:
pi@octopi:~ $ sudo reboot
pi@octopi:~ $ rpi-eeprom-config

[all]
BOOT_UART=0
WAKE_ON_GPIO=2
POWER_OFF_ON_HALT=0
DHCP_TIMEOUT=45000
DHCP_REQ_TIMEOUT=4000
TFTP_FILE_TIMEOUT=30000
ENABLE_SELF_UPDATE=1
DISABLE_HDMI=0
BOOT_ORDER=0xf41
pi@octopi:~ $
  • Identify the USB hubs:
pi@octopi:~ $ sudo uhubctl
Current status for hub 2 [1d6b:0003 Linux 5.10.103-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: 0503 power highspeed enable connect [046d:082d HD Pro Webcam C920 5B5DD3AF]
Port 4: 0103 power enable connect [2c99:0002 Prusa Research (prusa3d.com) Original Prusa i3 MK3 CZPX2118X004XK64851]
Current status for hub 1 [1d6b:0002 Linux 5.10.103-v7l+ xhci-hcd xHCI Host Controller 0000:01:00.0, USB 2.00, 1 ports, ppps]
Port 1: 0503 power highspeed enable connect [2109:3431 USB2.0 Hub, USB 2.10, 4 ports, ppps]
pi@octopi:~ $

I know my fan is connected to the same hub as my webcam & MK3, so I’m going to target hub 1-1 during shutdown.

  • Use your favorite text editor to create the magic script in the `/lib/systemd/system-shutdown` directory with the following contents:
#!/bin/bash

echo "Stopping USB..."
uhubctl -l 1-1 -a off

The -l limits the operation to hub 1-1. The command will not operate on multiple hubs at once. The -a turns the USB off (or on). Note that this command turns off all ports. This should be fine because there’s no reason to keep any ports running if you’re going into standby.

  • Make the script executable and reboot
pi@octopi:~ $ chmod 0755 /lib/systemd/system-shutdown/name-of-script
pi@octopi:~ $ sudo reboot

That’s it. You should now be able to use the pushbutton to turn the Pi and fan on and off.

 

Alaska 2022

TL;DR This trip has been on my bucket list for a few years. If you’ve never been, I’d highly recommend you plan on changing that. So far, it’s one of my favorite adventures and I’d definitely do it again.

Tom and I aren’t really into glitzy cruise ship vacations — we’re more get off the beaten path, mingle with the locals travelers. So when we decided we were going to do this, we knew we’d spend a lot of time on the road.

Since you can’t drive to Juneau, we flew in to spend a couple of days, flew to Glacier Bay and back, then flew to Anchorage where we picked up a Wrangler that would stay with us for the rest of the trip. From Anchorage, we drove to Kennicott, Fairbanks, Denali and back to Anchorage with a few short side trips to Talkeetna and Girdwood. 17 days and we could have probably spent another day or two.

Continue reading

Quick & Dirty Chili

I’ve always made my chili from scratch because those seasoning packets you buy in the grocery store are pretty underwhelming. Last night, I was tired, the spice rack was low on a few items… but I did have two packets of Old El Paso. I doctored it up and it was pretty close to my home made.Continue reading

Best Instant Pot Yogurt

If you’re interested in making your own yogurt to save money, this probably isn’t the recipe you want. On the other hand, if you love yogurt and you’re looking for a healthier alternative snack to replace that 1/2 gallon of ice cream in your freezer, you may have just struck gold.Continue reading

Instant Pot Potato Salad

I love potato salad and always bought the tubs from the deli counter at the grocery store. It’s edible, but I find it incredibly dry and flavorless. I’ve adapted my old recipe for the Instant Pot and I won’t be going back to store-bought.

Continue reading