Has gpio changed completely betwen bookworm and trixie?

Aug 28, 2025 Last reply: 10 months ago 12 Replies

I have upgraded my Pi 4B from bookworm to trixie and, while most things work fine, my gpiod code in Python is completely broken. Can anyone confirm that everything has changed a lot or am I going mad?


You are not going mad. Here are before and after examples from a shell script that I had to change. It reads a PIO pin and puts a message in a log file if a PIR detector has been triggered. There will be some equivalent change in Python. John

BEFORE

#!/bin/bash

echo "9" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio9/direction

while true; do

temp=$(</sys/class/gpio/gpio9/value) if [[ $temp -eq 1 ]]; then echo -n "Ceiling "; date; echo fi

sleep 2

done

echo "9" > /sys/class/gpio/unexport

AFTER

#!/bin/bash

while true

do

temp=$(pinctrl lev 9) if [[ $temp -eq 1 ]]; then echo -n "Ceiling "; date; echo fi

sleep 2

done

I noticed that when I tried updating a RPi 4 + Geekworm X728 system yesterday. The scripts that talk to the X728 (using rpi-lgpio instead of rpi-gpio) were completely broken. I'm trying to rework them to use gpiozero, hoping that it might be a better-supported system for the long term.

It's probably some rearrangement of the /sys hierarchy.

At some level the C library gpio functions should still work...

OP here, yes, I'm not going mad. There are major changes between the i.6.x and 2.x versions of python3-libgpiod. The trouble is that finding out about it all is very difficult because there are so many different python wrappers for gpiod and this makes searching very frustrating.

The best I've found so far is the 'source':-

formatting link
It has some Python examples but the coding style is very odd and makes it difficult to follow what's going on IMHO.

Can't help. I never use python.

One thing I forgot to mention: the system in question was running Armbian. I'm trying again under Raspbian to see if that makes a difference.

Before blowing Armbian off the board, I was tinkering around with gpiod instead of gpiozero. I tweaked a gpiod example and got the buzzer on the X728 to sound off, but it looks like porting to gpiod would be much more difficult than porting to gpiozero.

I had a look at one or two examples, but they didn’t look very “odd” to me. Any particular ones you are having trouble with?

I worked it all out OK, I do write quite a lot of Python code. My comment was rather that the style using 'with' and so on which makes it rather diffcult to actually follow the sequence of calls required to do simple things like 'set this line high' or 'read the state of that line'.

Ah. Written by a computer scientist rather than a software engineer. Designed to impress, not to elucidate...

You don’t know about context managers? They’re a basic Python mechanism for ensuring proper cleanup. You consider it “odd” just because you hadn’t learned about that feature of Python?

Look, I'm a software engineer (Eur. Ing., FEANI) with well over 50 years of programming experience in all sorts of languages.

Yes, context managers are a 'good thing' but using them to help

**understand** how the basics of a package work is not, IMHO, a good idea. First show how to do something **then** emphasise that you must release resources and say that using a context manager is one way of doing it.

Someone unfamiliar with Python and/or someone who is not an experienced programmer is much more likely to be the audience for these examples. The more professional/skilful people will probably simply dive in to the API documentation.

It is in fact quite a common thing. Look at the examples of use of the open() function in the standard Python library docs

formatting link
, for instance.

There is another call to open() on that page, in an example for another function, and that uses a with-statement too.

This is the old “do as I say, not as I do” school of writing example code. You tell people to understand what the code does and use it as a model, not just blindly copy-and-paste, and ... guess what they do?

In other words, precisely the ones who are in a hurry to get something done, finish an assignment or whatever, and therefore ... blindly copy- and-paste.

One would hope so, but given some discussions that have been happening recently, I’m not so sure ...

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required