17

This is the same question as this but for Raspberry Pi 3 / Raspbian.

I need a way to show black screen by running command in console by using SSH connection. Monitor should not go to standby I just need a black screen to hide everything that is on the screen. Screen should be black until I give another command to show screen content.

In Ubuntu this works:

xrandr -d :0 --output default --brightness 0

But in Raspbian nothing happens:

pi@media2:~ $ xrandr -d :0 --output default --brightness 0
xrandr: Gamma size is 0.

pi@media2:~ $ xrandr -d :0
xrandr: Failed to get size of gamma for output default
Screen 0: minimum 1360 x 768, current 1360 x 768, maximum 1360 x 768
default connected 1360x768+0+0 0mm x 0mm
1360x768       0.00*
Glorfindel
  • 620
  • 1
  • 8
  • 15
JPX
  • 553
  • 2
  • 4
  • 13

2 Answers2

10

Method 1: Blank the screen without turning the power off to the HDMI port.

You might need to set the screen's default state to blank (I didn't):

xset -display :0 s blank

Turn the monitor to it's default state (black hopefully):

xset -display :0 dpms force off

Turn the monitor back on by hitting a key, moving the mouse, or using this command:

xset -display :0 dpms force on

Method 2: Turn off the HDMI port and back on. This may result in the monitor itself turning off, depending on the monitor's settings, because it's not getting any signal. Some TVs or Projectors may display an error message about no signal.

Turn it off:

tvservice -o

Turn it back on:

tvservice -p

The monitor might be blank or checkered until you force it to display:

xset -display :0 dpms force on

Method 3: This does not apply to RPi 3 with standard Raspbian, but some specialized situations and the original Pi might be able to use this alternative (depreciated?) method.

Find out what the monitor's name is by running:

xrandr -display :0 -q

We'll use the name CRT1 in this example to turn it off:

xrandr -display :0 --output CRT1 --off

And turn it on again:

xrandr -display :0 --output CRT1 --on

In all these methods, the part about -display :0 is redundant if your terminal is visible on the display you are trying to control.

Best of luck!

Jon Musselwhite
  • 774
  • 4
  • 16
  • This doesn't work. Same gamma error: pi@media:~ $ xrandr -d :0 --output default --off xrandr: Failed to get size of gamma for output default – JPX Jan 05 '17 at 14:04
  • That's not the command I suggested. You're using -d :0 --output default instead of --output CRT1 or whatever your display's name is. You seem to be trying to accept the default monitor instead of explicitly using its name. Please humor me and try using the name you get from calling xrandr -q in place of CRT1 in the other commands I suggested. No other changes to the command. – Jon Musselwhite Jan 05 '17 at 14:42
  • I'm updating my answer because I can't get that to work either. I've found a way to blank the screen, but it will turn right back on if you move the mouse or hit a key on the keyboard. – Jon Musselwhite Jan 05 '17 at 15:23
  • 1
    And now I've included a method which turns the power to the monitor off as well. – Jon Musselwhite Jan 05 '17 at 16:01
  • Have you actually tried this on a Pi? The hdmi code on the Pi doesn't support most xrandr commands. – Milliways Jan 05 '17 at 23:11
  • Using ssh, xrandr -q can't open the monitor Pi3, Raspbian Jessie. pi@RPi3:~ $ sudo xrandr -q Can't open display – Chad Farmer Jan 05 '17 at 23:17
  • xrandr is reported to work by some Raspberry Pi users, but as I said in an earlier comment, I couldn't get it to work on mine. I included it for completeness. Methods 2 and 3 both work well for me though. I'll rearrange the order in my answer. – Jon Musselwhite Jan 06 '17 at 07:22
  • @ChadFarmer You need -display :0 in your command when executing x-server commands from a remote ssh terminal. I've updated my answer. Also, that method won't work on a Pi3. It's for original Pi (I think). I included it for completeness and because I read some reports of it working, so I believe there are cases in which it will work. – Jon Musselwhite Jan 06 '17 at 07:31
  • Method 2: tvservice -o turns off normal monitor but this doesn't work on some TV:s and projectors. Those devices report no signal and shows blue screen. Method 1: This blanks the screen but does need xset -display :0 s blank to work if not set. Otherwise shows the checkerboard. Problem is that if I use VNC connection to my Raspberry mouse and keyboard activity set disables blank screen. – JPX Jan 13 '17 at 06:37
  • Only: xset -display :0 dpms force on/off worked for me. blank/noblank didn't. – not2qubit Jan 01 '18 at 18:39
2

Turn black screen saver on: xset -display :0 s blank xset -display :0 s reset xset -display :0 s activate

Turn it off: xset -display :0 s reset xset -display :0 s noblank

You don't need command xset -display :0 s blank and xset -display :0 s noblank if the default setting is blank. reset is neede in the case if you try to turn screen saver on and it's already on.

JPX
  • 553
  • 2
  • 4
  • 13