4

I am running Raspbian Jessie Lite with a custom Xfce4 Desktop Environment installed. I created a file which when run, changes the number in /sys/class/backlight/rpi_backlight/bl_power to 0 or 1 depending on what was already in the file so that if I run the script twice it will turn the backlight off and then back on again. I am running the script as Pi user and have tried with and without sudo.

line=$(head -n 1 "/sys/class/backlight/rpi_backlight/bl_power")
if (( $line == 1 )); then
    echo 0 > "/sys/class/backlight/rpi_backlight/bl_power";
else
    echo 1 > "/sys/class/backlight/rpi_backlight/bl_power";
fi

After a reboot this script works fine. However after an arbitrary number of runs it stops turning the backlight on or off. However if I cat the bl_power file, the number has changed...the screen is just not turning off. A reboot fixes the problem but then it starts happening again.

Any ideas why this is not working?

EDIT

I also have this line in /etc/udev/rules.d/backlight-permissions.rules so I don't have to use sudo. Without this file and line I cannot echo to the bl_power file even with sudo.

SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"

EDIT 2

If I create a script with the following in it:

echo 0 > "/sys/class/backlight/rpi_backlight/bl_power"
echo 1 > "/sys/class/backlight/rpi_backlight/bl_power"

Surprisingly, it works to turn it on and off and so far hasn't stopped working. This is interesting because it seems like it would leave the screen in its original state because the commands appear to cancel each other out. However, running it once turns the screen off and again turns it back on again.

EDIT 3 The above stopped working suddenly and would not work without a reboot.

EDIT 4 I ran apt-get update and apt-get upgrade and it still is not working so I know it is not an issue of using an old kernel.

EDIT 5 I found a solution although I still am not sure why the above doesn't work. Instead of echoing 0 or 1 to the bl_power file I echo 0 or 255 to the brightness file which does the same thing. This has worked for over 4 hours now. It might be a hardware problem like the comment below this question.

NULL
  • 2,240
  • 8
  • 28
  • 49

2 Answers2

2

Although I haven't found the reason for this problem, a work around which works well is setting the brightness file to 0 like so:

echo 0 > "/sys/class/backlight/rpi_backlight/brightness"

And to turn it back on:

echo 255 > "/sys/class/backlight/rpi_backlight/brightness"

When the brightness file is set to zero the backlight is off so it has the same functionality.

NULL
  • 2,240
  • 8
  • 28
  • 49
0

From the fbtft wiki at https://github.com/notro/fbtft/wiki/SYSFS with a partial path, I guess.

bl_power

Turn backlight on/off

# backlight off
echo "1" | sudo tee bl_power

# backlight on
echo "0" | sudo tee bl_power
PaulF8080
  • 307
  • 1
  • 7