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.
Same package and every pin has the same function. Always check voltage, current and timing in the datasheet.
Overview from the pinout data
| Property | Raspberry Pi 4 Model B | Raspberry Pi 5 |
|---|---|---|
| Manufacturer | Raspberry Pi Ltd | Raspberry Pi Ltd |
| Type | Board | Board |
| Compared pinout | 40-Pin GPIO Header (J8) | 40-Pin GPIO Header (J8) |
| Pins | 40 | 40 |
| Supply pins | 3V3, 5V | 3V3, 5V |
| Ground pins | 8 | 8 |
| Interfaces | 1-Wire, I2C, JTAG, PWM, SPI, UART | 1-Wire, I2C, JTAG, PWM, SPI, UART |
Interface pins
| I2C | Raspberry Pi 4 Model B | Raspberry Pi 5 |
|---|---|---|
| SDA | 3 · GPIO215 · GPIO2219 · GPIO10+5 | 3 · GPIO215 · GPIO2219 · GPIO10+4 |
| SCL | 5 · GPIO316 · GPIO2321 · GPIO9+6 | 5 · GPIO316 · GPIO2321 · GPIO9+5 |
| SPI | Raspberry Pi 4 Model B | Raspberry Pi 5 |
|---|---|---|
| MOSI / COPI | 3 · GPIO28 · GPIO1419 · GPIO10+2 | 3 · GPIO28 · GPIO1419 · GPIO10+2 |
| MISO / CIPO | 21 · GPIO929 · GPIO533 · GPIO13+1 | 21 · GPIO929 · GPIO533 · GPIO13+1 |
| SCK | 5 · GPIO310 · GPIO1523 · GPIO11+1 | 5 · GPIO310 · GPIO1523 · GPIO11+1 |
| CS / SS | 7 · GPIO411 · GPIO1712 · GPIO18+8 | 7 · GPIO411 · GPIO1712 · GPIO18+8 |
| UART | Raspberry Pi 4 Model B | Raspberry Pi 5 |
|---|---|---|
| TX | 7 · GPIO48 · GPIO1432 · GPIO12 | 7 · GPIO48 · GPIO1432 · GPIO12+1 |
| RX | 10 · GPIO1529 · GPIO533 · GPIO13 | 10 · GPIO1529 · GPIO533 · GPIO13+1 |
| RTS | 5 · GPIO311 · GPIO17 | 5 · GPIO311 · GPIO17 |
| CTS | 3 · GPIO231 · GPIO636 · GPIO16 | 3 · 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.
| Pin | Raspberry Pi 4 Model B | Raspberry Pi 5 | |
|---|---|---|---|
| 1 | 3V3 | 3V3 | same |
| 2 | 5V | 5V | same |
| 3 | GPIO2 | GPIO2 | same |
| 4 | 5V | 5V | same |
| 5 | GPIO3 | GPIO3 | same |
| 6 | GND | GND | same |
| 7 | GPIO4 | GPIO4 | same |
| 8 | GPIO14 | GPIO14 | same |
| 9 | GND | GND | same |
| 10 | GPIO15 | GPIO15 | same |
| 11 | GPIO17 | GPIO17 | same |
| 12 | GPIO18 | GPIO18 | same |
| 13 | GPIO27 | GPIO27 | same |
| 14 | GND | GND | same |
| 15 | GPIO22 | GPIO22 | same |
| 16 | GPIO23 | GPIO23 | same |
| 17 | 3V3 | 3V3 | same |
| 18 | GPIO24 | GPIO24 | same |
| 19 | GPIO10 | GPIO10 | same |
| 20 | GND | GND | same |
| 21 | GPIO9 | GPIO9 | same |
| 22 | GPIO25 | GPIO25 | same |
| 23 | GPIO11 | GPIO11 | same |
| 24 | GPIO8 | GPIO8 | same |
| 25 | GND | GND | same |
| 26 | GPIO7 | GPIO7 | same |
| 27 | ID_SD | ID_SD | same |
| 28 | ID_SC | ID_SC | same |
| 29 | GPIO5 | GPIO5 | same |
| 30 | GND | GND | same |
| 31 | GPIO6 | GPIO6 | same |
| 32 | GPIO12 | GPIO12 | same |
| 33 | GPIO13 | GPIO13 | same |
| 34 | GND | GND | same |
| 35 | GPIO19 | GPIO19 | same |
| 36 | GPIO16 | GPIO16 | same |
| 37 | GPIO26 | GPIO26 | same |
| 38 | GPIO20 | GPIO20 | same |
| 39 | GND | GND | same |
| 40 | GPIO21 | GPIO21 | same |
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.