Skip to main content

GPIO Pinout

Raspberry Pi GPIO pinout reference for EdgeFlow.

Complete GPIO pinout reference for Raspberry Pi 40-pin header. EdgeFlow uses BCM (Broadcom) pin numbering for all GPIO operations. This guide covers all pin functions, alternate modes, and wiring recommendations.

Interactive Pinout Diagram

Hover over any pin to see its details. Click to copy the pin information.

Raspberry Pi GPIO Header 40-Pin Layout (Pi 2/3/4/5/Zero)
1 3V3
5V 2
3 GPIO2 SDA
5V 4
5 GPIO3 SCL
GND 6
7 GPIO4 1-Wire
GPIO14 TXD 8
9 GND
GPIO15 RXD 10
11 GPIO17
GPIO18 PWM0 12
13 GPIO27
GND 14
15 GPIO22
GPIO23 16
17 3V3
GPIO24 18
19 GPIO10 MOSI
GND 20
21 GPIO9 MISO
GPIO25 22
23 GPIO11 SCLK
GPIO8 CE0 24
25 GND
GPIO7 CE1 26
27 GPIO0 ID_SD
GPIO1 ID_SC 28
29 GPIO5
GND 30
31 GPIO6
GPIO12 PWM0 32
33 GPIO13 PWM1
GND 34
35 GPIO19 PWM1
GPIO16 36
37 GPIO26
GPIO20 38
39 GND
GPIO21 40
Hover over a pin for details
3.3V Power
5V Power
Ground
GPIO
I2C
SPI
UART
PWM

Pin Functions Reference

Power Pins

3.3V Power (Pins 1, 17)

Regulated 3.3V output from the Pi's onboard regulator. Maximum current draw is approximately 50mA when shared with GPIO. Use for powering 3.3V sensors and logic-level devices.

Voltage: 3.3V ±5% Max Current: ~50mA

5V Power (Pins 2, 4)

Direct 5V from the USB power input (minus any voltage drop). Can supply more current for 5V devices like relays, motors, and displays. Current limited by your power supply.

Voltage: 5V (from PSU) Max Current: PSU dependent

Ground (Pins 6, 9, 14, 20, 25, 30, 34, 39)

Common ground reference for all circuits. Always connect the ground of external devices to one of these pins. Multiple ground pins allow for better current distribution.

8 Ground pins available Use nearest ground to reduce noise

I2C Bus (Inter-Integrated Circuit)

I2C is a two-wire serial protocol for connecting multiple devices using just two pins. Each device has a unique address (7-bit, 0x00-0x77). EdgeFlow supports up to 128 devices on a single bus.

Speed: 100kHz (Standard) / 400kHz (Fast) / 1MHz (Pi 5)
Max Devices: 128 (limited by addresses)
Pull-ups: Built-in 1.8kΩ to 3.3V
Pin GPIO Function Description
3 GPIO2 SDA (Data) Bidirectional data line. Connect to SDA on all I2C devices.
5 GPIO3 SCL (Clock) Clock line driven by master (Pi). Connect to SCL on all I2C devices.
Enable I2C & Scan for Devices
# Enable I2C interface
sudo raspi-config nonint do_i2c 0

# Install I2C tools
sudo apt install -y i2c-tools

# Scan for connected devices
sudo i2cdetect -y 1

# Example output shows device at 0x76 (BME280)
#      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
# 70: -- -- -- -- -- -- 76 --

SPI Bus (Serial Peripheral Interface)

SPI is a high-speed, full-duplex serial protocol. Unlike I2C, each device needs a separate chip select (CE) line. SPI is faster than I2C and ideal for high-bandwidth devices like displays and ADCs.

