Comprehensive Guide to the Pin Diagram of Raspberry Pi 5: Understanding GPIO Pins and Their Functions
Oct 22, 2024
GPIO on Raspberry Pi 5
General Purpose Input/Output (GPIO) pins are physical connectors on the Raspberry Pi that allow it to interact with external electronic components such as sensors, LEDs, motors, and other devices. These pins can be programmed to function as either inputs, receiving data from external sources (e.g., sensors), or outputs, sending signals to control external devices (e.g., turning on an LED or activating a motor).
Importance
Learning and Experimentation: For educational purposes, learning how to use GPIO pins is fundamental for understanding electronics, programming, and embedded systems, making it a practical tool for STEM education.
Interfacing with Sensors and Actuators: GPIO pins allow the Raspberry Pi to gather input from sensors (e.g., temperature, motion, light) and send commands to actuators (e.g., motors, lights, relays), making it essential for automation, robotics, and IoT applications.
GPIO essentially allows the Raspberry Pi to function as an embedded system, bridging the gap between software and hardware.
Types of GPIO Pins on Raspberry Pi 5
The Raspberry Pi 5 continues the legacy of providing versatile General Purpose Input/Output (GPIO) pins, which allow it to interact with various electronic components.
Similar to previous models, the Raspberry Pi 5 uses a 40-pin GPIO header, but with improvements in performance and functionality.
Numbering: Two Schemes Used on Raspberry Pi GPIO Pins
When working with Raspberry Pi's GPIO pins, there are two main numbering schemes that can be used to refer to the pins:
Physical Pin Numbering (Board Numbering)
The physical pin numbering refers to the actual location of the pins on the 40-pin header of the Raspberry Pi, counting sequentially from Pin 1 (top left) to Pin 40 (bottom right). This numbering scheme is based purely on the physical layout of the pins.
- Example:
- Pin 1: 3.3V Power
- Pin 2: 5V Power
- Pin 6: Ground (GND)
- Pin 7: GPIO 4
Physical numbering is useful for wiring components when you’re following a visual guide or schematic, as it reflects the physical position of the pins on the header.
BCM (Broadcom SOC Channel) Numbering
BCM numbering refers to the Broadcom chip-specific GPIO numbers assigned to each pin based on the Raspberry Pi's internal SOC (System on Chip). These GPIO numbers correspond to the actual functional channels on the Broadcom processor.
- Example:
- BCM GPIO 2: Pin 3 (used for I2C SDA).
- BCM GPIO 3: Pin 5 (used for I2C SCL).
- BCM GPIO 18: Pin 12 (used for PWM).
BCM numbering is typically used in software when writing scripts or programs in languages like Python (with libraries like `RPi.GPIO` or `gpiozero`). The Raspberry Pi’s internal code and libraries recognize pins by their BCM numbers rather than their physical layout.
The two numbering schemes exist to address different needs:
- Physical Pin Numbering: This is simple and intuitive when physically wiring components.
- BCM Numbering: This is more precise for programming, as it reflects the actual hardware configuration and functions tied to specific GPIO channels.
Example to Compare:
- Pin 3 (Physical): Corresponds to GPIO 2 in BCM numbering.
- Pin 5 (Physical): Corresponds to GPIO 3 in BCM numbering.
Power Pins
These pins supply power to external devices or circuits connected to the Raspberry Pi.
● 5V Pins (Pin 2 and Pin 4): Provide 5V directly from the Raspberry Pi’s power supply, useful for powering components like relays or higher-power devices.
● 3.3V Pins (Pin 1 and Pin 17): Deliver a regulated 3.3V, suitable for lower-power devices such as sensors.
● Ground (GND) Pins: These pins (Pin 6, 9, 14, 20, 25, 30, 34, 39) are essential for completing electrical circuits with external components.
Standard GPIO Pins
● Digital Input/Output: These pins can be programmed as either input or output, depending on the task. They can read signals from external devices (input) or send signals to control them (output).
● Example Use: We can read the state of a button (input) or control an LED (output).
GPIO pins on the Raspberry Pi 5 include pins like GPIO 2, GPIO 3, etc., and can be referred to by their BCM numbers or physical pin numbers.
UART Pins (Universal Asynchronous Receiver-Transmitter)
These pins are used for serial communication with other devices like microcontrollers or even other Raspberry Pi boards.
● TXD (Transmit): Pin 8 (BCM GPIO 14).
● RXD (Receive): Pin 10 (BCM GPIO 15).
Ideal for communication between the Raspberry Pi and another device using a serial protocol, such as a GPS module or a wireless communication chip.
I2C Pins (Inter-Integrated Circuit)
The I2C protocol is used for communication with multiple low-speed devices over two shared lines (clock and data).
● SDA (Data Line): Pin 3 (BCM GPIO 2).
● SCL (Clock Line): Pin 5 (BCM GPIO 3).
Frequently used to connect the Raspberry Pi to sensors like temperature, humidity, or pressure sensors.
SPI Pins (Serial Peripheral Interface)
SPI is a high-speed communication protocol often used to interface with sensors, displays, and SD cards.
● MOSI (Master Out Slave In): Pin 19 (BCM GPIO 10).
● MISO (Master In Slave Out): Pin 21 (BCM GPIO 9).
● SCLK (Serial Clock): Pin 23 (BCM GPIO 11).
● CE0 (Chip Enable 0): Pin 24 (BCM GPIO 8).
● CE1 (Chip Enable 1): Pin 26 (BCM GPIO 7).
Commonly used for high-speed data communication with devices like TFT displays or high-speed sensors.
PWM Pins (Pulse Width Modulation)
Pulse Width Modulation (PWM) is a technique used to control the speed of motors or dim LEDs by varying the duty cycle of the signal.
● PWM0: Pin 12 (BCM GPIO 18).
● PWM1: Pin 33 (BCM GPIO 13).
These pins are often used to control motor speed, LED brightness, or servos in robotics projects.
EEPROM Identification Pin
● ID_SD (Data): Pin 27 (BCM GPIO 0).
● ID_SC (Clock): Pin 28 (BCM GPIO 1).
These pins are used for identifying add-on boards via the EEPROM on HATs (Hardware Attached on Top), allowing the Raspberry Pi to automatically configure settings when an accessory board is attached.
Pinout Diagrams on Raspberry Pi 5
To get an overview of the Raspberry Pi GPIO pin layout directly from your Raspberry Pi, we can use the built-in pinout command. This is a simple command-line tool that displays a visual representation of the GPIO pins, their numbers, and functions.
Open the Terminal on your Raspberry Pi. And run:
pinout
We can visit https://pinout.xyz/ and get more information about specific GPIOs.
Safety Precautions When Using GPIO Pins on the Raspberry Pi
√ Avoid Connecting 5V to 3.3V GPIO Pins
The Raspberry Pi operates with a 3.3V logic level. Connecting a 5V signal to any of the GPIO pins can easily fry the internal circuits of the Raspberry Pi.
Always check the voltage level of the devices or sensors we connect. If needed, use a level shifter to convert 5V signals to 3.3V.
√ Limit Current Through GPIO Pins
The GPIO pins can only handle a limited amount of current (typically around 16mA per pin, with a total limit of 50mA across all GPIO pins).
Always use current-limiting resistors (e.g., 220Ω to 1kΩ) when connecting LEDs or other components to prevent drawing too much current, which could permanently damage the GPIO pins.
√ Beware of Short Circuits
A short circuit occurs when the current takes an unintended path, often bypassing the load (e.g., a resistor or sensor). This can cause excessive current to flow, leading to heat buildup and potential hardware damage.
√ Use Ground Properly
Every circuit needs a common ground (GND) to complete the circuit. Not connecting components to ground or incorrectly connecting the ground can result in malfunctioning circuits or even damage.
√ Avoid Hot-Swapping Components
Plugging and unplugging components while the Raspberry Pi is powered on (hot-swapping) can cause electrical surges or spikes, which can damage both the GPIO pins and the components.
√ Use a Voltage Divider or Logic Level Converter
When interfacing with devices that operate at higher voltages (e.g., 5V or 12V), we must ensure the Raspberry Pi’s 3.3V GPIO pins aren't exposed to higher voltage.
√ Avoid Drawing Too Much Power from the Raspberry Pi
Why: The Raspberry Pi’s power supply has limits, and drawing too much power from the 5V or 3.3V pins can cause instability, reboots, or damage to the board.
Conclusion
Understanding the pin diagram of the Raspberry Pi 5 is essential for maximizing the board’s potential in electronics projects. With the proper knowledge of GPIO pin types, numbering systems, and safety precautions, users can confidently connect a wide range of components and expand their Raspberry Pi’s functionality. Whether you're working with sensors, actuators, or communication protocols like UART, I2C, or SPI, mastering GPIO will unlock countless possibilities for automation, IoT, and robotics applications. Always prioritize safety to protect both your Raspberry Pi and the external devices you connect."
This summary reinforces the importance of understanding the GPIO pin diagram while encouraging further exploration.