How to change the screen saving mode

The Iothermostat application puts the display to sleep after several minutes without touching the screen, and wakes up as soon as the screen is touched.

However, the backlight LEDs do not deactivate.

I’ve installed a new WaveShare display which includes the ability to control the backlight via port 18 of the RPI.

waveshare 3.5inch_RPi_LCD_(B)

I’ve tested and succeeded in turning off the backlight completely, so I’d like to replace the sleep mode with my backlight cut-off function,

However, I don’t understand how the existing standby function is activated.
it seems to me that it’s the same implementation as for HestiaPi

Thanks for your explanations

I don’t remember the HestiaPi image ever blanking out the screen. It think that might just be an Iothermostat thing.

However, I still want to try to be helpful. :heart: I believe screen blanking is generally handled by X, and I was able to dig up a post on the Raspberry Pi forums that also suggests this is the case.

If you run xset q from a shell on your pi, it should print out a bunch of information, including things like “prefer blanking” and “timeout”. The person on the rPi forum wrote a script that constantly looks at the output of that command to see when the brightness changes.

That same forum post links to A Primer on Screen Blanking Under Xorg, which I found incredibly helpful in understanding the details of how all this works. Since your LCD requires GPIO to control the backlight, my guess is that the very last line of that page will be your best bet at a minimally hacky solution: make your script to disable the backlight be the screensaver.

What I imagine would be a bash script that is run when the screensaver comes on. It runs the command to kill the backlight and then just goes into an infinite sleep loop. That’d take care of the “off” part, but what about turning it back on?

I’m guessing that when the screen it touched, X will kill the screensaver process. You can use a trap to have a function or command run when your bash script is killed. If you make that command the one to turn the backlight on, it seems like it should work. It’d still be a little janky, but much better than burning CPU power constantly running xset to see if the screen has been blanked out.

This is all off the time of my head and I haven’t tested any of it, so I’ll be interested to hear if it works as I hypothesize.

Let us know how it goes. And I’d be interested to hear your commets on that screen in general. Not being able to turn the backlight off on the HestiaPi is one of the things that people want but the hardware we’re currently using doesn’t do. It’d be cool to have an upgrade for people. Even it the Waveshare is twice the price of the screen we currently use, some people would probably find it to be worth the extra money.

blacklight screen for Iothermostat

Backlight control installation for Waveshare 3.5inch version B screen


Control is performed via pin12 of the rasp2B 40points connector (gpio18 of the rpi connector) using a pwm command.

but the backlight can be switched off with a value of 0 or fully illuminated with a value of 1.

The iothermostat application works for local display in an X windows session in a simple luakit browser.

Checking the characteristics of the windows manager

iothermostat@iothermostat:~ $ xset q

Keyboard Control:
auto repeat: on key click percent: 0 LED mask: ffffe780

XKB indicators:
00: Caps Lock: off 01: Num Lock: off 02: Scroll Lock: off
03: Compose: off 04: Kana: off 05: Sleep: off
06: Suspend: off 07: Mute: on 08: Misc: on
09: Mail: on 10: Charging: on 11: Shift Lock: off
12: Group 2: off 13: Mouse Keys: on

auto repeat delay: 660 repeat rate: 25

auto repeating keys: 00ffffffdffffbbf
fadfffefffedffff
9fffffffffffff
fff7ffffffffffff

bell percent: 50 bell pitch: 400 bell duration: 100
Pointer Control:
acceleration: 2/1 threshold: 4
Screen Saver:
prefer blanking: yes allow exposures: yes
timeout: 600 cycle: 600

Colors:
default colormap: 0x20 BlackPixel: 0x0 WhitePixel: 0xffff

Font Path:
/usr/share/fonts/X11/misc,built-ins

DPMS (Energy Star):
Standby: 600 Suspend: 600 Off: 600

DPMS is Enabled
Monitor is Off

DPMS management is enabled for the display, but no hardware interface is processed by the device.

#### Backlight control check

GPIO programming: use of sysfs interface (present in app)

see https://www.ics.com/blog/gpio-programming-using-sysfs-interface

https://elinux.org/RPi_GPIO_Code_Samples

user connection iothermostat ( iothermostat must be in the gpio group )

iothermostat@iothermostat:~ $ ls /sys/class/gpio/ export gpiochip0 unexport

create access to gpio18

