How to Control the Raspberry Pi 5 GPIO with Python 3

Raspberry Pi 5 GPIO with Python 3
(Image credit: Tom's Hardware)

The Raspberry Pi 5 has just been released and it introduced us to a more powerful Pi, but it also changed a few things and most notably it was the GPIO.

We still have the same 40-pin GPIO but it works a little differently now as it is connected to the new RP1 southbridge chip. Why does this matter? Well it all boils down to how we write code that interacts with the GPIO. In the past, alot of projects favored RPi.GPIO. This was a community project by Ben Croston and it served multiple generations of Raspberry Pi well. With the Raspberry Pi 5, we are unable to use RPi.GPIO due to how the GPIO pins are memory mapped. This forces us to use an alternative, and libgpiod is the focus of this how to.

Latest Videos FromTom's Hardware
Les Pounder
Associate Editor

Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".

  • gondor
    "8. Set the Button as an input. We want current to flow to the LED."

    Copy-pasta Les? ;)
    Reply
  • Pi-Plates
    So, is gpiod backwards compatible with the RPi 4 and RPi3? Or do we have to support both RPI.GPIO and gpiod in our scripts?
    Reply
  • pidloop
    What about C?
    Reply
  • Ockwig
    Admin said:
    The Raspberry Pi 5 has a new way to interact with the GPIO and if you need something a little more advanced than GPIO Zero, python3-gpiod is where you need to look. We introduce this Python module by running through two very basic examples that explain the syntax and thinking of the module.

    How to Control the Raspberry Pi 5 GPIO with Python 3 : Read more
    Admin said:
    The Raspberry Pi 5 has a new way to interact with the GPIO and if you need something a little more advanced than GPIO Zero, python3-gpiod is where you need to look. We introduce this Python module by running through two very basic examples that explain the syntax and thinking of the module.

    How to Control the Raspberry Pi 5 GPIO with Python 3 : Read more

    Admin said:
    The Raspberry Pi 5 has a new way to interact with the GPIO and if you need something a little more advanced than GPIO Zero, python3-gpiod is where you need to look. We introduce this Python module by running through two very basic examples that explain the syntax and thinking of the module.

    How to Control the Raspberry Pi 5 GPIO with Python 3 : Read more
    gpiozero or gpiod are not working following error :

    chip = gpiod.Chip('gpiochip4')
    ^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/pi5/pythonprograms/.venv/lib/python3.11/site-packages/gpiod/chip.py", line 58, in __init__
    self._chip = _ext.Chip(path)
    Reply