User Tools

Site Tools


raspberry:raspberry-gpio

This is an old revision of the document!


Table of Contents

GPIO

The old sysfs GPIO interface is deprecated and will be phased out of the kernel. As part of this the base offset of GPIO ports has been omitted in the kernel. Setting the base GPIO number to zero will result in a boot up error on kernels from 6.6. At the same time, the sysfs interface to the GPIOs has been deprecated - some distributions have already disabled it and are expecting users to go through libgpiod. In 6.6, high-numbered GPIOs - probably still available by sysfs, but eventually that will be switched off.

Query GPIO ports

From 6.5 onwards, the Pi kernel is not forcing a base GPIO for the main GPIO driver. Whilst the sysfs API is still enabled, the base GPIOs will change. The dynamic assignment generally starts at 512 and counts down. If you really need to track down a GPIO using sysfs, look through /sys/class/gpiochipN/ for a device with an appropriate label or ngpio, and then use base to determine the GPIO number.

cat /sys/kernel/debug/gpio
--------------------------
gpiochip0: GPIOs 512-565, parent: platform/3f200000.gpio, pinctrl-bcm2835:
 gpio-512 (ID_SDA              )
 gpio-513 (ID_SCL              )
 gpio-514 (GPIO2               )
 gpio-515 (GPIO3               )
 gpio-516 (GPIO4               )
 gpio-517 (GPIO5               |sysfs               ) in  hi 
 gpio-518 (GPIO6               )
 gpio-519 (GPIO7               )
 gpio-520 (GPIO8               )
 gpio-521 (GPIO9               )
 gpio-522 (GPIO10              )
 gpio-523 (GPIO11              )
 gpio-524 (GPIO12              )
 gpio-525 (GPIO13              )
 gpio-526 (GPIO14              )
 gpio-527 (GPIO15              )
 gpio-528 (GPIO16              )
 gpio-529 (GPIO17              )
 gpio-530 (GPIO18              )
 gpio-531 (GPIO19              )
 gpio-532 (GPIO20              )
 gpio-533 (GPIO21              )
 gpio-534 (GPIO22              )
 gpio-535 (GPIO23              )
 gpio-536 (GPIO24              )
 gpio-537 (GPIO25              )
 gpio-538 (GPIO26              )
 gpio-539 (GPIO27              )
 gpio-540 (SDA0                )
 gpio-541 (SCL0                )
 gpio-542 (NC                  )
 gpio-543 (LAN_RUN             )
 gpio-544 (CAM_GPIO1           )
 gpio-545 (NC                  )
 gpio-546 (NC                  )
 gpio-547 (PWR_LOW_N           |PWR                 ) in  lo 
 gpio-548 (NC                  )
 gpio-549 (NC                  )
 gpio-550 (USB_LIMIT           )
 gpio-551 (NC                  )
 gpio-552 (PWM0_OUT            )
 gpio-553 (CAM_GPIO0           |cam1_regulator      ) out lo 
 gpio-554 (SMPS_SCL            )
 gpio-555 (SMPS_SDA            )
 gpio-556 (ETH_CLK             )
 gpio-557 (PWM1_OUT            )
 gpio-558 (HDMI_HPD_N          |hpd                 ) in  hi ACTIVE LOW
 gpio-559 (STATUS_LED          |ACT                 ) out lo 
 gpio-560 (SD_CLK_R            )
 gpio-561 (SD_CMD_R            )
 gpio-562 (SD_DATA0_R          )
 gpio-563 (SD_DATA1_R          )
 gpio-564 (SD_DATA2_R          )
 gpio-565 (SD_DATA3_R          )

gpiochip1: GPIOs 566-569, parent: usb/1-1.4:1.0, ftdi-cbus, can sleep:

GPIOD

You can install the libraries and tools to interact with this device, using sudo apt install gpiod. This will install the gpiod tools, and the libgpiod2 library to let you interact with the device from your own code.

apt install gpiod --> runtime
apt install libgpiod2  --> build libraries
raspberry/raspberry-gpio.1713886466.txt.gz · Last modified: by oscar