Speed: Up to 125MHz (typically 1-10MHz)
Mode: Full Duplex (simultaneous TX/RX)
Chip Selects: CE0, CE1 (can use any GPIO for more)
Pin GPIO Function Description
19 GPIO10 MOSI Master Out Slave In - Data from Pi to device
21 GPIO9 MISO Master In Slave Out - Data from device to Pi
23 GPIO11 SCLK Serial Clock - Clock signal from Pi
24 GPIO8 CE0 Chip Enable 0 - Select device 0 (active low)
26 GPIO7 CE1 Chip Enable 1 - Select device 1 (active low)
Enable SPI Interface
# Enable SPI interface
sudo raspi-config nonint do_spi 0

# Verify SPI devices are available
ls -la /dev/spidev*
# Should show: /dev/spidev0.0 and /dev/spidev0.1

UART (Serial Port)

UART provides asynchronous serial communication. Used for GPS modules, GSM modems, and serial sensors. The Pi has two UARTs: a full-featured PL011 and a mini UART.

Baud Rates: 300 to 4,000,000 bps
Common Rates: 9600, 115200 bps
Logic Level: 3.3V (NOT 5V tolerant!)
Pin GPIO Function Description
8 GPIO14 TXD Transmit Data - Connect to device RX
10 GPIO15 RXD Receive Data - Connect to device TX

⚠️ UART Voltage Warning

The Pi's UART operates at 3.3V logic levels. Connecting 5V serial devices directly will damage the Pi! Use a level shifter for 5V devices.

Enable Serial Port
# Enable serial port (disable login shell over serial)
sudo raspi-config nonint do_serial 2

# The serial port is available at:
# /dev/ttyAMA0 (Pi 4/5) or /dev/serial0 (symlink)

1-Wire Protocol

1-Wire is a single-wire protocol (plus ground) primarily used for DS18B20 temperature sensors. Multiple sensors can share the same data pin, each identified by a unique 64-bit ROM code.

Default Pin: GPIO4 (Pin 7)
Pull-up: 4.7kΩ to 3.3V required
Max Sensors: Practically ~10-20 on one bus
Pin GPIO Function Description
7 GPIO4 DATA 1-Wire data line (default, configurable)
Enable 1-Wire & Read Temperature
# Enable 1-Wire interface
sudo raspi-config nonint do_onewire 0

# Or add to /boot/config.txt:
# dtoverlay=w1-gpio

# After reboot, sensors appear in:
ls /sys/bus/w1/devices/
# Example: 28-00000xxxxxxx

# Read temperature
cat /sys/bus/w1/devices/28-*/temperature
# Returns temperature in millidegrees (25125 = 25.125°C)

PWM (Pulse Width Modulation)

PWM generates variable duty-cycle signals for controlling LED brightness, servo motors, and motor speed. The Pi has 2 hardware PWM channels, each available on multiple pins.

Hardware Channels: 2 (PWM0, PWM1)
Resolution: Up to 12-bit (4096 levels)
Frequency: Configurable, typically 1kHz-100kHz
Pin GPIO PWM Channel Notes
12 GPIO18 PWM0 Also used for PCM/I2S audio clock
32 GPIO12 PWM0 Alternative pin for PWM channel 0
33 GPIO13 PWM1 Hardware PWM channel 1
35 GPIO19 PWM1 Alternative pin for PWM channel 1

💡 Software PWM

EdgeFlow can generate software PWM on any GPIO pin, but hardware PWM is more accurate and doesn't consume CPU. Use hardware PWM pins when precision timing is required (servos, precise dimming).

GPIO Electrical Specifications

Voltage Levels

Logic High (Output)3.3V
Logic Low (Output)0V
Input High Threshold≥1.3V
Input Low Threshold≤0.8V
Maximum Input Voltage3.3V
⚠️ GPIO pins are NOT 5V tolerant!

Current Limits

Max per GPIO pin16mA
Recommended per pin8mA
Total GPIO current50mA
3.3V rail max~50mA
5V rail maxPSU limited
Use transistors/MOSFETs for high-current loads!

Internal Pull Resistors

Pull-up resistance~50kΩ
Pull-down resistance~50kΩ
I2C pull-ups (GPIO2/3)1.8kΩ

Internal pulls are weak. Use external 4.7kΩ-10kΩ resistors for reliable operation.

