0
0
Iot-protocolsHow-ToBeginner · 4 min read

How to Use Raspberry Pi Compute Module: Setup and Programming Guide

To use the Raspberry Pi Compute Module, first connect it to a compatible carrier board and power it up. Then, flash the OS image onto the module's eMMC storage using rpiboot tool, and program it like a regular Raspberry Pi using SSH or direct connection.
📐

Syntax

The Raspberry Pi Compute Module itself is hardware, so 'syntax' here means the basic steps to set it up and program it:

  • Connect: Attach the Compute Module to a carrier board that provides power, USB, HDMI, and GPIO access.
  • Flash OS: Use the rpiboot tool on your PC to boot the module into USB mass storage mode and flash the OS image to its eMMC.
  • Boot: Power the module and it will boot the installed OS like a normal Raspberry Pi.
  • Access: Connect via SSH or serial console to program and control the module.
bash
sudo apt install rpiboot
sudo rpiboot
# Then use Raspberry Pi Imager or dd to flash OS image to the module's eMMC
Output
Waiting for BCM2835/6/7/2711/2710/2837/2711 device Found device in USB boot mode Downloading boot files Boot files downloaded successfully
💻

Example

This example shows how to flash Raspberry Pi OS onto the Compute Module and run a simple Python script to blink an LED connected to a GPIO pin.

python
# Step 1: Flash OS using rpiboot and Raspberry Pi Imager
# Step 2: Boot the Compute Module and SSH into it

# Python code to blink an LED on GPIO 17
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)

try:
    while True:
        GPIO.output(17, GPIO.HIGH)
        time.sleep(1)
        GPIO.output(17, GPIO.LOW)
        time.sleep(1)
except KeyboardInterrupt:
    GPIO.cleanup()
Output
LED connected to GPIO 17 blinks on and off every second until stopped
⚠️

Common Pitfalls

Many beginners face these issues when using the Compute Module:

  • Incorrect carrier board connection: The module must be firmly and correctly seated on the carrier board.
  • Not using rpiboot properly: Without running rpiboot, the PC cannot access the module's eMMC for flashing.
  • Power supply problems: The module needs a stable 5V power supply; insufficient power causes boot failures.
  • Wrong OS image: Use Raspberry Pi OS images compatible with the Compute Module version.
bash
## Wrong way: Trying to flash OS without rpiboot
# This will fail because the module is not in USB boot mode

sudo dd if=raspios.img of=/dev/sdX bs=4M

## Right way: Use rpiboot first
sudo rpiboot
sudo dd if=raspios.img of=/dev/sdX bs=4M
📊

Quick Reference

StepDescriptionCommand/Notes
1Connect Compute Module to carrier boardEnsure proper seating and power connection
2Run rpiboot on PCsudo apt install rpiboot && sudo rpiboot
3Flash OS image to eMMCUse Raspberry Pi Imager or dd on detected USB device
4Boot Compute ModulePower on carrier board, module boots OS
5Access moduleSSH or serial console for programming
6Program GPIO or other peripheralsUse Python with RPi.GPIO or other libraries

Key Takeaways

Always use a compatible carrier board to connect and power the Compute Module.
Use the rpiboot tool to flash the OS image onto the Compute Module's eMMC storage.
Ensure a stable 5V power supply to avoid boot issues.
Access the module via SSH or serial console after booting for programming.
Use Raspberry Pi OS images compatible with your Compute Module version.