Skip to content

Commit e79775a

Browse files
committed
Search for common gpiochip device names.
Tested so far on a Pi 4 running Bullseye and a Pi 5 running Bookworm.
1 parent c8506c9 commit e79775a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

blinkt/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Library for the Pimoroni Blinkt! - 8-pixel APA102 LED display."""
22
import atexit
3+
import glob
34
import time
45

56
import gpiod
@@ -11,7 +12,10 @@
1112
CLK = 24
1213
NUM_PIXELS = 8
1314
BRIGHTNESS = 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

1620
pixels = [[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+
3143
def 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),

0 commit comments

Comments
 (0)