Comparison

Raspberry Pi 4 Model B vs Raspberry Pi 5

Same 40-pin header, but new connectors and a different GPIO controller.

At first glance nothing changes on the GPIO header when moving from the Raspberry Pi 4 to the Raspberry Pi 5: both have the familiar 40-pin header with the same pinout, so 3.3 V on pin 1, 5 V on pins 2 and 4, I2C on GPIO2 and GPIO3, SPI0 on GPIO9 to 11 and the UART on GPIO14 and GPIO15. HATs and breakout cables therefore still fit electrically, as long as they respect the 3.3 V logic levels.

Under the hood, however, a lot has changed. On the Pi 5 the GPIOs are no longer driven directly by the main processor but by the new RP1 southbridge chip. Libraries that write straight to the registers, such as the old RPi.GPIO, no longer work; gpiozero, lgpio and libgpiod do. New are a PCI Express connector on a flat flex cable, a dedicated three-pin UART debug connector, a connector for an RTC backup battery and a power button. The camera and display connectors on the Pi 5 are combined mini FPC sockets, so older cameras need an adapter cable.

The pin-by-pin table shows that the 40-pin header is identical. Below it you will find the connectors that only one of the two boards has.

Pin-compatible

Same package and every pin has the same function. Always check voltage, current and timing in the datasheet.

Overview from the pinout data

PropertyRaspberry Pi 4 Model BRaspberry Pi 5
ManufacturerRaspberry Pi LtdRaspberry Pi Ltd
TypeBoardBoard
Compared pinout40-Pin GPIO Header (J8)40-Pin GPIO Header (J8)
Pins4040
Supply pins3V3, 5V3V3, 5V
Ground pins88
Interfaces1-Wire, I2C, JTAG, PWM, SPI, UART1-Wire, I2C, JTAG, PWM, SPI, UART

Interface pins

I2CRaspberry Pi 4 Model BRaspberry Pi 5
SDA3 · GPIO215 · GPIO2219 · GPIO10+53 · GPIO215 · GPIO2219 · GPIO10+4
SCL5 · GPIO316 · GPIO2321 · GPIO9+65 · GPIO316 · GPIO2321 · GPIO9+5
SPIRaspberry Pi 4 Model BRaspberry Pi 5
MOSI / COPI3 · GPIO28 · GPIO1419 · GPIO10+23 · GPIO28 · GPIO1419 · GPIO10+2
MISO / CIPO21 · GPIO929 · GPIO533 · GPIO13+121 · GPIO929 · GPIO533 · GPIO13+1
SCK5 · GPIO310 · GPIO1523 · GPIO11+15 · GPIO310 · GPIO1523 · GPIO11+1
CS / SS7 · GPIO411 · GPIO1712 · GPIO18+87 · GPIO411 · GPIO1712 · GPIO18+8
UARTRaspberry Pi 4 Model BRaspberry Pi 5
TX7 · GPIO48 · GPIO1432 · GPIO127 · GPIO48 · GPIO1432 · GPIO12+1
RX10 · GPIO1529 · GPIO533 · GPIO1310 · GPIO1529 · GPIO533 · GPIO13+1
RTS5 · GPIO311 · GPIO175 · GPIO311 · GPIO17
CTS3 · GPIO231 · GPIO636 · GPIO163 · GPIO231 · GPIO636 · GPIO16

Pin number · pin name. "+n" = further pins with the same function.

Pin by pin

40 of 40 pins have the same function at the same position.

PinRaspberry Pi 4 Model BRaspberry Pi 5
13V33V3same
25V5Vsame
3GPIO2GPIO2same
45V5Vsame
5GPIO3GPIO3same
6GNDGNDsame
7GPIO4GPIO4same
8GPIO14GPIO14same
9GNDGNDsame
10GPIO15GPIO15same
11GPIO17GPIO17same
12GPIO18GPIO18same
13GPIO27GPIO27same
14GNDGNDsame
15GPIO22GPIO22same
16GPIO23GPIO23same
173V33V3same
18GPIO24GPIO24same
19GPIO10GPIO10same
20GNDGNDsame
21GPIO9GPIO9same
22GPIO25GPIO25same
23GPIO11GPIO11same
24GPIO8GPIO8same
25GNDGNDsame
26GPIO7GPIO7same
27ID_SDID_SDsame
28ID_SCID_SCsame
29GPIO5GPIO5same
30GNDGNDsame
31GPIO6GPIO6same
32GPIO12GPIO12same
33GPIO13GPIO13same
34GNDGNDsame
35GPIO19GPIO19same
36GPIO16GPIO16same
37GPIO26GPIO26same
38GPIO20GPIO20same
39GNDGNDsame
40GPIO21GPIO21same

Further connectors

Raspberry Pi 4 Model B

  • 4-Pin PoE Header (J0)
  • Global En / Run Header (J2 / RUN)
  • 15-Pin MIPI CSI Camera Connector
  • 15-Pin MIPI DSI Display Connector

Raspberry Pi 5

  • POE+ Header (J0)
  • RTC Battery Connector
  • UART Serial Connector (J10)
  • PCI Express FPC Connector (J20)
  • Dual MIPI CSI/DSI FPC Connectors (J0, J1)

Verdict

For existing HAT projects the Pi 5 is usually a direct replacement, as long as the software uses a current GPIO library. The Pi 4 still makes sense if old RPi.GPIO code has to run or power consumption and price matter more.