I have a (maybe trivial) problem.
I want to power a Raspberry Pi (more specific a SteroPi) with a power bank. The power bank has the feature, that its output is always on. So even if I plug in a charger, the output will stay on. For my project, I need the Raspberry Pi to shut down when the power bank is charging, and power on if the charging cable gets disconnected ("Airpods like"). I know there are power banks that have that feature, but I have not found any that fits the size I need (need one with the size of 2x 18650 batteries). Also, it is very difficult to search for this specific feature, as simply no manufacturer points that feature out in it's description. (If anybody knows a power bank with this form factor and functionality, please tell me :D)
What I tried till now:
I connected the 5V pin to a GPIO through a voltage divider and polled that with a script on the raspberry pi to shut it down (sudo shutdown -h now
) if 5V are present. This is working great, but the Raspberry Pi gets into something like a "bootloop": The power bank seems to cut the power off for a short time when the raspberry pi is off but turns back on immediately after that, that restarts the pi, but the pi is powering down again because the 5V are present on the charging port. And so on, and so on...
So my next idea is to hard cut the power of the Raspberry Pi if the power bank is charging, so it has no chance to reboot. For that, I need a simple circuit (maybe something with a transistor/MOSFET) that is directly controlled by the 5V charger pin (cuts power if 5V are present and turns it back on if the 5V are gone). Does anybody have an idea, how such a circuit could look like, or has the other approach?
UPDATE:
Solved the first problem by switching the micro USB cable from the power adapter to the power bank. Now there isn't a bootloop anymore. Also, I replaced my script that polls the pin by modifying the /boot/config.conf
like M. Rostami mentioned in the comments. This is a much easier and cleaner solution. Thanks!
/boot/config.conf
.However, this link would be helpful. raspberrypi.org/forums/viewtopic.php?t=175161#p1117946/boot/config.conf
solution. This is much simpler! And @jsotola: I want to shut down my raspberry pi while charging, to faster charge the battery, and to generally save power