1

I'm looking into powering my raspberry pi via a powerbank. I already have a button and a relay to turn it on manually and when the pi shuts down flip the relay back to off position. Now I would like to have the option to power up the pi at specific times. After some research, an RTC seems promising. The question now is if anyone knows some nice off the shelf, low power, RTC circuit that is able to send out a 5V signal at e.g. 10am to flip the relay into the on position. I would prefer to power it directly through the powerbank instead of a coin battery to prevent having to charge the powerbank and switch out batteries.

for more info on the circuit I'm using to manually power on the pi see: Cut power supply to pi after shutdown and power on after button press

EDIT: The RTC would be an addition to powering it up manually. So both options would be possible. The idea is to build an ePaper photo frame that can change its picture when the button is pressed manually and also change its picture at certain set times. The times and photos will be collected from the accompanying website I built.

I also added a sketch of the adapted circuit that I am currently using for manual turning the pi on and shutting it down once it finished its task. I am a bit of a beginner in electronics so it is still very very basic (sorry for the handwriting).

sketch of circuit alteration

Thank you for the help!

3
  • 1
    Yes - I used the same basic circuit with an RTC for turning the RPi ON and OFF at specific times for my "solar power project". I'll post an answer here once I get caught up on a couple of other things. In the meantime, you can review the RTC setup on my GitHub site. You can also consider whether you want both manual & RTC-based OFF & ON, or just one of them. Once you've decided, edit your question to reflect that.
    – Seamus
    Jan 23, 2022 at 21:18
  • Hey Seamus, nice to hear from you again. Especially since you helped me with my other question. I was wondering what kind of signal the DS3231 module sends out once the alarm is triggered. Is there any other circuitry needed to increase the voltage so the latching relay switches into the 'on' position? @Seamus
    – Qorzyking
    Feb 8, 2022 at 11:13
  • Hopefully, the answer I've posted covers your questions, but feel free to follow up as required.
    – Seamus
    Feb 9, 2022 at 0:18

2 Answers 2

2

Proposed Solution:

The proposed solution requires hardware and software - including configuration changes to the system. Everything in this proposed solution has been verified on an RPi 3B+ running the Lite version of RPi OS buster.

Hardware

The following circuit seems to meet the objectives given in the OP. It adds three (3) components that weren't needed in the original schematic: the Real-Time Clock (RTC) at U1, a monostable multivibrator at U2- a.k.a. "one-shot" and a 3.3V regulator to power U1 & U2.

  1. For the RTC, I used Adafruit's DS3231 Precision RTC Breakout. The DS3231 is accurate, stable over temperature and has a feature set that includes an alarm function. N.B. "Counterfeit" DS3231 chips are widely distributed in the el-cheapo retail channels for much lower prices than the Adafruit unit.

  2. The one-shot at U2 provides two functions needed to integrate the RTC: It converts the RTC's alarm interrupt (#INT) from a state change to a fixed-duration pulse, and it inverts the signal polarity to drive the NPN transistor at Q1. The SN74AHC123 (available from TI) was chosen, but other one-shots may work equally well. Note that this is a CMOS part, and unused logic inputs must not be allowed to "float" - see the schematic for details.

  3. A 3.3V regulator is added to power the circuitry which must function when power is disconnected from the RPi. The RTC and one-shot draw very little power, and this simple Zener diode regulator is adequate.

RPi Power Management Schematic:

Zero-Power Control for Raspberry Pi

System Configuration

In addition to the hardware, there are some configuration changes to the device tree that will need to be made for the RTC. Setup and verification of the RTC should be done as a first step. The procedure I followed is documented on this GitHub page: Add a Real-Time Clock to Raspberry Pi.

To summarize this procedure, the following entries should be in the /boot/config.txt file:

dtparam=i2c_arm=on 
dtoverlay=i2c-rtc,ds3231,wakeup-source
dtoverlay=gpio-poweroff

Software

The "software" component of this proposed answer is intentionally austere. Its function is to automatically power the RPi ON & OFF on a 20 minute cycle - 10 minutes ON, then 10 minutes OFF. This cycle will repeat itself indefinitely.

The following crontab entries and bash script set the ON-OFF schedule, and write the alarm time to the RTC register via sysfs. Please note the root crontab must be used:

root crontab entries:

# shutdown & power off schedule
*/20 * * * * /home/pi/setalarm.sh >> /home/pi/setalarm.log 2>&1 

# clear the current alarm @reboot
@reboot sleep 10; /bin/echo "0" | tee /sys/class/rtc/rtc0/wakealarm; /bin/echo "boot time: $(/bin/date '+%D %X' -d '- 10 seconds') set wakealarm to 0" >> home/pi/setalarm.log 2>&1

setalarm.sh

#!/usr/bin/env bash

# clear the current alarm
echo "0" | tee /sys/class/rtc/rtc0/wakealarm
echo "THE TIME IS: $(date '+%D %X')"

# calculate the next wakeup and then halt:
/bin/date '+%s' -d '+ 10 minutes' | tee /sys/class/rtc/rtc0/wakealarm
/bin/sleep 5
/sbin/halt

Some Background on 'Zero Power' vs 'Low Power':

As of today, there is no RPi capable of reaching a Zero Power state without external hardware. As long as a 5V power source is connected to the RPi, the RPi will consume power. The RPi's rate of power consumption is reduced during halt, but all models will continue to consume power as long as a power source is connected. It may be fairly stated that all of the energy consumed by a RPi after receiving a halt command is wasted energy - unless your objective is to build a Raspberry Pi handwarmer. Obviously, this lack of power management disqualifies the RPi for a large class of otherwise potential applications; e.g. off-grid, battery-powered.

The RPi 4B is the first RPi model to provide what might be called a Low Power mode. However, as of Feb, 2022, a RPi 4B in LPM still burns 150-200 milliwatts after a halt, and also requires external hardware for re-start. While this is a significant improvement from when the RPi 4B was introduced, this level of power consumption is still too high for many off-grid and battery-powered applications - which is a shame.

Summary of Operation:

Referring to the Power Management Schematic:

Two signals and the K1 relay form the core of this design. INT# and GPIO-POWEROFF act through the support circuitry and the K1 relay to either apply or remove power from the RPi. Relay K1 differs from traditional relays in that it is a bi-stable, or latching relay; one of its two coils sets the relay, the other coil resets it. This bi-stable nature is what enables the Zero Power state: Once K1's contacts are set, they require no power to maintain this state. The contact positions will not change unless the reset coil is energized.

Edit: Do not use an RTC without a backup battery

By RTC backup battery, I mean the small coin-cell type battery that is fitted to the underside of the RTC module. The purpose of this battery is to keep the clock running while disconnected from the normal power source. Without an RTC backup battery, if 3V3 power is removed, the RTC will lose the alarm time that has been set, and when power is re-applied it will not know the correct time unless and until the RPi updates it. The RTC backup battery will last a very long time (years) based on mfr-published specs.

19
  • 1
    @Qorzyking: In this application, the one-shot turns edges into pulses based on the combinatorial logic... yeah - that's not as confusing as it sounds. The best way to understand it is to review the truth table. TI has great documentation, incl. "App Notes" - there's a link to it all in my answer, or this link takes you straight to it. The truth table is on p.2 of the spec sheet, and there's a document explaining why it's necessary to ground unused CMOS inputs.
    – Seamus
    Feb 9, 2022 at 15:52
  • 1
    @Qorzyking: At first glance, the only thing I noticed was Pin 16 was not connected to Vcc. Pls verify that & I'll look deeper.
    – Seamus
    Feb 19, 2022 at 18:44
  • 1
    @Qorzyking: ?? Do you mean it doesn't work on the breadboard when wired as shown in your schematic??
    – Seamus
    Feb 21, 2022 at 9:27
  • 1
    @Qorzyking: OK - I've been a bit busy, but I'll find some time to pull out my proto board, reconnect it & verify my wiring matches the schematic I posted. I guess the schematic should be updated also as it doesn't show all pin connections on the one-shot package. BTW - are you using the DIP package?
    – Seamus
    Feb 22, 2022 at 7:39
  • 1
    @Qorzyking: I put my prototype back on the bench, and verified the wiring matches the schematic. I made some changes to the schematic that will hopefully clarify the one-shot connections. RE the one-shot: You can more easily test the one-shot using the START pushbutton instead of the RTC. The pulse from the one-shot should be approx 10 msec - you'll need a scope to see this. I also discovered an error that I've corrected with the addition of a 3V3 Zener regulator to power the one-shot & the RTC. Pls keep me posted on developments, or if further questions arise.
    – Seamus
    Feb 24, 2022 at 11:28
2

ST makes a chip M41T62 that should do what you want. You program it via I2C. It has a watchdog and interrupt outputs that probably will do what you want. There are probably others but this looked the most interesting at this point. It will operate at 1.3 to 4.4V, nicely in the voltage range of the Pi. You will have to make a board for it or as I do sometimes dead bug it (tape to board with double sided tape and solder to the leads).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.