Raspberry Pi Setup
This guide will outline the steps taken to setup the baseline software on the Raspberry Pi 4.
Requirements
This project recommends using a Raspberry Pi with at least 4GB of RAM. Compiler issues have been encounter with the 2GB variant.
- Raspberry Pi 4 Model B Rev 1.5 (4GB)
- 64 GB Micro SD Card
- Micro SD Card Reader
Setup OS Installation
- Install Raspberry PI Imager https://www.raspberrypi.com/software/
- Select Raspberry PI OS (64-bit) Debian Bookworm
- Select at Storage option of at least 64 GB
- Select gear for advance option to specify the following form fields.
- Check the Set hostname box.
hostname: rpi4
- Check the Set username and password box ^rpi-os-config
username: bot
- `password: bot
- Check the Enable SSH box
- Select the Allow public-key authentication only radio button
- Open a terminal and enter the following. You may skip this step if you already have performed it. ^rpi4-ssh-key
ssh-keygen -C "user@hostname" -f ~/.ssh/samsung-rpi4
cat ~/.ssh/samsung-rpi4.pub
- Copy the output the last command and paste it into the
Set authorized_keys for the 'bot':
form field.
- Check the Configure wireless LAN box and enter the required form fields.
- Select Save
- Check the Set hostname box.
- Flash Raspberry PI OS 64-bit to the Micro SD Card
- Alternatively setup NVMe boot with NVMe hat
- Once the flashing is successful install the Micro SD card into the rpi4, hook up a monitor, mouse, and keyboard and power on the device.
Setup Raspberry Pi SSH config
NOTE
There are two ssh keys involved for this project each for specific access. The key naming pattern used is
LocalMachineHostname-RemoteMachineHostname
understood as “We log in from Local Machine (the computer in front of us) to the Remote Machine (computer elsewhere)“.
/home/user/.ssh/samsung-github
provides GitHub repo access to push commits to the repo- The contents the of the public key
samsung-github.pub
is copied to Github via https://github.com/settings/keys/home/user/.ssh/samsung-rpi4
provides access to Raspberry Pi 4- The contents the of public key
samsung-rpi4.pub
is copied from the local machine to the/home/bot/.ssh/authorized_keys
file of the remote Raspberry Pi 4. ^rpi4-ssh-configThe following notes will guide you setting up the ssh keys such that you may conveniently develop and commit code changes all entirely remotely (i.e Within a Docker Container that is running on the Raspberry Pi)
- From your local machine (non-rpi4) open up a terminal and perfrom the following.
- Test ssh access
ssh <user>@<rpi-local-ip>
Use the password you configured in the ^rpi-os-config step - Reserve a static local IP address for within the router’s configuration
- Reboot the pi
On host machine:
ssh -t <user>@<rpi-local-ip> "reboot"
- Test ssh access with machine name
ssh <user>@<hostname>
- Add ssh config to host machine ^rpi4-ssh-config
- On host machine:
xdg-open ~/.ssh/config
- Copy-paste the following, this project is using
rpi4
as the config-name. Note the identity field uses the key we create earlier ^rpi4-ssh-key
- On host machine:
- Test ssh
ssh <config-name>
Install Docker on Raspberry Pi OS (64-bit) Debian Bookworm
CAUTION
Installing Docker for Raspberry PI OS (64-bit) Debian Bookworm is not as straight forward at the time this note was authored (2024-11-1). The convenience script for Debian
get-docker.sh
will not be applicable and manual installation with need tweaking for the targeted OS. The following notes are based on https://docs.docker.com/engine/install/debian/#install-using-the-repository
- Open a ssh terminal on the Raspberry Pi 4
ssh <username>@<hostname>
- Update APT repos and upgrade packages
- Uninstall all conflicting packages
- Add GPG keys
- Add the bookworm repository to Apt sources.
CAUTION
Note
$VERSION_CODENAME
is NOT applicable as it’s used in the official Docker install for Debian. So we replace it withbookworm
- Install the Docker Packages
Attention
- If you previously added and updated an incorrect Apt sources (didn’t replace
$VERSION_CODE
withbookworm
) you may get the following error when you attempt tosudo apt install
docker packages. See section ^bookworm-aptThe following packages have unmet dependencies: docker-ce : Depends: iptables but it is not installable Recommends: pigz but it is not installable E: Unable to correct problems, you have held broken packages.
- This can be corrected by removing the updating the list and retrying the previous
sudo apt install
command.
- Run the docker
hello-world
image:
Post install steps to manage Docker as a non-root user
These next steps maybe necessary for docker to work it VS Code remote development click here for more info
- Create the
docker
group.
- Add your user to the
docker
group.
- Activate the changes to groups.
- Verify that you can run
docker
commands withoutsudo
.
Setup GitHub ssh keys
NOTE
For alternate authentication methods see Sharing Git credentials with your container
- Create private-public key pairs on your local machine (non-rpi4) and add public key to GitHub via https://github.com/settings/keys
- Test credentials
- Configure global settings
- Retrieve the fingerprint of the key just created
ssh-kengen lf ~/.ssh/<private-key>
- Add key to ssh agent
ssh-add ~/.ssh/<private-key>
- Verify key finger print is present in the ssh-agent
ssh-add -l
Setup VS Code and ROS2 Workspace Repository
- Open a ssh terminal on the Raspberry Pi 4
- Install Visual Studio Code on the pi
- Clone the ros2 workspace repo into the Raspberry Pi’s home directory for the current user
Setup VS Code Remote Development
- Install VS Code on your host machine
- Open VS Code on host machine
- Install the remote Remote Development extension pack more info about remote development here
- Connect to the
rpi4
via VS Code on your host machine- With VS Code open press
Ctrl + Shift + P
and enter “Connect to Host” - You should be prompted with a drop down menu of the known host that was configured in ^rpi4-ssh-config step
- With VS Code open press
- Open
bot2_ros2_workspace
workspace folder- With VS Code, Select File, Open Folder,
/home/bot/bot2_ros2_workspace/
then click okay
- With VS Code, Select File, Open Folder,
- Make sure the repo is currently on the
humble
branch- Check that the bottom left hand corner reads
humble
- if not, on VS Code press Ctrl + Shift + P and enter “Checkout to… ”
- Select “origin/humble”
- Check that the bottom left hand corner reads
- Open Docker the Humble ROS2 container
- on VS Code press Ctrl + Shift + P and enter “Rebuild and Reopen in Container”
- Check out the readme for the workspace to get started. Click hereto read a blog about this ROS2 workspace template