Jarkko's guides
You are here: Home » Raspberry Pi » Pinning & interfaces

Pinning & interfaces

Pin header

All Raspberry Pi boards with a 40-pin header use this pinout. Besides power and ground pins all other pins are GPIO. Note that the GPIO numbers are not the same as the pin number. You need to refer to an overview like this one to translate the GPIO numbers to pin numbers.

raspberry_pi:raspberry_pinout.svg

The GPIO pins operate at 3.3V. Pay attention to what voltage is output by hardware you attach. That should not exceed 3.3V to prevent damaging the Pi.

Pin functions

  • All pins have multiple functions. For the Pi 4 this document shows an overview (in section 5.3). For the Pi 5 the RP1 documentation shows a overview (in section 3.1.1).
  • In Linux you need to use overlays to select one of the pin functions (such as SPI).
  • By default the pins are true/generic GPIO pins that can be controlled directly from software. You can read the pin value and set the pin value to output something. Doing this directly from software is also known as “bit banging”.
  • "A history of GPIO usage on Raspberry Pi devices, and current best practices" from the official Raspberry website explains which software libraries exist to control the GPIO pins directly.
  • GPIO 0 and 1 are used to identify what HAT is attached. (They are used as I2C interface to read out an EEPROM that can be present on a HAT to contain identification information.) These GPIO pins should be freely usable if you have no HAT attached, but Raspberry seems to discourage its use (they described them as “reserved for advanced use”).
  • On the Pi 4 the main Broadcom chip contains interface controllers. For the Pi 5 all interface controllers have been moved to a separate I/O controller chip called the RP1. These controllers are dedicated pieces of hardware that can drive a specific type of interface. There are controllers for UART, PWM, I2C, SPI, I2S and PIO. Using these controllers results in much faster communication than with bit banging from software and offloads the processor.
  • In December 2024 Raspberry revealed a hidden controller in the RP1 chip (for the Pi 5): the PIO controller (programmable I/O). It could be extremely useful if you need faster bit banging (or more tightly controlled timing). If I understand the functionality correctly it's a tiny processor executing its own simple code. A user library (piolib) has been made available.

I2S digital audio pins

A major difference between the Pi 4 and Pi 5 for audio applications is that the Pi 4 supported only stereo in and stereo out, while the Pi 5 supports 8 input channels + 8 output channels (via an I2S interface). That means you can e.g. have 8 mono outputs or 4 stereo outputs.

The Pi 5 has two I2S controllers in the RP1 chip that are exposed via the GPIO pins: one is called I2S0 (outputting SCLK and WS), the other I2S1 (receiving SCLK and WS). Either one or the other must be selected for the whole set of I2S pins. On the Pi 4 and earlier models it was possible to switch the clock direction on-the-fly (source).

These GPIO pins can have an I2S function. I2Sx stands for: can either be I2S0 or I2S1.

GPIO pin Pi 4 Pi 5
GPIO 18 PCM_CLK I2Sx_SCLK
GPIO 19 PCM_FS (frame sync) I2Sx_WS (word select) 1)
GPIO 20 PCM_DIN (stereo in) I2Sx_SDI[0] (stereo in)
GPIO 21 PCM_DOUT (stereo out) I2Sx_SDO[0] (stereo out)
GPIO 22 I2Sx_SDI[1] (stereo in)
GPIO 23 I2Sx_SDO[1] (stereo out)
GPIO 24 I2Sx_SDI[2] (stereo in)
GPIO 25 I2Sx_SDO[2] (stereo out)
GPIO 26 I2Sx_SDI[3] (stereo in)
GPIO 27 I2Sx_SDO[3] (stereo out)

Official documentation

  • https://www.raspberrypi.com/documentation/
  • https://pip.raspberrypi.com/categories/685-whitepapers-app-notes
  • https://datasheets.raspberrypi.com/bcm2711/bcm2711-peripherals.pdf (Pi 4)
  • https://datasheets.raspberrypi.com/rp1/rp1-peripherals.pdf (Pi 5)
1)
Frame sync and word select for I2S are the same thing.
Previous Next

ALL THE TOPICS ON THIS WEBSITE:

Linux

Raspberry Pi

Digital room correction

Web design

By Jarkko Huijts
Jarkko's guides

Table of Contents

Table of Contents

  • Pinning & interfaces
    • Pin header
    • Pin functions
    • I2S digital audio pins
    • Official documentation

RASPBERRY PI HARDWARE

  • Intro
  • Pinning & interfaces
  • Audio components
  • FLIRC for IR remotes
  • Small displays
  • USB gadget
  • Linux groups

RASPBERRY PI SOFTWARE

  • SD card images
  • CamillaDSP
  • Raspotify

MY DRC SET-UP

  • Overview
  • Spectrum analyzer

AVAILABLE TOPICS

  • Linux
  • Raspberry Pi
  • Digital room correction
  • Web design