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.

  • 2
    Wonder is if its something to do with the LCD controller. Maybe it doesn't like being turned off and on constantly. Just to test.. unplug the LCD from power, then plug the LCD back in to power without rebooting the Pi! Try the commands again. This way you can eliminate kernel (highly unlikely) – Piotr Kula Jan 5 '17 at 12:34
  • 1
    Your edit #2 makes me think the root cause is a race condition in a badly written driver. – Dmitry Grigoryev Jan 9 '17 at 17:27
  • 1
    I don't have the device but "Edit 5" makes me think you should have a look in that directory (/sys/class/backlight/rpi_backlight/) to see what other fields are there. Some of them (e.g "max_brightness", which is standard for laptops and other backlit screens) will be read only, and indicate a range. This box (intel_backlight) it's up to 4648. "1" would be pretty dark. Of course this doesn't explain all the silly behaviour. – goldilocks Jan 10 '17 at 17:43
  • @goldilocks My max_brightness file has the number 255 in it. I'll have to see what other files are there. – NULL Jan 11 '17 at 13:03
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
  • 1
    -1 Whilst this is a valid way to use echo to get it to write into the /sys/class/backlight/rpi_backlight/bl_power file when the latter is only writeable by root it does not answer the OPs question... – SlySven Jan 6 '17 at 19:58
  • 1
    Unfortunately this did not work either. – NULL Jan 6 '17 at 20:47
  • You are down voting the owner of the TFT drivers, not me. This site the most annoying site I visit. – PaulF8080 Jan 6 '17 at 21:47
  • The wiki uses at relative path (no leading "/"). Relative to your current directory.(do pwd). You can use the full path you used. Maybe the trick is to use quotes in a "sudo echo" – PaulF8080 Jan 8 '17 at 21:28
  • I'm thinking the quotes around the 1 or 0 may make it a string. The owner should know if bl_power is type char. – PaulF8080 Jan 8 '17 at 21:40
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.