Raspberry Pi - Manage Port Power
Web agency » Digital news » Raspberry Pi – Manage Port Power

Raspberry Pi – Manage Port Power

Three years ago, I acquired a Raspberry Pi (the first) model B to set up a small homemade NAS. I had then bought two magnificent hard disks of 3TB each which I had put in a box to carry out a magnificent RAID 1. This installation was good but it had a painful inconvenience… My hard disks never went out! Understand, they never go to sleep, not even when it hadn't been used for several hours.

Faced with this problem, I had looked in vain for a solution allowing me to control the power supply of my USB ports myself… At the time, the Raspberry was almost more in the prototype state and the community was not as big as it is today.

Raspberry Pi 3, there you are!

In recent days, I wanted to invest in a more powerful model. Having heard a lot of good things about the Model 2, I was hoping that this USB power management problem would be fixed, so I decided to buy a new model. Fortunately, the Raspberry Pi 3 was released at the same time, and neither one nor two I ordered.

Sleeping USB devices

After some tests, I realized that my initial problem had not been solved with this new card. So I tried to play with food and BINGO! this time, I found something to do.

Manual power management

First, here is the ticket that allowed me to change the power supply.

And here is the project in C allowing to influence the power supply of the USB ports.

A little bit of command line

$ git clone https://github.com/codazoda/hub-ctrl.c.git $ cd hub-ctrl.c $ sudo apt install -y libusb-dev
$ gcc -o hub-ctrl hub-ctrl.c -lusb

We are good. The project of
Joel Dare
has been compiled and we are now ready to turn on/off our USB devices.

Organizational diagram of USB ports

Play with ports

Note that the USB 1 port cannot be switched off individually.

Switch off

  • USB Port 2
    1
    sudo ./hub-ctrl -h 0 -P 4 -p 0
  • USB Port 3
    1
    sudo ./hub-ctrl -h 0 -P 5 -p 0
  • USB Port 4
    1
    sudo ./hub-ctrl -h 0 -P 3 -p 0
  • The Ethernet port!
    1
    sudo ./hub-ctrl -h 0 -P 1 -p 0
  • All 4 USB ports at once
    1
    sudo ./hub-ctrl -h 0 -P 2 -p 0

Light up

  • USB Port 2
    1
    sudo ./hub-ctrl -h 0 -P 4 -p 1
  • USB Port 3
    1
    sudo ./hub-ctrl -h 0 -P 5 -p 1
  • USB Port 4
    1
    sudo ./hub-ctrl -h 0 -P 3 -p 1
  • The Ethernet port!
    1
    sudo ./hub-ctrl -h 0 -P 1 -p 1
  • All 4 USB ports at once
    1
    sudo ./hub-ctrl -h 0 -P 2 -p 1

Conclusion

This brief article shows a solution that I have long sought. I hope that the work of the community transcribed here in English will have been useful to you.

★ ★ ★ ★ ★