Complete Hardware Reference · BCM2711

Raspberry Pi 4
GPIO & Peripherals

Full 40-pin pinout, alternate functions, pull states — plus interactive tools: I²C · SPI · UART · PWM · 1-Wire reference, GPIO planner with conflict detection, PWM calculator, voltage divider, LED resistor, and more. Based on BCM2711 datasheet RP-008341-DS Rev 1.1.

BCM2711 40-Pin Header 28 User GPIOs 6 ALT Modes Rev 1.1 · 2024
40
Total Pins
28
User GPIOs
6
ALT Modes
7
SPI Buses
✕

40-Pin GPIO Map

Click any pin circle or label for full details · Filter by type using legend below

💡 Orientation: Pin 1 (3.3V) is top-left when USB ports face right. Odd pins = left column, Even = right. All GPIO logic is 3.3V — NOT 5V tolerant. Max 16 mA per pin, 50 mA total.

Visual GPIO Board

Hover pins to preview · Click to jump to detail · Coloured by function type

ODD 1,3,5…
GPIO
EVEN 2,4,6…
Hover a pin dot to see its function
⚠️ Never connect 5V to a GPIO pin. Use a level-shifter (BSS138, TXS0108E) or resistor divider for one-way signals.
⚡ GPIO current limits: 16 mA max per pin · 50 mA total · Always use a current-limiting resistor with LEDs.

Alternate Functions

All 28 user GPIOs · ALT0–ALT5 · Source: RP-008341-DS Release 1.1, March 2024

Key: UARTSPI I²CPWM PCM/CLKJTAG GPCLKDPI/SD

Pull-up / Pull-down States

Default pull state at BCM2711 power-on. All overridable in software.

Pull-UP (HIGH by default)
Pin reads HIGH when floating. BCM2711 internal pull ≈ 50 kΩ. I²C header pins have board-level 1.8 kΩ pull-ups for fast edge rates.
Pull-DOWN (LOW by default)
Override: GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
⚠ 3.3V Logic ONLY — All GPIO pins
Connecting 5V will permanently damage the BCM2711. Use a bi-directional level shifter (e.g., TXS0108E) or voltage divider for read-only 5V signals.

I²C — Inter-Integrated Circuit

BCM2711 provides 7 I²C buses. I²C1 (Bus 1) is on the 40-pin header at Pins 3 and 5.

I²C
I²C Basics
Two-wire synchronous serial
Wires2 (SDA + SCL)
TopologyMulti-master / multi-slave
Standard100 kHz
Fast mode400 kHz
Fast+1 MHz
Addresses7-bit (128) or 10-bit
BCM2711 buses7 (I²C0–I²C6)
Header busI²C1 ← use this
SDA1BCM2 · Pin 3Data · 1.8kΩ board pull-up
SCL1BCM3 · Pin 5Clock · 1.8kΩ board pull-up
SDA0BCM0 · Pin 27HAT EEPROM — reserved
SCL0BCM1 · Pin 28HAT EEPROM — reserved
I²C
Enable & Scan
Setup and diagnostics
Enable I²C
sudo raspi-config → Interface → I²C → Yes
# /boot/config.txt:
dtparam=i2c_arm=on
dtparam=i2c_arm_baudrate=400000
Scan & debug
sudo apt install i2c-tools
i2cdetect -y 1
i2cget -y 1 0x68 0x75
i2cset -y 1 0x68 0x6B 0x00
I²C
I²C Bus Map
All BCM2711 I²C buses
I²C0HAT EEPROM (GPIO0/1)
I²C1Header Pins 3+5 ← use
I²C2HDMI DDC (internal)
I²C3GPIO2/3/4/5 (ALT mux)
I²C4GPIO7/8/9 (ALT mux)
I²C5GPIO10/11/12/13 (ALT mux)
I²C6GPIO0/1/22/23 (ALT mux)

SPI — Serial Peripheral Interface

BCM2711 has 7 SPI buses. SPI0 on header pins; SPI1–6 via ALT mux.

