The original Raspberry Pi, launched in 2012, was the first model in the Raspberry Pi series. Designed to promote computer science education, it provided an affordable, compact, and low-power computing platform.
Image: Harrison Fornasier / Wikimedia Commons, CC BY‑SA 4.0 :contentReference[oaicite:1]{index=1}
More info: Raspberry Pi 1 Model B – Official Site
Image: Lucasbosch / Wikimedia Commons, CC BY‑SA (per file) :contentReference[oaicite:3]{index=3}
More info: Raspberry Pi 1 Model B+ – Official Site
The original Raspberry Pi runs a variety of Linux distributions, with Raspbian (now called Raspberry Pi OS) being the most popular. Other compatible OS options include:
The original Raspberry Pi paved the way for modern single-board computers (SBCs) and has been widely used in education, DIY projects, robotics, and embedded applications. Its low cost and flexibility have made it a popular choice among hobbyists and developers worldwide.
The Raspberry Pi Compute Module is designed for embedded and industrial applications, offering the processing power of the original Raspberry Pi Model B in a more compact and flexible form. It was specifically developed for users who require a small form factor and need to integrate the Raspberry Pi’s capabilities into custom hardware or larger systems.
Original Raspberry Pi Compute Module
I2C (Inter-Integrated Circuit) is a popular communication protocol for connecting low-speed devices like sensors, displays, and EEPROMs. The Raspberry Pi provides native support for I2C communication, which can be easily enabled and used for a variety of projects.
To use I2C on the Raspberry Pi, you'll first need to enable it in the Raspberry Pi's configuration settings. Follow these steps:
Once I2C is enabled, you can use the `i2c-tools` package to interact with I2C devices. To install it, run:
sudo apt-get install i2c-toolsRaspberry Pi has two I2C bus interfaces available. The default I2C bus is typically on the GPIO pins 3 (SDA) and 5 (SCL), but some models of Raspberry Pi have multiple I2C buses available. You can connect any I2C-enabled device to these pins, ensuring the correct voltage level and pull-up resistors are used.
After connecting an I2C device, you can detect it by running:
sudo i2cdetect -y 1This will show a map of I2C devices connected to your Raspberry Pi.
To communicate with I2C devices, you can use Python libraries such as `smbus`. Here's an example of how to use I2C with Python to read data from an I2C sensor:
import smbus
bus = smbus.SMBus(1) # Initialize I2C bus 1
address = 0x48 # I2C address of the device
# Reading a byte from a register (example)
data = bus.read_byte_data(address, 0x00)
print(data)
SPI (Serial Peripheral Interface) is a high-speed communication protocol used for connecting peripherals like sensors, displays, and memory chips. Raspberry Pi supports SPI communication, which is widely used in projects that require fast data transfer.
To enable SPI on the Raspberry Pi, you need to activate it through the Raspberry Pi configuration settings:
You can check if SPI is enabled by running:
lsmod | grep spiSPI communication on the Raspberry Pi uses the following pins:
The `spidev` library in Python allows you to communicate with SPI devices. Here's an example to communicate with an SPI device:
import spidev
spi = spidev.SpiDev()
spi.open(0, 0) # Open SPI bus 0, device 0
spi.max_speed_hz = 50000 # Set the clock speed
# Send and receive data
response = spi.xfer2([0x01, 0x02, 0x03])
print(response)
Raspberry Pi supports hardware timers and Pulse Width Modulation (PWM), which are essential for controlling motors, LEDs, and other components that require precise timing or modulation of signals.
The Raspberry Pi includes multiple timers for precise time management. These can be used for scheduling tasks or triggering events at regular intervals. Raspberry Pi OS provides access to these timers through libraries such as Python's `RPi.GPIO` or `pigpio`.
Timers can be used for a wide variety of applications, including:
PWM (Pulse Width Modulation) allows you to control the power supplied to devices like LEDs and motors. The Raspberry Pi supports PWM on several GPIO pins. Here's how to set it up:
Example code to generate PWM:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 1000) # Pin 18, frequency 1 kHz
pwm.start(50) # 50% duty cycle
# Change duty cycle after 5 seconds
pwm.ChangeDutyCycle(75)
Serial communication allows the Raspberry Pi to communicate with other devices like sensors, modules, and microcontrollers over a serial link. It is commonly used for debugging, interfacing with peripherals, or controlling other systems.
By default, the serial interface on the Raspberry Pi is disabled. To enable it:
The `pyserial` library is commonly used for serial communication in Python. To install it, run:
sudo apt-get install python3-serialHere's an example of using serial communication:
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600) # Open serial port at 9600 baud rate
# Write to serial
ser.write(b'Hello, Raspberry Pi!')
# Read from serial
data = ser.readline()
print(data)
The GPIO pins on the Raspberry Pi provide a versatile interface for connecting sensors, actuators, and other external components. With up to 40 GPIO pins available on various models, you can interact with the physical world, controlling LEDs, motors, buttons, and more.
The GPIO pins are connected to the Broadcom SoC (System on Chip), and their functionality can be configured in software. They can be used for digital input, digital output, PWM (Pulse Width Modulation), and communication protocols like I2C and SPI.
RPi.GPIOPython library to configure GPIO pins for input or output.gpiozeroPython library for higher-level control, such as controlling LEDs or buttons with minimal code.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
while True:
GPIO.output(17, GPIO.HIGH)
time.sleep(1)
GPIO.output(17, GPIO.LOW)
time.sleep(1)
Interrupts are a powerful feature of Raspberry Pi's GPIO (General Purpose Input/Output) pins, allowing the Pi to react to events such as changes in input signals. Interrupts are used for efficient event handling, enabling the Pi to perform actions only when needed, rather than constantly polling input pins. In this guide, we will explore how to use GPIO interrupts on a Raspberry Pi, including setup, use cases, and code examples.
A GPIO interrupt is an event that occurs when the state of a GPIO pin changes. When the interrupt condition is met (e.g., a rising edge, falling edge, or change in state), the Raspberry Pi triggers an interrupt service routine (ISR) to handle the event. This allows the system to react quickly to external stimuli, without needing to waste processor time checking the pin state constantly.
Raspberry Pi supports several types of GPIO interrupts:
To use GPIO interrupts, you must configure the GPIO pin in your code and specify the type of interrupt you want to listen for. You will then write an interrupt service routine (ISR) that will be called when the interrupt is triggered.
WiringPilibrary installed, or use the RPi.GPIOlibrary (depending on your preferences and Raspberry Pi model).Here is an example using the RPi.GPIOlibrary in Python to set up a GPIO interrupt on pin 17 for a rising edge trigger:
import RPi.GPIO as GPIO
import time
# Set the GPIO mode
GPIO.setmode(GPIO.BCM)
# Define the pin to listen for interrupts
pin = 17
# Setup the pin as an input with a pull-up resistor
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Define the callback function that will be triggered by the interrupt
def gpio_callback(channel):
print("Interrupt detected on GPIO pin", channel)
# Add an interrupt to GPIO pin 17, looking for a rising edge
GPIO.add_event_detect(pin, GPIO.RISING, callback=gpio_callback)
# Keep the program running to listen for interrupts
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Program terminated")
finally:
GPIO.cleanup()
In this example, when the GPIO pin 17 detects a rising edge (i.e., when it changes from LOW to HIGH), the interrupt service routine gpio_callbackis called, printing a message to the terminal.
Debouncing is a technique used to ensure that a signal is stable and doesn't generate multiple interrupts from a single event. Mechanical switches and buttons can generate noisy signals, causing multiple interrupts to be triggered. You can implement a debounce function in your interrupt callback to ensure that only one event is detected within a short period.
Here is an example of a debounced interrupt for a button press using the RPi.GPIOlibrary in Python:
import RPi.GPIO as GPIO
import time
# Set the GPIO mode
GPIO.setmode(GPIO.BCM)
# Define the pin for the button
button_pin = 17
# Setup the button pin as an input with a pull-up resistor
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Define a debounce delay (in seconds)
debounce_delay = 0.2
# Define the callback function with debounce
def gpio_callback(channel):
print("Button pressed!")
time.sleep(debounce_delay)
# Add an event detection on the button pin with a falling edge (button press)
GPIO.add_event_detect(button_pin, GPIO.FALLING, callback=gpio_callback, bouncetime=int(debounce_delay * 1000))
# Keep the program running to listen for interrupts
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Program terminated")
finally:
GPIO.cleanup()
In this example, the bouncetimeparameter is used to ignore any additional interrupts that occur within 200 milliseconds of the first one, effectively debouncing the button press.
You can set up interrupts on multiple GPIO pins simultaneously. This is useful for applications that need to respond to events from several sources, such as buttons, sensors, or other inputs.
Here's an example where we set up interrupts on two GPIO pins (17 and 18) for a rising edge trigger:
import RPi.GPIO as GPIO
import time
# Set the GPIO mode
GPIO.setmode(GPIO.BCM)
# Define pins for input
pin1 = 17
pin2 = 18
# Setup the pins as inputs with pull-up resistors
GPIO.setup(pin1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Define the callback function for pin interrupts
def gpio_callback(channel):
print(f"Interrupt detected on GPIO pin {channel}")
# Add events for multiple pins
GPIO.add_event_detect(pin1, GPIO.RISING, callback=gpio_callback)
GPIO.add_event_detect(pin2, GPIO.RISING, callback=gpio_callback)
# Keep the program running to listen for interrupts
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Program terminated")
finally:
GPIO.cleanup()
In this example, both GPIO pins (17 and 18) are configured to trigger an interrupt on a rising edge, and the callback function is triggered for each pin when the event occurs.
While GPIO interrupts are a powerful tool, there are some limitations:
GPIO interrupts are an essential tool for handling real-time events on a Raspberry Pi, allowing it to respond quickly and efficiently to changes in input signals. With proper setup, interrupts can be used to create responsive systems for a variety of applications, such as monitoring sensors, buttons, or communication signals.
The Raspberry Pi models support various camera modules through the **CSI (Camera Serial Interface)** port. Below is a description of the camera compatibility for each model.
The Raspberry Pi Zero supports the official Raspberry Pi camera modules through its **CSI** interface. The camera can be connected using a small ribbon cable. The Zero uses a mini version of the standard CSI connector found on other models.
The original Raspberry Pi Model B (rev 1 and rev 2) supports the **CSI** interface for connecting a camera. It was the first model to introduce camera support, although the interface was relatively new at the time.
The Raspberry Pi 2 Model B also supports the **CSI** interface for camera connections, similar to the original Model B, but with improved processing power for handling higher resolution and more demanding camera applications.
The Raspberry Pi 3 Model B and B+ continue to support the **CSI** interface, and the improved performance makes it suitable for higher frame rates, video streaming, and more advanced camera applications.
The Raspberry Pi 4 Model B supports the **CSI** interface as well, and with the increased performance of the 4GB/8GB RAM variants, it is ideal for intensive camera-based projects, such as high-quality video capture, surveillance, and machine vision.
The Raspberry Pi 5 (when released) is expected to continue supporting the **CSI** interface for camera connections, with potential improvements to the bandwidth and performance for high-end camera applications, including 4K video capture and machine vision projects.
On all models, the camera interface is supported by the raspistill and raspivid tools, which allow you to capture images and record video. These tools are pre-installed on Raspbian OS.
raspistill -o image.jpgThis command captures an image and saves it as "image.jpg".
raspivid -o video.h264 -t 10000This command records a 10-second video and saves it as "video.h264".
sudo raspi-configThis command opens the configuration tool. In the "Interface Options" section, select "Camera" to enable the camera interface.
Raspberry Pi models support video output through various interfaces, including the composite video connector and the CSI interface for cameras. While HDMI is the most commonly used video output, several models also feature alternative video outputs for different use cases.
The Raspberry Pi Zero does not have an official composite video jack. Video output is available through HDMI or via the GPIO pins using additional adapters or HATs.
The original Raspberry Pi Model B (rev 1 and rev 2) includes a 3.5mm jack that outputs both analog audio and composite video. This allows you to connect the Pi directly to older TVs or monitors with composite input.
The Raspberry Pi 2 Model B also features a 3.5mm jack for composite video output, along with analog audio. Like the original Model B, the Pi 2 offers this composite video output for older display devices.
The Raspberry Pi 3 Model B and B+ maintain the 3.5mm jack for composite video and audio output. Additionally, these models support HDMI for digital video and audio.
The Raspberry Pi 4 Model B has the standard 3.5mm jack for composite video and analog audio output, in addition to HDMI. The Pi 4 also supports 4K HDMI video output, though composite video is still available for legacy displays.
The Raspberry Pi 5 is expected to continue offering the 3.5mm jack for composite video and audio output, while also supporting digital video via HDMI. Future enhancements to video output might include higher-resolution video support for legacy systems.
Raspberry Pi models with audio output support 3.5mm audio jacks or HDMI audio through adapters. The audio connectors vary depending on the model, with some models featuring a dedicated audio jack, while others rely on HDMI or other digital interfaces.
The Raspberry Pi Zero does not have a dedicated 3.5mm audio jack. Audio is available through the HDMI interface or via a GPIO pin with the help of a DAC (digital-to-analog converter) HAT or external module.
The Raspberry Pi Model B (both rev 1 and rev 2) features a 3.5mm audio jack for analog audio output. It supports both audio and composite video output through this jack.
The Raspberry Pi 2 Model B also features a 3.5mm audio jack for analog audio output, along with composite video on the same jack. Audio is sent via the HDMI interface as well, offering digital audio output when using HDMI.
The Raspberry Pi 3 Model B and B+ continue to offer the 3.5mm audio jack for analog audio, in addition to the HDMI audio output. These models have improved processing power, which allows for better handling of digital audio via HDMI.
The Raspberry Pi 4 Model B features a 3.5mm audio jack for analog audio output and offers digital audio through the HDMI interface. The audio quality is improved on the Pi 4, supporting better digital audio output when using HDMI.
The Raspberry Pi 5 (when released) is expected to continue offering the 3.5mm audio jack for analog output. It will also support digital audio through the HDMI interface, with possible improvements to audio quality and formats.
The Raspberry Pi features several USB ports that allow you to connect a variety of peripherals, such as keyboards, mice, storage devices, and networking adapters. The USB interface is based on the Universal Serial Bus (USB) standard, which provides data transfer and power to connected devices.
Raspberry Pi models support different USB versions, depending on the hardware revision. Most models come with USB 2.0 ports, though newer models such as the Raspberry Pi 4 offer USB 3.0 ports as well, enabling faster data transfer rates.
Some Raspberry Pi models can power external devices through the USB ports. For instance, you can power a USB keyboard, mouse, or even a small external hard drive. However, the power provided through the USB port is limited, and for devices with high power consumption, an external power supply might be necessary.
On Raspberry Pi models with micro-USB ports (such as the Raspberry Pi Zero and Raspberry Pi 3), the USB port supports OTG, which allows the Pi to act as a USB host or a device. This feature is useful for creating USB gadgets or connecting the Raspberry Pi to other devices like a smartphone or computer.
To use a USB device with the Raspberry Pi, simply plug it into the USB port. Most common devices like keyboards, mice, and storage devices should work out of the box. To interact with more specialized USB peripherals, you may need to install drivers or use specific tools.
If you want to use a USB WiFi adapter with your Raspberry Pi, plug the device into a USB port, and ensure that the necessary drivers are installed. For most USB WiFi adapters, the required drivers are included in the Raspberry Pi's operating system (Raspberry Pi OS).
sudo apt-get update
sudo apt-get install firmware-ralink
If you are experiencing issues with a USB device, check the following:
dmesgcommand to view system messages and check for errors related to USB devices.lsusb: Lists all connected USB devices.dmesg | grep usb: Shows detailed logs related to USB devices.Raspberry Pi computers support a wide range of operating systems, including Linux distributions, Android, Ultibo, and various real-time operating systems (RTOS). This page covers the installation of these OSes onto SD cards for Raspberry Pi, with detailed instructions for Windows and Linux hosts. It also provides detailed information about Ultibo, a bare-metal operating system that allows you to write programs in Pascal directly on Raspberry Pi.
Linux is the most popular operating system family for Raspberry Pi devices. Raspberry Pi OS (formerly Raspbian) is the official OS, but there are many other distributions like Ubuntu, Manjaro, and others. Below are the instructions for installing Linux OS onto the Raspberry Pi SD card using either a Windows or Linux host.
isudo apt install rpi-imagerirpi-imagerAndroid is another operating system available for Raspberry Pi, though it may not be as commonly used as Linux-based OSes. Android for Raspberry Pi allows users to run Android apps and use the Raspberry Pi as an Android device. Here's how to install Android on your Raspberry Pi SD card:
Ultibo is a unique operating system designed for bare-metal programming on the Raspberry Pi. It allows developers to write low-level programs in Pascal, offering fine control over hardware without the overhead of a full operating system like Linux. The Ultibo Pascal IDE provides an efficient development environment that allows you to write programs and directly run them on Raspberry Pi without the need for an operating system.
The Ultibo Pascal IDE is a cross-platform integrated development environment designed specifically for Ultibo. It is tailored for bare-metal development on the Raspberry Pi, which means your code interacts directly with the hardware without an operating system in between. The Ultibo IDE supports creating programs in Pascal and compiling them for various Raspberry Pi models.
Ultibo can be used for a variety of applications where low-level access to hardware is necessary. Here are a few examples:
Several RTOS options are available for Raspberry Pi. These operating systems provide real-time performance, which is ideal for applications that require precise timing, fast responses, and minimal delays. Some of the most popular RTOS options for Raspberry Pi include:
Raspberry Pi is a trademark of Raspberry Pi Ltd.