Python API

Make sure you’ve installed the library correctly.

Open a Python shell and import the Backlight class:

>>> from rpi_backlight import Backlight

Create an instance:

>>> backlight = Backlight()

Now you can get and set the display power and brightness:

>>> backlight.brightness
>>> backlight.brightness = 50
>>> backlight.brightness
>>> with backlight.fade(duration=1):
...     backlight.brightness = 0
>>> backlight.fade_duration = 0.5
>>> # subsequent `backlight.brightness = x` will fade 500ms
>>> backlight.power
>>> backlight.power = False
>>> backlight.power

To use with ASUS Tinker Board:

>>> from rpi_backlight import Backlight, BoardType
>>> backlight = Backlight(board_type=BoardType.TINKER_BOARD)
>>> # continue like above

See the API reference for more details.

Command line interface

Open a terminal and run rpi-backlight.

$ rpi-backlight -b 100
$ rpi-backlight --set-brightness 20 --duration 1.5
$ rpi-backlight --get-brightness
$ rpi-backlight --get-power
$ rpi-backlight --p off
$ rpi-backlight --get-power
$ rpi-backlight --set-power off :emulator:

To use with ASUS Tinker Board:

$ rpi-backlight --board-type tinker-board ...

You can set the backlight sysfs path using a positional argument, set it to :emulator: to use with rpi-backlight-emulator.

Available options:

usage: rpi-backlight [-h] [--get-brightness] [-b VALUE] [--get-power]
                    [-p VALUE] [-d DURATION] [-B {raspberry-pi,tinker-board}]

Get/set power and brightness of the official Raspberry Pi 7" touch display.

positional arguments:
SYSFS_PATH            Optional path to the backlight sysfs, set to
                        :emulator: to use with rpi-backlight-emulator

optional arguments:
-h, --help            show this help message and exit
--get-brightness      get the display brightness (0-100)
-b VALUE, --set-brightness VALUE
                        set the display brightness (0-100)
--get-power           get the display power (on/off)
-p VALUE, --set-power VALUE
                        set the display power (on/off/toggle)
-d DURATION, --duration DURATION
                        fading duration in seconds
-B {raspberry-pi,tinker-board}, --board-type {raspberry-pi,tinker-board}
                        board type
-V, --version         show program's version number and exit

Graphical user interface

Open a terminal and run rpi-backlight-gui.

Graphical User Interface Graphical User Interface (2)

Adding a shortcut to the LXDE panel

Panel Result

First, create a .desktop file for rpi-backlight (e.g. /home/pi/.local/share/applications/rpi-backlight.desktop) with the following content:

[Desktop Entry]
Name=rpi-backlight GUI

The absolute path to rpi-backlight-gui might differ if you did not follow the installation instructions exactly, e.g. installed as root.

Make it executable:

$ chmod +x /home/pi/.local/share/applications/rpi-backlight.desktop

You should now be able to start the rpi-backlight GUI from the menu: (Raspberry Pi Logo) Accessoires rpi-backlight GUI.

Next, right-click on the panel and choose Add / Remove panel items. Select Application Launch Bar and click Preferences:

Panel Preferences

Select rpi-backlight GUI on the right and click Add:

Application Launch Bar

You’re done!