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.
Click any pin circle or label for full details · Filter by type using legend below
Hover pins to preview · Click to jump to detail · Coloured by function type
All 28 user GPIOs · ALT0–ALT5 · Source: RP-008341-DS Release 1.1, March 2024
Default pull state at BCM2711 power-on. All overridable in software.
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)BCM2711 provides 7 I²C buses. I²C1 (Bus 1) is on the 40-pin header at Pins 3 and 5.
BCM2711 has 7 SPI buses. SPI0 on header pins; SPI1–6 via ALT mux.
BCM2711 has 6 UARTs. UART0 is a full PL011; UART1 is mini-UART (CPU-clock-dependent).
2 hardware PWM channels. Multiple GPIO pins route to each via ALT modes.
Dallas 1-Wire on GPIO4 via kernel driver. Supports multiple sensors on one pin.
Click any GPIO pin → see its ALT functions → pick one to assign · Conflict detection is bus-aware (two UARTs on different pins = ✓ OK)
PWM · Voltage divider · Servo · I²C address decoder · LED resistor · UART baud
Full peripheral inventory of the BCM2711 SoC in Raspberry Pi 4 Model B
RPi.GPIO · smbus2 · spidev · pyserial · gpiozero · pigpio — click copy on any block
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
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()
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")
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()
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()
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()
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()
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()
Essential pins, commands, packages and safety limits