SPI
SPI0 Header Pins
Main SPI bus on 40-pin header
TypeSynchronous full-duplex
Max speed125 MHz (250 MHz ÷ n)
ModesCPOL/CPHA 0,1,2,3
CE0GPIO8 · Pin 24 (active LOW)
CE1GPIO7 · Pin 26 (active LOW)
MOSIGPIO10 · Pin 19Master Out Slave In
MISOGPIO9 · Pin 21Master In Slave Out
SCLKGPIO11 · Pin 23Clock
CE0GPIO8 · Pin 24Chip enable 0
CE1GPIO7 · Pin 26Chip enable 1
SPI
SPI Bus Map
All 7 BCM2711 SPI buses
SPI0GPIO7–11 (header) ← use
SPI1GPIO16–21 (ALT4)
SPI2Not on header
SPI3GPIO0/1/2/3/4 (ALT3)
SPI4GPIO4/5/6/7/8 (ALT3)
SPI5GPIO12–16 (ALT3)
SPI6GPIO18–21 (ALT3)
Enable SPI
sudo raspi-config → SPI → Yes
dtparam=spi=on
dtoverlay=spi1-3cs # for SPI1
SPI
SPI Modes
Clock polarity and phase
Mode 0CPOL=0 CPHA=0 (most common)
Mode 1CPOL=0 CPHA=1
Mode 2CPOL=1 CPHA=0
Mode 3CPOL=1 CPHA=1
CPOL=0Clock idles LOW
CPOL=1Clock idles HIGH
CPHA=0Sample on leading edge
CPHA=1Sample on trailing edge

UART — Universal Async Receiver-Transmitter

BCM2711 has 6 UARTs. UART0 is a full PL011; UART1 is mini-UART (CPU-clock-dependent).

TX
Header UART Pins
GPIO14/15 — default serial port
Default baud115200 bps
Baud range300 – 4 Mbps
UART0PL011 ← preferred
UART1Mini-UART (baud varies)
/dev/serial0Symlink → active UART
TXD0GPIO14 · Pin 8TX → RX of device
RXD0GPIO15 · Pin 10RX ← TX of device
TX
UART Bus Map
All 6 BCM2711 UARTs
UART0GPIO14/15 (ALT0) — PL011
UART1GPIO14/15 (ALT5) — mini
UART2GPIO0/1 (ALT4)
UART3GPIO4/5 (ALT4)
UART4GPIO8/9 (ALT4)
UART5GPIO12/13/14/15 (ALT4)
Disable console (required for device use)
sudo raspi-config → Interface → Serial Port
Login shell: No · Hardware port: Yes
TX
Loopback Test
Verify UART hardware
⚠ Loopback: bridge Pin 8 (TX) ↔ Pin 10 (RX)
Python loopback
import serial
ser = serial.Serial('/dev/serial0', 9600, timeout=2)
ser.write(b'HELLO')
print(ser.read(5))
UART0 device/dev/serial0 · /dev/ttyAMA0
UART1 device/dev/ttyS0

PWM — Pulse Width Modulation

2 hardware PWM channels. Multiple GPIO pins route to each via ALT modes.

PWM
Hardware PWM Pins
True hardware-timed PWM
Channels2 (PWM0, PWM1)
Freq range~1 Hz – 125 MHz
Clock source19.2 MHz oscillator
Servo freq50 Hz (20 ms period)
Servo pulse1000–2000 µs
PWM0GPIO18 · Pin 12 (ALT5)Channel 0 ← main
PWM0GPIO12 · Pin 32 (ALT0)Channel 0 alt
PWM1GPIO13 · Pin 33 (ALT0)Channel 1
PWM1GPIO19 · Pin 35 (ALT5)Channel 1 alt
PCM
PCM / I²S Audio
Digital audio interface
ProtocolI²S / PCM digital audio
Sample rates8 kHz – 192 kHz
Bit depthUp to 32-bit
Enabledtoverlay=i2s-mmap
PCM_CLKGPIO18 · Pin 12Bit clock (ALT0)
PCM_FSGPIO19 · Pin 35Frame sync (ALT0)
PCM_DINGPIO20 · Pin 38Data in (ALT0)
PCM_DOUTGPIO21 · Pin 40Data out (ALT0)
CLK
General Purpose Clocks
GPCLK0, GPCLK1, GPCLK2
SourcesOscillator, PLLA, PLLD, HDMI
Use caseAudio MCLK, external ref
GPCLK0GPIO4 · Pin 7 (ALT0)
GPCLK0GPIO20 · Pin 38 (ALT5)
GPCLK1GPIO5 · Pin 29 (ALT0)
GPCLK2GPIO6 · Pin 31 (ALT0)

1-Wire — DS18B20 Temperature Sensor

Dallas 1-Wire on GPIO4 via kernel driver. Supports multiple sensors on one pin.

1W
1-Wire Protocol
Single-wire, parasitic or VCC power
Default pinGPIO4 (Pin 7)
Pull-up required4.7 kΩ to 3.3V (external!)
Standard speed15.4 kbps
Overdrive125 kbps
Temp accuracy±0.5°C (−10°C to +85°C)
Resolution9–12 bit (configurable)
Conversion time750 ms @ 12-bit
Multi-sensorUnique 64-bit ID per device
1W
Wiring & Setup
DS18B20 connections
DS18B20 3-wire wiring
VCC → 3.3V (Pin 1)
GND → GND (Pin 6)
DATA → GPIO4 (Pin 7)
4.7kΩ between VCC ↔ DATA
Enable & verify
# /boot/config.txt:
dtoverlay=w1-gpio,gpiopin=4
ls /sys/bus/w1/devices/
cat /sys/bus/w1/devices/28-*/w1_slave

