Home and Links
 Your PC and Security
 Server NAS
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>

Raspberry Pi auto-power control

Pi power

Pi auto-power off

Preventing auto-power-off

To make sure the photoframe doesn't go into 'screen saver' mode and turn off the display, the Pi must be configured so it doesn't 'power down' or 'blank' the screen due to 'inactivity'. To do this, we have to edit the config file in the etc/ directory :-

sudo nano /etc/kbd/config
look for the section :-
# Powerdown time. The console will go to DPMS Off mode POWERDOWN_TIME
# minutes _after_ blanking. (POWERDOWN_TIME + BLANK_TIME after the last input)
Change the '30' to '0' (= 'never auto-power down')

Now find the section :-
# screen 'blanking' timeout. monitor remains on, but the screen is cleared to screen saver
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
Change the '30' to '0' (= 'no auto-screen blanking')

The changes will take effect on the next restart (to restart, type 'sudo /etc/init.d/kbd restart')

NOTE If at any stage you 'loose control', just press the Reset switch :-) .. otherwise, to shutdown the Pi, you just type :-

sudo shutdown -h now

Turning the display off overnight

To turn off the display, all we need do is 'stop' the Pi (assuming your monitor is 'modern' enough to detect 'loss of signal' and shut itself down)

The Pi has no 'real time clock'. At power-on it discovers the current date & time from the Internet and then 'counts up' from there (whilst it's still powered on). Of course if you want to use your photo-frame in 'stand-alone' mode (with no network connection) it can't discover the date/time after being 'reset' or powered-down, so it's 'count' will quickly become 'out of date'. This means you can't set the Pi to turn off at a specific time

Simple software solution

However the Pi does keep 'counting' the time. So if you 'always' turn on your photoframe at (say) 9am in the morning, the Pi just needs to turn itself off after 14 hours or so !

To achieve this, all you have to do is add a 'shutdown' command with a delay of (14x60 =) 840 minutes to the 'gophotoframe.sh' script.

Each morning, when you 'turn it on' (by pressing Reset) at (say) 9am, the 'shutdown' delay starts and 14 Hrs later (at 11 pm) it will turn itself off (until you press 'reset' again). :-

sudo shutdown -h 840

The hardware RTC approach

You can fit a RTC chip (Real Time Clock = a battery backed clock that can keep running whilst the Pi is off). These can now be had from China, post paid, via eBay for less than £2 each and plug directly into the Pi GPIO header

You can then set a task to run at a specific time (eg midnight) to shutdown the Pi
If you want to avoid the having to start it again 'manually', instead of shutting down, the task should just turn off the video signal (and thus the display) and keep the Pi running 'in the background' so it can perform a 'Reboot' the following morning (as you will discover, turning off the video drive is easy, turning it back on again is chancy at best)

Ambient light detection approach

A rather more clever approach would be to to monitor the state of the ambient light using a 'light detecting diode' (actually, a normal LED can be used for this). Fitted to one of the GPIO pins, a 'script' would check the light levels and decide when to turn the display off (or reboot to turn it back on)

When it gets dark (and no-one turns on the room lights) the script can 'turn off' the HDMI using 'tvservice -o' (which should prompt the display to put itself into power saving mode). When it gets light again, the script can perform a 'reboot' to turn the screen back on again. Of course the script would need to incorporate some time delays (to avoid the display being turned off and the Pi rebooting every time some-one walks in front of it and gets in the way of the light)

The 'ambient light' approach also means the photo-frame will turn itself off (and thus stop providing a distraction) if you happen to like watching the TV in the dark :-)

Next page :- Photo Frame software