0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

🐢 ROS 2 Initial Setup for Raspberry Pi 4

0
Posted at

πŸ“ 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.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?