Pin Assignment Planner

Click any GPIO pin → see its ALT functions → pick one to assign · Conflict detection is bus-aware (two UARTs on different pins = ✓ OK)

← Click a GPIO pin
to see its ALT functions
Conflicts
No conflicts
Available
Assigned
Conflict
Reserved / Power

Tools & Calculators

PWM · Voltage divider · Servo · I²C address decoder · LED resistor · UART baud

〰️

PWM Frequency Calculator

Target Frequency (Hz)
Duty Cycle: 50%
Enter frequency to calculate
⚡

Voltage Divider (5V→3.3V)

Input Voltage (V)
Target Output (V)
R1 top resistor (Ω)
Set values to calculate R2
🔄

Servo Pulse Width

Angle: 90°
Min pulse (µs)
Max pulse (µs)
Adjust angle to calculate
🔗

I²C Address Decoder

I²C Address (hex)
Enter address to identify device
💡

LED Resistor Calculator

Supply Voltage (V)
LED Type
Current (mA)
Fill values to calculate
💬

UART Baud Rate Info

Target baud rate
Select baud rate for details

All Peripheral Blocks

Full peripheral inventory of the BCM2711 SoC in Raspberry Pi 4 Model B

Signal Timing Reference

I²C Timing
Standard100 kHz
Fast mode400 kHz
Fast+1 MHz
Bit time @ 100kHz10 µs
Board pull-up1.8 kΩ
SPI Timing
Max clock125 MHz
Clock divisor250 MHz / n (even)
Default500 kHz
CE setup1 clock cycle
CE polarityActive LOW
UART Timing
Common bauds9600, 115200, 230400
Max (UART0)~4 Mbps
Frame default8N1
Start bit1 bit (LOW)
Stop bit1 or 2 bits (HIGH)
PWM / Servo
Servo freq50 Hz (20 ms period)
0°1.0 ms (5%)
90°1.5 ms (7.5%)
180°2.0 ms (10%)
LED PWM1 kHz typical
GPIO Electrical
Logic voltage3.3V ONLY
Max per pin16 mA output
Max total50 mA (all GPIO)
HIGH threshold> 1.6V
Internal pull~50 kΩ
1-Wire Timing
Standard speed15.4 kbps
Overdrive125 kbps
Reset pulse480 µs LOW
DS18B20 convert750 ms @ 12-bit
Pull-up4.7 kΩ to 3.3V

Code Snippets

RPi.GPIO · smbus2 · spidev · pyserial · gpiozero · pigpio — click copy on any block

GPIO — RPi.GPIO
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Output — blink LED on GPIO18
GPIO.setup(18, GPIO.OUT)
for _ in range(5):
    GPIO.output(18, GPIO.HIGH); time.sleep(0.5)
    GPIO.output(18, GPIO.LOW);  time.sleep(0.5)

# Input with pull-up
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
val = GPIO.input(17)  # 1=HIGH, 0=LOW

# Edge interrupt callback
def on_edge(channel):
    print(f"Rising edge on GPIO{channel}")

GPIO.add_event_detect(17, GPIO.RISING,
    callback=on_edge, bouncetime=200)
GPIO.cleanup()  # always cleanup
PWM — LED + Servo
import RPi.GPIO as GPIO, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)

# Software PWM @ 1kHz (LED fade)
pwm = GPIO.PWM(18, 1000)
pwm.start(0)
for dc in range(0, 101, 5):
    pwm.ChangeDutyCycle(dc); time.sleep(0.04)
pwm.stop()

# Servo @ 50 Hz on GPIO18
servo = GPIO.PWM(18, 50)
servo.start(7.5)       # 90° neutral
time.sleep(1)
servo.ChangeDutyCycle(2.5)  # 0°
time.sleep(1)
servo.ChangeDutyCycle(12.5) # 180°
time.sleep(1)
servo.stop(); GPIO.cleanup()
1-Wire — DS18B20
import glob, time

# Requires: dtoverlay=w1-gpio in /boot/config.txt
def read_temp(sensor_path):
    with open(f"{sensor_path}/w1_slave") as f:
        lines = f.readlines()
    if 'YES' in lines[0]:
        raw = lines[1].split('t=')[1].strip()
        return float(raw) / 1000.0
    return None

sensors = glob.glob('/sys/bus/w1/devices/28-*')
for s in sensors:
    t = read_temp(s)
    name = s.split('/')[-1]
    print(f"{name}: {t:.3f}°C / {t*9/5+32:.1f}°F")