Timing (Pi 5)

GPIO toggle rate~30MHz
I2C fast mode1MHz
SPI max clock125MHz
PWM resolution12-bit

Pi 5 GPIO is ~10× faster than Pi 4 due to RP1 chip.

Common Wiring Diagrams

🌡️ DS18B20 Temperature Sensor

DS18B20          Pi
───────         ────
 GND ─────────── GND (Pin 6)
 VDD ─────────── 3V3 (Pin 1)
 DQ  ──┬──────── GPIO4 (Pin 7)
       │
      4.7kΩ
       │
      3V3
        

4.7kΩ pull-up resistor required between DQ and 3.3V

📊 BME280 (I2C Mode)

BME280           Pi
───────         ────
 VIN ─────────── 3V3 (Pin 1)
 GND ─────────── GND (Pin 6)
 SCL ─────────── GPIO3 (Pin 5)
 SDA ─────────── GPIO2 (Pin 3)
        

I2C address: 0x76 (or 0x77 if SDO pin is high)

📟 OLED SSD1306 Display

SSD1306          Pi
───────         ────
 VCC ─────────── 3V3 (Pin 1)
 GND ─────────── GND (Pin 6)
 SCL ─────────── GPIO3 (Pin 5)
 SDA ─────────── GPIO2 (Pin 3)
        

I2C address: 0x3C (or 0x3D)

🔘 Button with Pull-up

Button           Pi
───────         ────
 One leg ──┬──── GPIO17 (Pin 11)
           │
         10kΩ
           │
          3V3

 Other leg ───── GND (Pin 6)
        

Button press reads as LOW. Can use internal pull-up instead.

💡 LED with Resistor

LED              Pi
───────         ────
 Anode (+) ─330Ω─ GPIO18 (Pin 12)
 Cathode (-) ──── GND (Pin 6)
        

330Ω for standard LED at ~10mA. Adjust for different LEDs.

🔌 Relay Module

Relay Module     Pi
───────         ────
 VCC ─────────── 5V (Pin 2)
 GND ─────────── GND (Pin 6)
 IN  ─────────── GPIO23 (Pin 16)
        

Most relay modules are active-low (LOW = relay ON)

EdgeFlow GPIO Nodes

EdgeFlow provides dedicated nodes for GPIO operations:

IN

GPIO Input

Read digital input state (HIGH/LOW). Supports pull-up/pull-down configuration and edge detection (rising, falling, both).

OUT

GPIO Output

Set digital output state. Control LEDs, relays, and other digital devices. Supports initial state configuration.

PWM

PWM Output

Generate PWM signals for LED dimming, servo control, and motor speed. Configurable frequency and duty cycle (0-255).

I2C

I2C Sensors

Built-in support for BME280, BH1750, AHT20, SHT3x, ADS1015, and more. Auto-detection and configuration.

Raspberry Pi 5 GPIO Differences

🆕 Pi 5 RP1 Chip Changes

Raspberry Pi 5 uses a new RP1 I/O controller chip with some differences from earlier models:

  • GPIO Chip: Uses gpiochip4 instead of gpiochip0
  • Speed: ~10× faster GPIO toggle rate (~30MHz vs ~3MHz)
  • I2C: Supports up to 1MHz fast mode plus
  • Pinctrl: More flexible alternate function mapping

EdgeFlow automatically detects your Pi model and configures the correct GPIO interface.

Troubleshooting

❌ GPIO permission denied

sudo usermod -a -G gpio $USER
# Log out and back in

❌ I2C device not detected

# Check wiring, then scan:
sudo i2cdetect -y 1
# Check if I2C is enabled:
ls /dev/i2c*

❌ SPI not working

# Check if SPI is enabled:
ls /dev/spidev*
# Enable if needed:
sudo raspi-config nonint do_spi 0

❌ 1-Wire sensor not found

# Check 1-Wire devices:
ls /sys/bus/w1/devices/
# Should show 28-xxxx for DS18B20