$ echo 18 >/sys/class/gpio/export
$ ls /sys/class/gpio export gpio18 gpiochip0 unexport
$ ls /sys/class/gpio/gpio18 active_low device direction edge power subsystem uevent value

now we need to define the output
$ echo out >/sys/class/gpio/gpio18/direction

then set the gpio port output value to 1
$ echo 1 >/sys/class/gpio/gpio18/value

Backlighting is now controllable

We’ll see that we can use the raspi-gpio library present in the configuration.

Implementation


Solution 1 modify DPMS management for the display

I haven’t been able to find a solution for processing DPMS to take the display into account.

Solution 2 control display according to DPMS control status

DPMS (Energy Star):
Standby: 600 Suspend: 600 Off: 600
DPMS is Enabled
Monitor is Off

Proposed here Controlling the LCD Backlight, I retain the bash script solution

(simple, no compilation required, and raspi-gpio library installed)

Bash script: backlight.sh

#!/bin/bash
#PWM_PIN=31
PIN=18
# Set pins as output
#raspi-gpio set $PWM_PIN op
raspi-gpio set $PIN op
# Start with both pins HIGH.* *If either of the
# pins go LOW, the backlight will turn off.
#raspi-gpio set $PWM_PIN dh
raspi-gpio set $PIN dh
# Get the current state
CURRENT_STATUS=$(xset q | grep “Monitor is” | awk '{print $3}')
LAST_STATUS=$CURRENT_STATUS
logger -p info -t “backlight_service” -s “Monitor is $CURRENT_STATUS”
# Loop indefinitely updating backlight in sync with monitor status
while true; do
# Check the current monitor status
CURRENT_STATUS=$(xset q | grep “Monitor is” | awk '{print $3}')
# Only turn the backlight on/off if the Monitor state has changed
if [ “$CURRENT_STATUS” != “$LAST_STATUS” ]; then
logger -p info -t “backlight_service” -s “Monitor is $CURRENT_STATUS”
# Control backlight pin according to the monitor status
if [ “$CURRENT_STATUS” = “On” ]; then
logger -p info -t “backlight_service” -s “Turning Backlight On”
raspi-gpio set $PIN dh
else
logger -p info -t “backlight_service” -s “Turning Backlight Off”
raspi-gpio set $PIN dl
fi
LAST_STATUS=$CURRENT_STATUS
fi
# Sleep before checking again
sleep 1s
done

#### integration in iothermostat app

iothermostat@iothermostat:~ $ pstree -a

systemd splash

│ ....
│
├─login -f
│ └─startx /usr/bin/startx -- -nocursor
│ └─xinit /home/iothermostat/.xinitrc -- /usr/bin/X :0 -nocursor vt1 -keeptty -auth /tmp/serverauth.Hz4MUFRc4L
│ ├─Xorg :0 -nocursor vt1 -keeptty -auth /tmp/serverauth.Hz4MUFRc4L
│ │ └─9*[{Xorg}]
│ └─sh /home/iothermostat/.xinitrc
│ ├─backlight.sh ./backlight.sh
│ ├─luakit -u http://localhost/iothermostat/index.php
│ │ ├─WebKitNetworkPr 4 16
│ │ └─11*[{WebKitNetworkPr}]
│ │ ├─WebKitWebProces 9 23
│ │ └─10*[{WebKitWebProces}]
│ │ └─18*[{luakit}]
│ └─matchbox-window
├─

spot controls DPMS status and turns backlight on or off accordingly

http://comfilewiki.co.kr/en/doku.php?id=comfilepi:configure_a_program_to_auto-start:index#configure_an_x_program_to_auto-start_eg_mono

In our case, it will be launched by xinitrc

root@iothermostat:/home/iothermostat# cat /home/iothermostat/.xinitrc

#!/bin/bash
FILE=~/calibrated
/usr/bin/matchbox-window-manager &
if [ -f “$FILE” ]; then
CURRENT_STATUS=$(xset q | grep “Monitor is” | awk '{print $3}')
logger -p info -t “backlight_service” -s “start Monitor is $CURRENT_STATUS”
   ./backlight.sh &
   luakit -u http://localhost/iothermostat/index.php
else
  xinput_calibrator
  touch “$FILE”
fi

### Complements

http://comfilewiki.co.kr/en/doku.php?id=comfilepi:controlling_the_lcd_backlight:index

depending on bash options, double quotes may have to be replaced by single quotes

" must be replace with simple quote