gpiozero — Modern API
from gpiozero import LED, Button, PWMLED, Servo
from signal import pause

led = LED(18)
led.blink(on_time=0.5, off_time=0.5)

pwm_led = PWMLED(18)
pwm_led.pulse()  # smooth fade in/out

btn = Button(17)
btn.when_pressed  = lambda: print('Pressed!')
btn.when_released = lambda: print('Released!')

servo = Servo(18)
servo.min()  # 0°
servo.mid()  # 90°
servo.max()  # 180°
pause()
I²C — smbus2
import smbus2

bus = smbus2.SMBus(1)  # Bus 1 = Pin 3+5

# Scan all 7-bit addresses
found = []
for addr in range(0x03, 0x78):
    try:
        bus.read_byte(addr)
        found.append(f"0x{addr:02X}")
    except OSError:
        pass
print("Devices:", found)

# MPU-6050 (0x68) — read WHO_AM_I
who = bus.read_byte_data(0x68, 0x75)
print(f"WHO_AM_I = 0x{who:02X}")  # → 0x68
bus.write_byte_data(0x68, 0x6B, 0x00)  # wake
data = bus.read_i2c_block_data(0x68, 0x3B, 6)
ax = (data[0] << 8) | data[1]
bus.close()
SPI — spidev
import spidev

spi = spidev.SpiDev()
spi.open(0, 0)           # bus=0, CE0
spi.max_speed_hz = 500000
spi.mode = 0             # CPOL=0 CPHA=0

# Full-duplex loopback (wire MOSI→MISO)
tx = [0xDE, 0xAD, 0xBE, 0xEF]
rx = spi.xfer2(tx)
print(tx == rx)  # True if loopback wired

# MCP3008 ADC — read channel 0
def read_adc(ch):
    assert 0 <= ch <= 7
    r = spi.xfer2([1, (8+ch) << 4, 0])
    return ((r[1] & 3) << 8) + r[2]

val = read_adc(0)
voltage = val * 3.3 / 1023
print(f"{val} → {voltage:.3f}V")
spi.close()
UART — pyserial
import serial, time
# Disable console first via raspi-config!
ser = serial.Serial(
    port='/dev/serial0',
    baudrate=9600,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    timeout=2
)
ser.write(b'Hello RPi!')
time.sleep(0.05)
print(ser.read(10))
# Non-blocking read loop
ser.timeout = 0
while True:
    if ser.in_waiting:
        line = ser.readline().decode('utf-8', errors='ignore')
        print(line.strip())
    time.sleep(0.01)
ser.close()
Hardware PWM — pigpio
import pigpio, time
# sudo pigpiod  (start daemon first)
pi = pigpio.pi()

# HW PWM on GPIO18 — 50Hz neutral servo
pi.hardware_PWM(18, 50, 75000)   # 7.5%
time.sleep(1)
pi.hardware_PWM(18, 50, 50000)   # 0°
time.sleep(1)
pi.hardware_PWM(18, 50, 100000)  # 180°
time.sleep(1)
pi.hardware_PWM(18, 0, 0)  # off
pi.stop()

Quick Reference

Essential pins, commands, packages and safety limits

Power Pins
3.3VPin 1, 17
5VPin 2, 4
GND6,9,14,20,25,30,34,39
I²C Bus 1
SDAGPIO2 · Pin 3
SCLGPIO3 · Pin 5
EEPROMGPIO0/1 · Pin 27/28
Enableraspi-config → I²C
SPI Bus 0
MOSIGPIO10 · Pin 19
MISOGPIO9 · Pin 21
SCLKGPIO11 · Pin 23
CE0GPIO8 · Pin 24
CE1GPIO7 · Pin 26
UART
TXGPIO14 · Pin 8
RXGPIO15 · Pin 10
UART0/dev/ttyAMA0
symlink/dev/serial0
PWM
PWM0 mainGPIO18 · Pin 12
PWM0 altGPIO12 · Pin 32
PWM1GPIO13 · Pin 33
PWM1 altGPIO19 · Pin 35
1-Wire
Default pinGPIO4 · Pin 7
Pull-up4.7kΩ to 3.3V
Sysfs/sys/bus/w1/devices/
Enabledtoverlay=w1-gpio
raspi-config
I²CInterface → I2C
SPIInterface → SPI
UARTInterface → Serial Port
1-WireInterface → 1-Wire
CameraInterface → Camera
pip packages
GPIOpip install RPi.GPIO
I²Cpip install smbus2
SPIpip install spidev
UARTpip install pyserial
Modernpip install gpiozero
HW PWMpip install pigpio
GPIO Safety
Logic3.3V ONLY
Max/pin16 mA output
Max total50 mA all GPIO
Pull R~50 kΩ internal
HIGH min> 1.6V
LOW max< 0.8V
↑