Raspberry Pi
Raspberry Pi hardware interfacing, GPIO, and embedded Linux questions.
The Raspberry Pi is a family of single-board computers running embedded Linux, widely used in prototyping, education, industrial gateways, and applications requiring more compute or richer OS services than a bare microcontroller can provide. From sensor data logging to computer vision pipelines, the Raspberry Pi bridges the gap between traditional embedded systems and full Linux-based applications.
What Is the Raspberry Pi?
The Raspberry Pi is a single-board computer featuring:
- ARM application processor — Cortex-A series (A53, A72, or A76) running at 1–2.4 GHz, running Raspberry Pi OS (Debian-based Linux) or other Linux distributions.
- GPIO header — a 40-pin header providing digital I/O, SPI, I2C, UART, PWM, and 3.3 V/5 V power. The maximum GPIO source/sink current is typically 16 mA per pin and 50 mA total for the 3.3 V supply — level shifting is required for 5 V peripherals.
- Interfaces — USB, Ethernet, HDMI, camera (CSI), and display (DSI) on the Compute Module and larger boards.
- Compute Module — the CM4 and CM5 are the production-oriented variants with eMMC storage, no on-board connectors, and a board-to-board connector intended for custom carrier boards in products.
This subtopic is part of the Embedded Systems topic.
Why Use a Raspberry Pi?
The Raspberry Pi is appropriate when the application requires:
- Full Linux OS — package management, Python ecosystem, web servers, databases, and SSH remote access.
- Significant compute — computer vision (OpenCV, TensorFlow Lite), audio processing, or running a web server alongside the embedded application.
- Rich I/O — USB host (USB cameras, storage), Ethernet, HDMI video output.
- Rapid prototyping — the Raspberry Pi ecosystem has extensive pre-built libraries for sensors, displays, and communication modules, enabling fast prototyping without deep hardware knowledge.
For applications where power consumption, real-time response, or component cost are the primary constraints, a bare microcontroller (STM32, nRF, ESP32) is usually the better choice.
Key Concepts
- GPIO (General Purpose Input/Output) — the Raspberry Pi's digital I/O pins, 3.3 V logic level. Input pins must not exceed 3.3 V; 5 V signals require a level shifter.
- Device tree — Linux's hardware description mechanism. On the Raspberry Pi, device tree overlays (in
/boot/config.txt) enable and configure GPIO functions, SPI, I2C, UART, PWM, and other peripherals. - I2C on the Raspberry Pi — I2C-1 is the standard user-accessible I2C bus (pins GPIO2/SDA1, GPIO3/SCL1 on the 40-pin header). The
raspi-configtool enables it; thei2c-toolspackage (i2cdetect) confirms device presence. - SPI on the Raspberry Pi — SPI0 and SPI1 are available on the 40-pin header. Enable via
/boot/config.txt; thespidevkernel module provides user-space access. - Compute Module (CM4/CM5) — the production-ready variant with eMMC, no USB-A or HDMI ports. Designed for integration into a custom carrier board. Runs the same software as the Pi 4/5.
- Real-time limitations — Linux on the Raspberry Pi is not a real-time OS. GPIO toggling has timing jitter of microseconds to tens of microseconds. For microsecond-or-better real-time requirements, use a co-processor (STM32, RP2040) alongside the Pi.
Common Tools and Software
- Raspberry Pi Imager — the official tool for writing Raspberry Pi OS (and other supported OS images) to SD card or eMMC. Supports pre-configuring Wi-Fi, SSH, hostname, and user credentials in the image before first boot.
- raspi-config — the Raspberry Pi configuration utility (terminal-based); enables SPI, I2C, UART, and other interfaces; sets locale, hostname, and SSH. Available on all Raspberry Pi OS variants.
- GPIO libraries — RPi.GPIO (Python, classic), gpiozero (Python, higher-level abstraction), lgpio (Python, newer, supports Pi 5), WiringPi (C, deprecated). For C/C++ applications, the
bcm2835library provides direct BCM GPIO access. - I2C debug tools —
i2c-toolspackage (i2cdetect -y 1to scan the I2C-1 bus and confirm device presence),i2cget/i2csetfor reading and writing I2C registers from the command line. - Device tree overlays — peripheral configuration on Raspberry Pi is managed through device tree overlays in
/boot/firmware/config.txt(Pi 4/5 and CM4/CM5). Overlays enable SPI, I2C, UART, PCM, PWM, and hardware-specific peripherals.
Common Mistakes
- Connecting 5 V signals directly to GPIO — Raspberry Pi GPIO pins are strictly 3.3 V logic. Applying 5 V to a GPIO input pin exceeds the BCM SoC's absolute maximum input voltage and can permanently damage the pin. Use a bidirectional level shifter (TXB0108, MOSFET-based I2C level shifter, or dedicated level shifter IC) between 5 V peripherals and the Pi's GPIO. The 5 V header pins are power outputs only — they have no protection circuitry.
- Expecting real-time GPIO behaviour from Linux — the Raspberry Pi runs a standard Linux kernel; GPIO toggling timing has jitter of microseconds to tens of microseconds from scheduler and interrupt latency. For timing-critical applications (stepper motor stepping, precise PWM, sub-millisecond response), use a co-processor (RP2040, STM32, or similar) alongside the Pi, not GPIO bit-banging from Linux userspace.
- Using SD card storage for write-intensive applications — SD cards have limited write endurance. Applications that write frequently (logging, database writes, frequent system updates) will wear out an SD card in months. Use the Compute Module with eMMC storage, or configure the Pi to run the root filesystem from a USB SSD, for write-intensive production deployments.
- Not validating the power supply for full-load operation — the Raspberry Pi 4 and 5 can draw 3–5 A at full CPU + peripheral load. A supply that appears to work at idle may cause undervoltage (lightning bolt icon, throttled CPU) under load, causing instability. Use a quality 5.1 V power supply rated to the Pi's specifications, not a generic USB charger.
- Designing with the standard Raspberry Pi board for a production product — the standard Pi 4B, 5B, and Zero boards are not designed for long-term product integration (single-source supply, SD card, USB-A and HDMI ports that waste enclosure space). The Compute Module CM4/CM5 is the production-appropriate form factor.
Common Questions
Can I use 5 V sensors directly with the Raspberry Pi GPIO?
No. Raspberry Pi GPIO pins are 3.3 V logic. Connecting 5 V signals directly will damage the GPIO pins over time and may immediately damage the SoC. Use a bidirectional level shifter (such as the TXB0108 or a MOSFET-based bidirectional shifter for I2C) between 5 V peripherals and the Pi's GPIO. The 5 V pins on the header are power outputs only — they come directly from the USB supply or the 5V input and have no protection.
What is the difference between the Raspberry Pi Model B and Compute Module?
The Raspberry Pi Model B (and Zero, 3B+, 4B, 5B, etc.) are complete boards with USB, Ethernet, HDMI, and SD card directly on the board — ideal for prototyping and development. The Compute Module (CM4, CM5) is a bare SoM (System on Module) with eMMC storage and a board-to-board connector; it is designed to be integrated into a custom carrier board for production products. The CM provides more GPIO, the ability to design a custom form factor, and removes unnecessary ports (USB-A, HDMI) that waste board area in embedded applications.
Is the Raspberry Pi suitable for production hardware products?
The Raspberry Pi CM4/CM5 (Compute Module) is designed for production use — it has a defined supply chain, a long production commitment from the Raspberry Pi Foundation, and eMMC storage (more reliable than SD card). The standard development boards (Pi 4B, Pi 5) are less suitable for production due to SD card reliability and single-source supply constraints. Zeus Design builds embedded Linux applications and custom carrier boards for Raspberry Pi Compute Module based products.
Knowledge Base
Platform Selection
- Raspberry Pi Models Compared: Pi 5, Pi 4, CM4, Zero 2W, and Pico — which Raspberry Pi model to choose: SBC vs microcontroller device classes, Pi 5/4/Zero 2W/CM4 side-by-side, Pico and Pico 2 as MCU alternatives, and model selection by application type
- Raspberry Pi vs Microcontroller: When Should You Choose Each? — decision guide covering real-time requirements, power consumption, compute needs, boot time, cost, and when the hybrid Pi + MCU co-processor pattern is the right architecture
- Should You Use the Raspberry Pi CM4 in a Product? — CM4 vs standard Pi dev boards; DF40 carrier board design requirements; eMMC storage strategy and write-reduction; rpiboot flashing; OS choices for production; RCM certification scope for CM4-based products
- Real-Time Control on Raspberry Pi: PREEMPT-RT and the Co-Processor Pattern — Linux scheduler jitter explained; when PREEMPT-RT is sufficient; RP2040 vs STM32 as co-processor; UART/SPI interface design; bare-metal vs RTOS co-processor firmware; watchdog and OTA update considerations
GPIO Interfacing
- How to Interface Sensors and Peripherals with Raspberry Pi GPIO — Pi-specific GPIO guide: 3.3 V electrical constraints, level shifting for 5 V peripherals, enabling I2C/SPI/UART/PWM via device tree overlays, i2cdetect, lgpio and gpiozero APIs, CM4 carrier board pull-up requirements
- How Do GPIO Pins Work? — foundational GPIO concepts (push-pull, open-drain, pull resistors, alternate functions, interrupts) applicable to the Raspberry Pi's BCM GPIO
Communication Protocols
Protocols used with Raspberry Pi peripherals are covered in the Communications topic:
- What Is I2C? — I2C protocol; directly applicable to Raspberry Pi sensor interfacing
- What Is SPI? — SPI protocol; used for displays, ADCs, and other high-speed peripherals
- What Is UART? — UART; used for serial console, GPS modules, and other serial peripherals
Debugging and Testing
- How Do You Use a Multimeter for Electronics Work? — essential for verifying GPIO voltages and checking level shifters before connecting peripherals
Forum Discussions
- CM4 on custom carrier board won't enter USB boot mode — rpiboot not detecting it — debugging a CM4 that won't enumerate as a USB device: diagnosing nBOOT_ENABLE miswiring from current draw, confirming USB enumeration on Windows and Linux, and verifying nRUN pull-up