File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 11"""Library for the Pimoroni Blinkt! - 8-pixel APA102 LED display."""
22import atexit
3+ import glob
34import time
45
56import gpiod
1112CLK = 24
1213NUM_PIXELS = 8
1314BRIGHTNESS = 7
14- GPIOCHIP = "/dev/gpiochip4"
15+ RPI_GPIO_LABELS = [
16+ "pinctrl-rp1" , # Pi 5 - Bookworm, /dev/gpiochip4 maybe
17+ "pinctrl-bcm2711" # Pi 4 - Bullseye, /dev/gpiochip1 maybe
18+ ]
1519
1620pixels = [[0 , 0 , 0 , BRIGHTNESS ]] * NUM_PIXELS
1721
@@ -28,6 +32,14 @@ def _exit():
2832 gpio_lines .release ()
2933
3034
35+ def get_gpiochip ():
36+ for path in glob .glob ("/dev/gpiochip*" ):
37+ if gpiod .is_gpiochip_device (path ):
38+ if gpiod .Chip (path ).get_info ().label in RPI_GPIO_LABELS :
39+ return path
40+ raise RuntimeError ("Compatible /dev/gpiochipN device not found!" )
41+
42+
3143def set_brightness (brightness ):
3244 """Set the brightness of all pixels.
3345
@@ -83,7 +95,7 @@ def show():
8395
8496 if not gpio_lines :
8597 gpio_lines = gpiod .request_lines (
86- GPIOCHIP ,
98+ get_gpiochip () ,
8799 consumer = "blinkt" ,
88100 config = {
89101 DAT : gpiod .LineSettings (direction = Direction .OUTPUT , output_value = Value .INACTIVE ),
You can’t perform that action at this time.
0 commit comments