0

With gpiod installed on a Raspberry Pi 5, you can use gpioinfo to list all the GPIO lines:

$ sudo gpioinfo gpiochip4
gpiochip4 - 54 lines:
    line   0:      "ID_SD"       unused   input  active-high 
    line   1:      "ID_SC"       unused   input  active-high 
    line   2:       "PIN3"       unused   input  active-high 
    line   3:       "PIN5"       unused   input  active-high 
    line   4:       "PIN7"       unused   input  active-high 
    line   5:      "PIN29"       unused   input  active-high 
    line   6:      "PIN31"       unused   input  active-high 
    line   7:      "PIN26"   "spi0 CS1"  output   active-low [used]
    line   8:      "PIN24"   "spi0 CS0"  output   active-low [used]
    line   9:      "PIN21"       unused   input  active-high 
    line  10:      "PIN19"       unused   input  active-high 
    line  11:      "PIN23"       unused   input  active-high 
    line  12:      "PIN32"       unused   input  active-high 
    line  13:      "PIN33"       unused   input  active-high 
    line  14:       "PIN8"       unused   input  active-high 
    line  15:      "PIN10"       unused   input  active-high 
    line  16:      "PIN36"       unused   input  active-high 
    line  17:      "PIN11"       unused   input  active-high 
    line  18:      "PIN12"       unused   input  active-high 
    line  19:      "PIN35"       unused   input  active-high 
    line  20:      "PIN38"       unused   input  active-high 
    line  21:      "PIN40"       unused   input  active-high 
    line  22:      "PIN15"       unused   input  active-high 
    line  23:      "PIN16"       unused   input  active-high 
    line  24:      "PIN18"       unused   input  active-high 
    line  25:      "PIN22"       unused   input  active-high 
    line  26:      "PIN37"       unused   input  active-high 
    line  27:      "PIN13"       unused   input  active-high 
    line  28: "PCIE_RP1_WAKE" unused input active-high 
    line  29:   "FAN_TACH"       unused   input  active-high 
    line  30:   "HOST_SDA"       unused   input  active-high 
    line  31:   "HOST_SCL"       unused   input  active-high 
    line  32:  "ETH_RST_N"  "phy-reset"  output   active-low [used]
    line  33:          "-"       unused   input  active-high 
    line  34: "CD0_IO0_MICCLK" "cam0_reg" output active-high [used]
    line  35: "CD0_IO0_MICDAT0" unused input active-high 
    line  36: "RP1_PCIE_CLKREQ_N" unused input active-high 
    line  37:          "-"       unused   input  active-high 
    line  38:    "CD0_SDA"       unused   input  active-high 
    line  39:    "CD0_SCL"       unused   input  active-high 
    line  40:    "CD1_SDA"       unused   input  active-high 
    line  41:    "CD1_SCL"       unused   input  active-high 
    line  42: "USB_VBUS_EN" unused output active-high 
    line  43:   "USB_OC_N"       unused   input  active-high 
    line  44: "RP1_STAT_LED" "PWR" output active-low [used]
    line  45:    "FAN_PWM"       unused  output  active-high 
    line  46: "CD1_IO0_MICCLK" "cam1_reg" output active-high [used]
    line  47:  "2712_WAKE"       unused   input  active-high 
    line  48: "CD1_IO1_MICDAT1" unused input active-high 
    line  49: "EN_MAX_USB_CUR" unused output active-high 
    line  50:          "-"       unused   input  active-high 
    line  51:          "-"       unused   input  active-high 
    line  52:          "-"       unused   input  active-high 
    line  53:          "-"       unused   input  active-high 

The mapping of these lines to the BCM pin numbers is non-obvious. Is PIN5 referring to BCM pin 5 (physical pin 29)? Or is PIN29 referring to physical pin 29 (BCM pin 5)?

rgov
  • 223
  • 2
  • 9

1 Answers1

0

The line numbers 0-27 correspond with the BCM numbers of the GPIOs. This numbering scheme is what you will virtually always use in software.

(Note: The gpioget tool uses another term, "offset", which means the same as line number, and in the context of RPi, BCM number.)

As @Milliways points out, this numbering is intrinsic to the Broadcom SoC design, where our software is running, whereas the way these are wired the 40-pin header is arbitrarily decided by the Raspberry Pi designers.

The Raspberry Pi device tree helpfully defines gpio-line-names which give textual labels to the GPIO lines. In these labels, PIN# are referring to the physical pin numbers. For the Raspberry Pi 5, these are:

3, 5, 7, 8, 10, 11, 12, 13, 15, 16,
18, 19, 21, 22, 23, 24, 26, 29, 31,
32, 33, 35, 36, 37, 38, 40

For example, GPIO 25 appears as line 25: "PIN22"; the label lets us know it is physical pin 22.

Note that GPIO 0 (physical pin 27) is labeled ID_SD, and GPIO 1 (physical pin 28) is labeled ID_SC. These are normally reserved for querying the EEPROM of an attached HAT.

To conclude, to use gpioget you must use the BCM aka line number aka "offset".

rgov
  • 223
  • 2
  • 9