Hey guys,
Just a little note for for those who are struggling.
I have recently upgraded from my RPi 3B+ to RPi 5 4GB. MM has been running fine for a while now and all my modules are running sweet.
One thing I have been struggling with was getting the Pi to shut off the output at night and then on again in the morning. The old way, vcgencmd display_power 0
and vcgencmd display_power 1
does not work on the RPi5.
In order to get things working again, and after a lot of research I have managed to get this working now. Below are 2 scripts that I have which are called from crontab at specified times.
You have to ensure that both of the below scripts are executeable. To do this you need to run the following command. chmod +x mon.sh mof.sh
from the command prompt.
mof.sh - Monitor Off.
Create a file: nano mof.sh
and add the below.
#!/bin/bash
export WAYLAND_DISPLAY=wayland-1
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/wlr-randr --output HDMI-A-1 --off
Explanation
- Declare a variable for WAYLAND_DISPLAY
- Declare a variable for XDG_RUNTIME_DISPLAY (I had an issue with this and only found recently that I needed to declare this as well in the script)
- Execute the wlr-randr command to turn off the display
mon.sh - Monitor On
Create a file: nano mon.sh
and add the below to it.
#!/bin/bash
export WAYLAND_DISPLAY=wayland-1
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/wlr-randr --output HDMI-A-1 --on --mode 1920x1080@60Hz --transform 270
Explanation
- Declare a variable for WAYLAND_DISPLAY
- Declare a variable for XDG_RUNTIME_DISPLAY (I had an issue with this and only found that I needed to declare this as well in the script)
- Execute the wlr-randr command to turn on the display
- lI have to supply options to this command as I needed to ensure that when the monitor is turned on, it has the same pixilation and rotation etc. This is achieved by passing
--mode 1929x1080@60Hz
and to ensure it is flipped 90 degrees I pass the option --transform 270
.
To obtain your current screen settings you run wlr-randr
from the command prompt and you will be shown the current settings for your mirror. You can then use those values and substitute them for the values above if yours is different. This will also confirm if your monitor is HDMI-A-1
or if it is called something else.
Crontab
To instantiate a crontab you do crontab -e
from the command line.
Add the following entries at the bottom of the file.
00 06 * * * /home/pi/mon.sh >> /home/pi/mon.log 2>&1
00 21 * * * /home/pi/mof.sh >> /home/pi/mof.log 2>&1
From the above, it will turn the output on at 6am and turn it off at 9pm.
Hope this helps somebody.