π Introduction
After setting up your Raspberry Pi in headless mode, the next step for robotics projects is installing ROS 2.
ROS 2 is a framework used to build robot applications, such as sensor processing and movement control.
In this guide, you will:
- Install ROS 2 on Raspberry Pi 4
- Set up the environment
- Run a simple test to confirm everything works
This tutorial focuses on a minimal, working setup for beginners.
By the end of this guide, you will have a working ROS 2 environment on your Raspberry Pi and confirm that nodes can communicate.
β οΈ Before You Start
Make sure your Raspberry Pi is already set up and accessible.
β
You should have:
- Raspberry Pi OS (64-bit) installed using Raspberry Pi Imager
- WiβFi configured (your Raspberry Pi already knows how to connect to your WiβFi network)
- VNC or SSH working
π If not, follow this guide first:
πΆ Raspberry Pi 4 Initial Setup (Headless + VNC)
https://qiita.com/tri-edge/items/df545c0aaac6975101ed
π‘ How to access your Raspberry Pi
You can use either:
- VNC (desktop GUI)
- SSH (terminal only)
Example:
ssh your_username@raspberrypi.local
π All commands in this tutorial are run in the terminal.
π§ Requirements
π Hardware
- Raspberry Pi 4 (4GB recommended)
- microSD card (32GB recommended for ROS 2)
- Stable power supply (5V / 3A)
π» Software
- Raspberry Pi OS (64-bit recommended)
- Internet connection
- Terminal access
β»All commands in this tutorial should be run on the Raspberry Pi (via VNC or SSH).
π Setup
β Update your system
sudo apt update
sudo apt upgrade -y
π This ensures your system is up to date.
β‘ Set locale (required)
sudo apt install locales -y
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
Using Raspberry PI terminal, check:
locale
π You should see en_US.UTF-8
β’ Add ROS 2 repository
Install required tools:
sudo apt install software-properties-common curl -y
Add ROS 2 key:
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key | sudo apt-key add -
Add repository:
sudo sh -c 'echo "deb http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2.list'
Update packages:
sudo apt update
β£ Install ROS 2
β Recommended (lightweight)
sudo apt install ros-humble-ros-base -y
π Best option for Raspberry Pi RoboDog
β€ Set up environment
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
β
This enables the ros2 command
β₯ Install build tools
sudo apt install python3-colcon-common-extensions -y
β Test ROS 2 installation
π₯οΈ Open two terminals
Terminal A:
ros2 run demo_nodes_cpp talker
Terminal B:
ros2 run demo_nodes_py listener
Expected result
- Terminal A β sending messages
- Terminal B β receiving messages
Example:
I heard: Hello World
β This confirms ROS 2 is working
π§ What is ROS 2?
ROS 2 uses a publisher / subscriber system:
- Talker β sends data
- Listener β receives data
π This is how robot components communicate
β‘ Key Points
- Use Raspberry Pi 64-bit OS for compatibility
- Install ros-base for better performance
- Run source ~/.bashrc if commands donβt work
- ROS 2 needs two terminals to test communication
β Summary
You now have a working ROS 2 setup:
- Installed ROS 2
- Configured environment
π ROS 2 commands are available in the terminal - Verified communication
π Confirmed that ROS 2 nodes can send and receive messages
β Your Raspberry Pi is now ready for robotics development using ROS 2
π You are now ready to start controlling hardware and building your robot dog using ROS.