Ubuntu Linux for Robotics · Lesson 94 of 96
Raspberry Pi
Ubuntu on a Raspberry Pi 4/5, SD card vs SSD, GPIO, I2C, power and ROS 2 limits.
Estimated time · 60–90 min
Learning goals
What you will understand
- Explain raspberry pi in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
A Raspberry Pi is a low-cost, low-power arm64 computer that is well suited to sensor drivers, motor control and simple robots, though not to heavy perception. Ubuntu Server images for the Pi are written to an SD card with Raspberry Pi Imager; use a good quality card, or better an SSD, and a power supply that keeps the voltage up under load.
Enable I2C and SPI for sensors, add your user to the gpio and i2c groups, and watch for under-voltage warnings (vcgencmd get_throttled) and temperature (vcgencmd measure_temp). Build large C++ workspaces on a faster machine or cross-compile, because compiling on a Pi is slow.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the raspberry pi commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
vcgencmd measure_temp
# Read the CPU temperature.
vcgencmd get_throttled
# Check for under-voltage or throttling (0x0 means fine).
sudo usermod -aG gpio,i2c,dialout $USER
# Allow your user to use GPIO, I2C and serial ports.
ls /dev/i2c-*
# Confirm the I2C bus is enabled.
colcon build --parallel-workers 2 --symlink-install
# Limit parallel builds so the Pi does not run out of memory.
free -h
# Check memory; add swap only if compilation fails.What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · The robot's computer
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Raspberry Pi. Expected result: throttled=0x0
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: print the throttling state of the Raspberry Pi with vcgencmdExpected output
throttled=0x0Stuck? Show the full solution (try it yourself first)
vcgencmd get_throttledExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Set up Ubuntu on a Raspberry Pi, run a ROS 2 sensor driver and publish data, and record temperature and throttling state while it runs. Note which parts of your stack are too heavy for the Pi.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.