User avatar
Gerd
Posts: 66
Joined: Wed Mar 16, 2016 10:48 am
Location: Europe

Screen Saver -> Screen OFF instead of Screen black

Wed Mar 16, 2016 11:28 am

Hi there,

running my new Pi3 I noticed that when the screen saver kicks in, it displays black pixels instead of swiching off the screen. While I do not care about the 1 or 2 watts the pi3 draws when idle, I do care about the 70 watts my screen draws when displaying black pixels.
After an intensive search I found a solution to this:
Append the following line in config.txt

Code: Select all

hdmi_blanking=1
After the next reboot and coffee break, voilà: Screen is blank

I`d like to share this finding, because I didn't find this setting documented neither in http://elinux.org/RPiconfig nor https://www.raspberrypi.org/documentati ... fig-txt.md , only in this git commit https://github.com/raspberrypi/document ... /245/files I stumbled upon.

Hope this is helpful for someone not using his Pi as a media center.

Gerd, new user who is reading a lot at the moment.

mikluz
Posts: 17
Joined: Thu Mar 31, 2016 11:52 am
Location: Szczecin, Poland

Re: Screen Saver -> Screen OFF instead of Screen black

Thu Mar 31, 2016 1:28 pm

Hi,

maybe you or someone else would know the answer on the question: "How to trigger locking or blank screen with a keyboard shortcut"?
You know, the same as works on M$ when you hit Windows+L, or Ctrl+Alt+L on Ubuntu-like distros?

I tried to search the answer on that question, but apparently I couldn't find anything that fully covers my issues.


Thanks a lot for your help.
Raspberry Pi 3 @ Raspbian

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: Screen Saver -> Screen OFF instead of Screen black

Thu Mar 31, 2016 1:34 pm

you can also install xscreensaver and get gui options for screen off
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

mikluz
Posts: 17
Joined: Thu Mar 31, 2016 11:52 am
Location: Szczecin, Poland

Re: Screen Saver -> Screen OFF instead of Screen black

Fri Apr 01, 2016 8:52 am

I know about xscreensaver and am testing it right now, but as someone else stated in this forum, that xscreensaver is using lots of CPU (sic!).
I just wondered Raspbian knows how to switch monitor off, so, there is a routine for that. Maybe someone knows how to attach keyboard shortcut for running this routine like it is done in other desktop OS (Windows + L or so)?

//EDIT
I've written the script that adds Ctrl + Alt + L shortcut that locks the screen
Here is the answer: viewforum.php?f=28
Raspberry Pi 3 @ Raspbian

User avatar
Rive
Posts: 586
Joined: Sat Mar 26, 2016 5:21 pm
Location: USA

Re: Screen Saver -> Screen OFF instead of Screen black

Tue Apr 26, 2016 12:11 am

mikluz wrote:Hi,

maybe you or someone else would know the answer on the question: "How to trigger locking or blank screen with a keyboard shortcut"?
You know, the same as works on M$ when you hit Windows+L, or Ctrl+Alt+L on Ubuntu-like distros?

I tried to search the answer on that question, but apparently I couldn't find anything that fully covers my issues.


Thanks a lot for your help.
Youtube Video: https://youtu.be/aTrp83lgq_s

Code: Select all

xset q
note- "xset q" is useful for checking screen and dpms settings, and changing them for testing (e.g., Monitor "off" is set for 1200 sec, or 20 min, and you want to test it, so you set dpms to 10 sec (xset dpms 0 0 10)). Changes here are temporary, and will not survive a reboot.

Run:

Code: Select all

sudo apt-get install light-locker
Open:

Code: Select all

sudo nano /boot/config.txt
Add:

Code: Select all

# uncomment to put the monitor into power saving mode (DPMS)
hdmi_blanking=1
Open:

Code: Select all

sudo nano ~/.config/lxsession/LXDE-pi/autostart
Add:

Code: Select all

@xset s 0 0
@xset s noblank
@xset s noexpose
@xset dpms 0 0 1200
Save with 'Ctrl + x', then 'y', then 'enter'

open:
(note- if you do an "apt-get dist-upgrade" instead of an "apt-get upgrade", you will need to re-add this keybind)

Code: Select all

nano ~/.config/openbox/lxde-pi-rc.xml
find:

Code: Select all

 <!--keybindings for LXPanel →
add:

Code: Select all

      <keybind key="C-A-L">
    <action name="Execute"><command>lxlock</command></action>
  </keybind>
The above dpms '1200', means turn off monitor after 20min, and lock screen with light-locker (lxlock). Change to whatever time you want (in seconds).

If you do not want screen to autolock
If you prefer screen to just turn off/go into power save mode, and resume if you move mouse, or hit a key WITHOUT requiring login, and wish to manually do screenlock, then;

open

Code: Select all

sudo nano /etc/xdg/autostart/light-locker.desktop
find "Exec=light-locker", change to

Code: Select all

Exec=light-locker --lock-after-screensaver=0 --no-lock-on-suspend --no-late-locking

Code: Select all

sudo reboot

Shortcuts:
1. add "ScreenLock" Menu shortcut (via Menu/Preferences/Main Menu Editor/Other/)
2. use keyboard 'Ctrl ' + 'Alt' + 'L' to turn off monitor and lock screen
Last edited by Rive on Fri Apr 29, 2016 9:30 pm, edited 21 times in total.
DNPNWO

User avatar
DougieLawson
Posts: 35840
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Screen Saver -> Screen OFF instead of Screen black

Tue Apr 26, 2016 12:19 am

Try running this

Code: Select all

#!/bin/bash

bl_on() {
  echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
}

bl_off() {
  echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
}

process() {
  while read line; do
     case "$line" in
       UNBLANK*)
          bl_on
          ;;
       BLANK*)
          bl_off
          ;;
       RUN*)
          bl_off
          ;;
     esac
  done
}

/usr/local/bin/xscreensaver-command -watch | process
If you have sudo protected with PASSWD (rather then NOPASSWD, which I have changed) you'll fail on the sudo tee command. I ended up writing a suid (chmod +s) program to write to the backlight file from any userid without needing sudo.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

antirasp
Posts: 2
Joined: Mon May 22, 2017 10:06 pm

Re: Screen Saver -> Screen OFF instead of Screen black

Thu Aug 24, 2017 4:57 pm

DougieLawson wrote:
Tue Apr 26, 2016 12:19 am
Try running this

Code: Select all

#!/bin/bash

bl_on() {
  echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
}

bl_off() {
  echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
}

process() {
  while read line; do
     case "$line" in
       UNBLANK*)
          bl_on
          ;;
       BLANK*)
          bl_off
          ;;
       RUN*)
          bl_off
          ;;
     esac
  done
}

/usr/local/bin/xscreensaver-command -watch | process
If you have sudo protected with PASSWD (rather then NOPASSWD, which I have changed) you'll fail on the sudo tee command. I ended up writing a suid (chmod +s) program to write to the backlight file from any userid without needing sudo.


HEllo:

Is this to turn off the screen with a shortcut to the script, or does it simply change the way the screen shuts off in an original way, ie from black screen to off screen?
Apologies for my lousy English, it is done with the google translator. Thank you.

User avatar
DougieLawson
Posts: 35840
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Screen Saver -> Screen OFF instead of Screen black

Thu Aug 24, 2017 7:57 pm

bl_on() turns it on, bl_off() turns it off.

Code: Select all

#include <stdio.h>     /* for printf */
#include <stdlib.h>    /* for exit */
#include <unistd.h>    /* for getopt */

#define FN "/sys/class/backlight/rpi_backlight/bl_power"
#define BL_ON 0
#define BL_OFF 1

FILE *bl;

void bl_on ()
{
 fwrite("0", 1, 1, bl);
}

void bl_off()
{
 fwrite("1", 1, 1, bl);
}

int main (int argc, char **argv)
{

    int c, err = 0;
    int sflag = 0;
    char *sopt = 0;
    static char usage[] = "Usage: %s -s 0|1 \n";
    
    while ((c = getopt(argc, argv, "s:")) != -1)
    {
        switch (c)
        {
        case 's':
            sflag = 1;
            printf ("option s with value '%s'\n", optarg);
            sopt = optarg;
            break;
        case '?':
            fprintf(stderr, usage, argv[0]);
            err = 1;
            break;
        }
    }
    if ((optind) != argc)
    {
       fprintf(stderr, usage, argv[0]);
       exit(-1);
    }
    else if (sflag == 0)
    {
       fprintf(stderr, "Err: %s: missing -s option\n", argv[0]);
       exit(-1);
    }
    else if (err)
    {
       fprintf(stderr, usage, argv[0]);
       exit(-1);
    }
    bl = fopen(FN, "w");
    if (strcmp(sopt, "0")==0)
    {
       printf("Backlight ON");
       bl_on();
    }
    else if (strcmp(sopt, "1")==0)
    {
       printf("Backlight OFF");
       bl_off();
    }
    else
    {
       fprintf(stderr, "Invalid switch option");
       exit(-1);
    }
    fclose(bl);
    exit (0);
}
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Beginners”