• Stars
    star
    245
  • Rank 165,304 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔆 A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display

rpi-backlight

A Python module for controlling power and brightness of the official Raspberry Pi 7" touch display.

PyPI Python Version Downloads Documentation License Black Build Read the Docs Issues

Example

Note: This GIF was created using the old v1 API, so please don't use it as API reference 🙂

Features

  • Set the display brightness smoothly or abrupt
  • Set the display power on or off
  • Get the current brightness
  • Get the display power state (on/off)
  • Command line interface
  • Graphical user interface

Requirements

  • A Raspberry Pi or ASUS Tinker Board including a correctly assembled 7" touch display v1.1 or higher (look on the display's circuit board to see its version), or a Surface RT running a Linux-based OS
  • Python 3.6+
  • Optional: Raspberry Pi: pygobject for the GUI, already installed on a recent Raspbian
  • Optional: Tinker Board: gir1.2-gtk-3.0 for the GUI install

Installation

Install from PyPI:

$ pip3 install rpi-backlight

Note: Create this udev rule to update permissions, otherwise you'll have to run Python code, the GUI and CLI as root when changing the power or brightness:

$ echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules

Emulator

For testing without a physical display (e.g. on your main Linux/macOS/Windows machine) you can use linusg/rpi-backlight-emulator.

Usage

API

Example in a Python shell:

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

For more details see docs.

CLI

Open a terminal and run rpi-backlight.

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

For all available options see docs.

GUI

Open a terminal and run rpi-backlight-gui.

Graphical User Interface Graphical User Interface (2)

Adding a shortcut to the LXDE panel

Panel result

See docs.

Tests

Tests use pytest, install with pip3 install pytest.

Now, run from the repository root directory:

$ python3 -m pytest

Contributing

Please free to open an issue for bug reports and to discuss new features - pull requests for new features or bug fixes are welcome as well!

License

The source code and all other files in this repository are licensed under the MIT license, so you can easily use it in your own projects. See LICENSE for more information.

More Repositories

1

xbox360controller

🎮 A pythonic Xbox360 controller API built on top of the xpad Linux kernel driver
Python
80
star
2

libjs-test262

✅ Tools for running the test262 ECMAScript test suite with SerenityOS's JavaScript engine (LibJS)
Python
28
star
3

libjs-website

Website for SerenityOS's JavaScript engine (LibJS)
JavaScript
27
star
4

spotifube

Download songs from YouTube using Spotify playlists or song URLs. Uses spotify-downloader under the hood.
JavaScript
27
star
5

serenityos-emoji-font

😃 The SerenityOS pixel art emojis as a TTF
Python
27
star
6

la-capitaine-android

📱 La Capitaine icons on Android!
Python
20
star
7

serenity_exporter

📈 A Prometheus exporter for SerenityOS
JavaScript
16
star
8

libjs-bindings

LibJS Bindings for some of the SerenityOS C++ libraries
C++
15
star
9

ecmascript-wiki

📄 Information and links related to ECMAScript engine/tooling development
13
star
10

rocketchat-dark

🌒 Dark Userstyle for Rocket.Chat
CSS
10
star
11

rpi-backlight-emulator

📺 Raspberry Pi 7" display emulator for rpi-backlight
Python
7
star
12

dotfiles

💻 My dotfiles & other OS configuration
Nix
4
star
13

nachrichten

📺 Quickly get the URL of the latest ZDF heute or Tagesschau (German news) video
Python
4
star
14

garmin-watchface

⌚ A Garmin Watch Face for myself
Monkey C
4
star
15

prometheus-owntracks-exporter

A simple Python HTTP server exporting OwnTracks Recorder stats for Prometheus
Python
3
star
16

spec2json

📝 Extract section metadata and algorithm steps from specification HTML documents as JSON.
Python
3
star
17

adventofcode

🎄 My Advent of Code solutions
Python
2
star
18

serverlog2map

Visualize IP address locations from server logs on a map.
Python
2
star
19

hyper-unspecific-data-parsing-and-graphing-scripts

📈 A simple Python tool/framework for generating statistics about code in a git repository.
Python
2
star
20

wsinfo

Python package for simply retrieving information about a specific website.
Python
2
star
21

user-chrome-playground

Playing around with Firefox's ability to style, relayout or hide browser UI elements with the userChrome.css file
2
star
22

forum-rpi

Tools for the German Raspberry Pi forum.
Python
1
star