2

I will be using the Raspbian Lite OS.

I want my Users to be able to switch the device on/off.

I am using a battery source for the main application.

I was thinking of providing kiosk browser UI (which I found some sample code for) to allow the user to click on my virtual button to shut the device down when not in use.

But, 'durrh' just occurred how can i get my user to switch the device back on? Or should I be looking at some 'sleep' functionality rather than looking to completely power off?

2 Answers 2

3

First, the bad news: Currently, only the RPi4B has what might be considered a "sleep mode". And at 40mA, or approximately 5 watt-hours per day, this could only be considered "sleep mode" if you're still living in the era of bag phones. While the Raspberry Pi doesn't use a great deal of power when it's running, 72 watt-hours per day is beyond the capacity of batteries typically used for "mobile" (or even transportable) devices. YMMV, but you should compare these power consumption figures against your battery capacity.

There are other "tweaks" available to further reduce power consumption; e.g. some hardware can be disabled via configuration file, and clock speed can be reduced for less demanding applications. Here are some specific suggestions on reducing power consumption, and here are some more. If you're interested in minimizing power consumption in this way, determine what hardware resources you can live without, and edit your question (or post a new one) - we'll try to help.

I'll organize my answer to your question under 3 headings:

1. Brute force power removal

As far as allowing your users to switch the device on and off, perhaps the simplest solution is to wire your battery lead (positive side) through a switch. You can buy a switch that is said to do this from several vendors; e.g. this one from Amazon. The advantage this solution has over the one below is that power consumption is reduced to ZERO. However, be aware that there are a couple of cautionary notes for this approach:

  1. Powering off your RPi by removing power may create file integrity issues on your SD card, and is not considered good practice. In any event, fsck will be invoked on the next boot sequence, which will require additional time to boot.
  2. Some of the hardware sold in the "hobbyist market" is not manufactured to the highest standards. Be aware of this, and look out for new issues with your RPi after adding new hardware.

2. Reduce power consumption via shutdown command

A better alternative to the brute-force power switch described in the previous paragraph is to reduce power using (one of the) halt/poweroff/shutdown commands, and then toggle the state of GPIO3 pin with a pushbutton switch to restart the Pi. However, you should know that the RPi will continue to use power after the shutdown command takes effect (see Note 1 below). Basically, this solution takes the following steps:

  1. Halt the RPi via the command: sudo shutdown now. (see Note 2 below)

  2. Restart the RPi by connecting pin GPIO3 to Ground. This can be done using a "momentary" pushbutton switch that shorts GPIO3 to GROUND.

One clever way to configure the momentary pushbutton switch to "toggle" the RPi between OFF and ON is to monitor the state of GPIO3 in software, and execute a script that runs the shutdown command above to halt the system. Once the system is halted, the next push of the toggle button will restart the RPi. This technique is covered in more detail here.

Of course there are other ways to halt the system, and then use the momentary pushbutton to restart it. For example, you could add a line in your crontab file to shut the RPi down at a designated time (at 9:00 PM for example), then turn it on again by pressing the momentary pushbutton switch. Or you could write a script to monitor usage of some resource, and shutdown based on that usage.

Update: If you have an RPi4B, there are additional options that will further reduce power consumption in shutdown mode.

3. Add hardware to minimize RPi energy consumption

There are other solutions that, for example, use external hardware - even micro-controllers (e.g. Arduino) - to remove power from the RPi when it's not needed. These solutions do not reduce the RPi's power requirements, but they can greatly reduce its energy consumption; i.e. power over time.

Generally speaking, these energy-reduction solutions invoke a shutdown of the OS to preserve filesystem integrity, followed by disconnecting the RPi's external power source to . As of this writing, an automated re-start of the RPi is possible only from an external source; e.g. realtime clocks, sensors or other external systems (incl. "HATs").

Energy-reduction solutions are available as commercial products, or perhaps more usefully as DIY solutions that allow customization for a particular use-case:

4. In closing...

Your question has probed the interesting topic of power management on the Raspberry Pi. The holy grail of RPi power management is battery operation, but given its current hardware design this remains a challenge for many applications. However, demand from the user community, clever solutions from developers/users, and The Foundation's gradual improvements to their proprietary firmware are making useful inroads. In the meantime, a number of solutions that have been developed - some commercial and some DIY.

Suggest you try something simple to start, then build on that. You can post specific follow-up questions once you've got the basic functionality working.

Notes-


NOTE 1: How much power does the RPi consume after entering shutdown mode"?

  • In general, this depends upon which model of RPi, but...
  • For my RPi 3B+, I measure 80-90mA
  • For my RPi 4B, I measured 40-370mA.
  • Others have made measurements - for example

NOTE 2: Although halt and shutdown commands are implemented somewhat differently, there is no difference in power consumption once the machine is in this state.

15
  • If the RasPi is in halt state (after shutdown) does it consume power? May it be possible that you add this info to the answer?
    – Ingo
    Dec 21, 2018 at 18:44
  • thanks for such a comprehensive answer I did look at the GPIO route + script before and purchased the components. I was looking at all possibilities as well though. I think the way I prefer to go is to minimise what is running and 'sleep' that way. thanks again :)
    – user11286
    Dec 21, 2018 at 18:52
  • 1
    I'm worried using the cable switch might encourage the user to regard that as the proper way to turn the device off, which all by itself it isn't. Not shutting the OS down properly will: 1) Slow your boot time because the root filesystem must then be checked when the pi is switched on again, 2) Significantly increase the risk of arbitrary filesystem corruption, which may or may not be fixable by the boot fs check.
    – goldilocks
    Dec 21, 2018 at 18:57
  • @goldilocks: That's a valid point; I'll add a cautionary note.
    – Seamus
    Dec 21, 2018 at 19:16
  • BTW: I have a few of those cables that came with Anker 5V 2.5A supplies, and they are all bad in the sense that no matter what supply they are used with, I get continuous undervolting on a Pi 3 (the Anker supplies themselves are also subpar, no matter what cable they are used with). Despite being sold "for the Raspberry Pi", there's some 1 star reviews there that reflect this too.
    – goldilocks
    Dec 21, 2018 at 19:20
1

To be able to save battery power you will need additional hardware like a wittypi2 http://www.uugear.com/product/wittypi2/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy