I am using raspberry pi 5. In which my service is running and it is doing some task for sometime.After completion of task i want raspberry pi to go in sleep mode and consume low power.Can i do it with programmatically or any other way is there?
1 Answers
There is no sleep mode available on the RPi5 (or any other RPi). The Linux kernel supports sleep mode - but it's not implemented in any RPi. Why? ...You'll have to ask "The Raspberries" that question.
One thing you can do with the RPi5 is to press the "soft power" button. This will execute a safe shutdown, and put the RPi5 into a lower (not zero!) power consumption state. Another press will bring the RPi5 back to "life". This is a "manual" version of putting the RPi 5 into low power mode.
This "low power" state is said to be on the order of 3mA, and requires some changes to the RPi 5 EEPROM:
$ sudo -E rpi-eeprom-config --edit
# this will open your default editor
# once the editor is open, add the following two lines (if they're not already there):
POWER_OFF_ON_HALT=1
WAKE_ON_GPIO=0
Again, this reduces the power consumption when the RPi 5 is in halt mode, and still connected to power.
The RPi 5 is the first model to be made with an in-built Real Time Clock (RTC). The RTC can be programmed to wake the RPi 5 from its low-power halt mode. This may meet the objective stated in your question. As an example, suppose you wanted your RPi 5 to execute a task that was defined in a program called myscript, and then go to sleep for 2 hours. This could be done with a simple cron job.
$ sudo crontab -e
# crontab opened in editor; add one line:
@reboot /path/to/myscript >> /path/to/logfile 2>&1
save & exit editor
Assume myscript is a simple bash script:
#!/usr/bin/bash
start some task here
...
...
end it here
wakeuptime=$(date '+%s' -d '+2 hour') # calculate wakeuptime
echo "$wakeuptime" > /sys/class/rtc/rtc0/wakealarm # schedule RTC wakeup
/usr/sbin/halt # enter halt mode
exit 0
end of myscript
In this example, cron executes myscript at boot time (@reboot). Once myscript is started by cron it runs some service/function/etc, and when that is finished, it sets the RTC to "wake" the system at $wakeuptime, and then halts. The RPi wakes up in 2 hours, and repeats the process. Again - this is a simple-minded example, but it can be extended; perhaps used in a systemd unit.
There are other methods by which you can programmatically control the RPi5 to turn it ON or OFF that use external hardware (ex 1; ex 2). If you're interested in something like that, post another question.
- 23,558
- 5
- 42
- 83