Raspberry Pi Original Overview

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.

Key Specifications

Raspberry Pi 1 Model B

Raspberry Pi 1 Model B board top view

Image: Harrison Fornasier / Wikimedia Commons, CC BY‑SA 4.0 :contentReference[oaicite:1]{index=1}

Raspberry Pi 1 Model B+

Raspberry Pi 1 Model B+ top view

Image: Lucasbosch / Wikimedia Commons, CC BY‑SA (per file) :contentReference[oaicite:3]{index=3}

Operating System

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:

Legacy and Impact

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.

Related Links

Original Raspberry Pi Compute Module Overview

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.

Key Specifications

Embedded Image of the Original Raspberry Pi Compute Module

Original Raspberry Pi Compute Module

Original Raspberry Pi Compute Module

Key Features

Applications

Carrier Board Options

How to Get Started

Related Links

I2C on Raspberry Pi

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.

Enabling I2C on Raspberry Pi

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-tools

Connecting I2C Devices

Raspberry 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 1

This will show a map of I2C devices connected to your Raspberry Pi.

Using I2C with Python

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 on Raspberry Pi

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.

Enabling SPI on Raspberry Pi

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 spi

SPI Pinout

SPI communication on the Raspberry Pi uses the following pins:

Using SPI with Python

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)
        

Timers & PWM on Raspberry Pi

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.

Timers on Raspberry Pi

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 on Raspberry Pi

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 on Raspberry Pi

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.

Enabling Serial on Raspberry Pi

By default, the serial interface on the Raspberry Pi is disabled. To enable it:

Using Serial with Python

The `pyserial` library is commonly used for serial communication in Python. To install it, run:

sudo apt-get install python3-serial

Here'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)
        

GPIO (General Purpose Input/Output) on Raspberry Pi

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.

Configuring GPIO Pins

Example Code to Blink an LED


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)

GPIO Interrupts on Raspberry Pi

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.

What are GPIO Interrupts?

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.

GPIO Interrupt Types

Raspberry Pi supports several types of GPIO interrupts:

Setting Up GPIO Interrupts on Raspberry Pi

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.

Step-by-Step Setup

  1. First, ensure that you have the WiringPilibrary installed, or use the RPi.GPIOlibrary (depending on your preferences and Raspberry Pi model).
  2. In your Python or C program, configure the GPIO pin as an input pin.
  3. Set up the interrupt on the input pin to listen for a rising edge, falling edge, or both edges.
  4. Write the interrupt handler function (ISR) to handle the event triggered by the interrupt.
  5. Enable the interrupt to listen for changes in the GPIO pin state.

Python Example Code

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.

Using Interrupts for Debouncing

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.

Debouncing Example

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.

Using Multiple GPIO Interrupts

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.

Example for Multiple GPIO Interrupts

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.

GPIO Interrupt Limitations

While GPIO interrupts are a powerful tool, there are some limitations:

Conclusion

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.

Camera Support on Raspberry Pi Models

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.

Raspberry Pi Zero

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.

Raspberry Pi Model B (Original)

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.

Raspberry Pi 2 Model B

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.

Raspberry Pi 3 Model B and B+

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.

Raspberry Pi 4 Model B

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.

Raspberry Pi 5 (Upcoming)

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.

Camera Software and Commands

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.

Video Connectors (Non-HDMI) on Raspberry Pi Models

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.

Raspberry Pi Zero

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.

Raspberry Pi Model B (Original)

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.

Raspberry Pi 2 Model B

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.

Raspberry Pi 3 Model B and B+

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.

Raspberry Pi 4 Model B

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.

Raspberry Pi 5 (Upcoming)

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.

Audio Connectors on Raspberry Pi Models

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.

Raspberry Pi Zero

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.

Raspberry Pi Model B (Original)

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.

Raspberry Pi 2 Model B

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.

Raspberry Pi 3 Model B and B+

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.

Raspberry Pi 4 Model B

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.

Raspberry Pi 5 (Upcoming)

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.

USB on Raspberry Pi

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.

USB Versions

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.

