r/raspberry_pi • • 3d ago

Troubleshooting Pins not releasing properly with lgpio

I have been trying to put together a simple python script with a Raspberry Pi 5 (model B Rev 1.1 with Pi OS 13 - Trixie).

It is very straightforward:

import lgpio, time

h = lgpio.gpiochip_open(0)

lgpio.gpio_claim_output(h, 22)
lgpio.gpio_write(h, 22, 1)
time.sleep(1)
lgpio.gpio_write(h, 22, 0)
lgpio.gpio_free(h, 22)
lgpio.gpiochip_close(h)

However, when I check using pinctrl in the terminal afterward, the pin is still enabled as an output (and if I don't set it back to low in the script, it stays at high). Is there some other step I am missing on how to control the pins and release them properly so that they go back to inactive?

8 Upvotes

3 comments sorted by

2

u/Gamerfrom61 3d ago

Possibly add a lgpio.stop() at the end?

TBH I have never tried this on a Pi 5 with the RP1 chip handling the GPIO pins. 

1

u/Previous_Tea_2250 3d ago

I would check whether `pinctrl` still shows a consumer after the script exits. `gpio_free` releases your process’s claim, but it may leave the pin in its last configured hardware state rather than restoring an input/default state. Explicitly writing the safe level before freeing it is the important part; `lgpio.stop()` is worth testing as cleanup, but I would not rely on it alone to reset a pin state.