Power Supply via USB

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.

USB OTG (On-The-Go)

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.

Configuring USB Devices

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.

Example: Using a USB WiFi Adapter

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
    

USB Troubleshooting

If you are experiencing issues with a USB device, check the following:

Useful USB Commands

Installing Operating Systems on Raspberry Pi SD Cards

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.

Installing Linux OS 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.

Windows Host

  1. Download the Raspberry Pi Imager: Go to the official Raspberry Pi website and download the Raspberry Pi Imager for Windows.
  2. Install the Imager: Run the downloaded installer and follow the on-screen instructions to install the Raspberry Pi Imager on your Windows computer.
  3. Insert the SD Card: Insert the SD card (at least 8GB recommended) into your Windows PC using an SD card reader.
  4. Open Raspberry Pi Imager: Launch the Raspberry Pi Imager application.
  5. Select the OS: In the Imager, select the desired OS from the list of available operating systems, such as Raspberry Pi OS or Ubuntu.
  6. Select the SD Card: Choose your SD card from the list of available devices.
  7. Write the OS: Click the "Write" button to begin writing the OS to the SD card. The process may take several minutes.
  8. Finish and Eject: Once the writing process is complete, safely eject the SD card from your PC and insert it into your Raspberry Pi.

Linux Host

  1. Install Raspberry Pi Imager: On a Linux system, you can install Raspberry Pi Imager by running the following command in your terminal:
    isudo apt install rpi-imager
  2. Insert the SD Card: Insert the SD card (at least 8GB recommended) into your Linux PC using an SD card reader.
  3. Launch Raspberry Pi Imager: Once installed, run the following command to launch the Imager:
    irpi-imager
  4. Select the OS: Choose the operating system you want to install on the SD card, such as Raspberry Pi OS, Ubuntu, or others.
  5. Select the SD Card: Choose the SD card as the target device for the installation.
  6. Write the OS: Click "Write" to start installing the OS on the SD card. The process may take several minutes.
  7. Finish and Eject: Once complete, safely eject the SD card and insert it into the Raspberry Pi.

Installing Android on Raspberry Pi

Android 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:

Using an Image File (Windows and Linux)

  1. Download an Android Image: Download a compatible Android image from sources like KonstaKANG or AndroidPi.
  2. Write the Image to SD Card: Use a tool like Balena Etcher (available for both Windows and Linux) to write the downloaded Android image to the SD card.
  3. Insert the SD Card: Once the image is written, safely eject the SD card from your computer and insert it into the Raspberry Pi.
  4. Boot the Raspberry Pi: Power up the Raspberry Pi. The device should boot into Android, and you can set it up as you would on any Android device.

Installing Ultibo Programs on Raspberry Pi

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.

Ultibo Pascal IDE Overview

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.

Key Features of Ultibo Pascal IDE:

Steps to Install Ultibo on Raspberry Pi

  1. Download Ultibo Image: Go to the official Ultibo website and download the latest Ultibo image compatible with your Raspberry Pi model.
  2. Write the Image to SD Card: Use Balena Etcher or Raspberry Pi Imager to write the Ultibo image onto the SD card.
  3. Install Ultibo IDE: Download and install the Ultibo Pascal IDE on your host computer. The IDE is available for Windows, macOS, and Linux.
  4. Develop and Compile Programs: Using the Ultibo Pascal IDE, develop your program in Pascal. Once the code is written, compile it into a binary file that can be executed directly on the Raspberry Pi.
  5. Load Ultibo Programs: Transfer the compiled binary to the SD card and insert it into your Raspberry Pi. Upon booting, the Raspberry Pi will execute the program without the need for an operating system to manage the hardware.
  6. Run on Raspberry Pi: Once the SD card is inserted, power up the Raspberry Pi. Your program will run directly on the hardware, and you’ll be able to interact with GPIO pins, peripherals, and sensors.

Examples of Ultibo Projects

Ultibo can be used for a variety of applications where low-level access to hardware is necessary. Here are a few examples:

Other Non-Linux OS: Real-Time Operating Systems (RTOS)

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.