Read a few steps ahead before executing. It might contain error fixes or examples which might be helpful
- Raspberry Pi 4 Model B (RPi 4)
- 32GB microSD card (16GB or more recommended)
- Power supply 5V 3A Type-C (phone charger)
- Wi-Fi router
- Windows 10 computer
- Ubuntu Server 20.04.x LTS 64-bit with Desktop
- belenaEtcher
- Powershell
- TightVNC and Remote Desktop Connections
- ROS2 Foxy
-
Get Ubuntu Server 20.04.x LTS 64-bit image from official site: https://ubuntu.com/download/raspberry-pi
-
Get belenaEtcher from the official site: https://www.balena.io/etcher/
-
Open belenaEtcher
-
Press Flash from file
-
Select Ubuntu image downloaded at step 1
- e.g ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz
- or ubuntu-20.04.1-preinstalled-server-arm64+raspi.img (if file extensions are hidden)
- Do NOT unzip
-
Press Select target
-
Select your SD card
- e.g. Mass Storage Device USB Device 32GB D:\,E\
-
Press Flash!
-
Wait till flashing is done
- Reconnect SD card
- Open SD card system-boot (Note: USB Drive can't be opened in Windows)
-
Open network-config file with any notepad application. I recommend Sublime Text because it shows spaces when text is selected. Both files has to have Unix (LF) line endings
-
Delete everything in network-config file
-
Copy and paste the text below to network-config file
# This file contains a netplan-compatible configuration which cloud-init # will apply on first-boot. Please refer to the cloud-init documentation and # the netplan reference for full details: # # https://cloudinit.readthedocs.io/ # https://netplan.io/reference # # Some additional examples are commented out below version: 2 wifis: wlan0: dhcp4: true optional: true access-points: "HUAWEI-AB77": password: "myPassword123" # myworkwifi: # password: "correct battery horse staple"
-
Change HUAWEI-AB77 to your Wi-FI SSID and myPassword123 to Wi-Fi password
-
Save network-config file
-
Open and append user-data file with text below (don't copy first 2 lines it's already in the file). Warning: make sure to use 2 spaces and no tabs for indentation
# ... #- [ wget, "http://ubuntu.com", -O, /run/mydir/index.html ] ##Reboot after cloud-init completes power_state: mode: reboot
Example of user-data file. Only last lines are changed (Click to expand)
#cloud-config # This is the user-data configuration file for cloud-init. By default this sets # up an initial user called "ubuntu" with password "ubuntu", which must be # changed at first login. However, many additional actions can be initiated on # first boot from this file. The cloud-init documentation has more details: # # https://cloudinit.readthedocs.io/ # # Some additional examples are provided in comments below the default # configuration. # On first boot, set the (default) ubuntu user's password to "ubuntu" and # expire user passwords chpasswd: expire: true list: - ubuntu:ubuntu # Enable password authentication with the SSH daemon ssh_pwauth: true ## On first boot, use ssh-import-id to give the specific users SSH access to ## the default user #ssh_import_id: #- lp:my_launchpad_username #- gh:my_github_username ## Add users and groups to the system, and import keys with the ssh-import-id ## utility #groups: #- robot: [robot] #- robotics: [robot] #- pi # #users: #- default #- name: robot # gecos: Mr. Robot # primary_group: robot # groups: users # ssh_import_id: foobar # lock_passwd: false # passwd: $5$hkui88$nvZgIle31cNpryjRfO9uArF7DYiBcWEnjqq7L1AQNN3 ## Update apt database and upgrade packages on first boot #package_update: true #package_upgrade: true ## Install additional packages on first boot #packages: #- pwgen #- pastebinit #- [libpython2.7, 2.7.3-0ubuntu3.1] ## Write arbitrary files to the file-system (including binaries!) #write_files: #- path: /etc/default/keyboard # content: | # # KEYBOARD configuration file # # Consult the keyboard(5) manual page. # XKBMODEL="pc105" # XKBLAYOUT="gb" # XKBVARIANT="" # XKBOPTIONS="ctrl: nocaps" # permissions: '0644' # owner: root:root #- encoding: gzip # path: /usr/bin/hello # content: !!binary | # H4sIAIDb/U8C/1NW1E/KzNMvzuBKTc7IV8hIzcnJVyjPL8pJ4QIA6N+MVxsAAAA= # owner: root:root # permissions: '0755' ## Run arbitrary commands at rc.local like time #runcmd: #- [ ls, -l, / ] #- [ sh, -xc, "echo $(date) ': hello world!'" ] #- [ wget, "http://ubuntu.com", -O, /run/mydir/index.html ] ##Reboot after cloud-init completes power_state: mode: reboot
-
Save user-data file
-
Close notepad and remove sd card
- Power off RPi
- Insert SD card into RPi
- Power on RPi. Green LED should blink while booting
- For first boot WAIT FOR 5min (or longer) before continuing to next step. After some time RPi should automatically connect to Wi-Fi
To SHH into Raspberry Pi we need to 3 things: username, password and IP address of RPi which will be used in Powershell command as:
ssh username@IPAddress
Note: to paste in Powershell press right mouse button
Note: for more advanced users I recommend Windows Terminal. It has nicer interface
-
By default on new Ubuntu installation username: ubuntu, password: ubuntu
-
Find IP address of RPi (source)
-
Download Advanced IP Scanner https://www.advanced-ip-scanner.com/
-
Press Scan and wait for 2 minutes
-
Find and copy RPi ip address e.g 192.168.8.106. Raspberry Pi MAC address format is DC:A6:32:xx:xx:xx
-
If RPi is not found stop the scan and scan again a few times (scanning can take a few minutes). Or read further for more solutions for errors (search this document for In case of error)
-
If RPi have gray monitor icon power off and power on RPi wait few minutes and repeat scanning now it should show blue monitor icon
- Alternatively connect to your router and find all connected devices one of which is RPi and copy IP address
-
-
Connect to RPi with SHH
-
Open Powershell (by search or by right clicking Windows icon at the bottom left corner)
-
Run command in Powershell (change IP address accordingly). Type
yes
if requested.-
In case of error:
ssh: connect to host 192.168.0.106 port 22: Connection timed out
you need to disable your router WPS: -
In case of error:
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
runssh-keygen -R 192.168.8.106 ssh [email protected]
-
If it's still not connecting check steps before for any error or google the error. Also it might be necessary to start from the beginning and re-flash Ubuntu image
-
-
It will ask for password. Type
ubuntu
. Note star "*" symbols won't appear due to security reasons but it's still typing -
After login it's required to change password. After changing password ssh gets disconnected. To reconnect repeat
ssh [email protected]
command. Now terminal should displayubuntu@ubuntu: $
if not something went wrong. -
Run
lsb_release -a
. Output should be:
- Password can be changed with
passwd myUserName
e.g.passwd ubuntu
-
-
ubuntu@ubuntu:~$
should be shown in terminal if not connect to Raspberry Pi via SSH. How to do that is described in a previous chapter. Hint:ssh [email protected]
-
Copy paste commands below line by line press enter to run. It will install desktop environment. To paste in Powershell press right mouse button
sudo apt update && sudo apt -y upgrade sudo apt install -y tasksel sudo tasksel install ubuntu-desktop-minimal
- In case of problem:
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock frontend.
Power off and power on RPi, wait ~2 min for it to boot and connect via SSH by runningssh [email protected]
in Powershell. Repeat failed command which could not be finished due to cache lock. Repeating apt install command won't do anything if package is already installed so it's safe. - Alternative cache lock fix (no reboot)
- In case of problem:
-
Install VNC server
sudo apt install -y xrdp sudo apt install -y tightvncserver
-
Reboot Raspberry Pi
-
On Windows 10 computer open search for Remote Desktop Connections application
-
Specify IP address of RPi. It's the same address as for SSH connection. e.g 192.168.8.106
-
Credentials can be saved for next session by pressing Show Options, entering User name and checking Allow me to save credentials
-
Press Connect and select Xorg, username: ubuntu and password: yourChangedPassword. Press OK and wait a minute for black window to load
-
To open Ubuntu terminal press Ctrl+Alt+T
- For dark theme press top right menu icon -> Preferences -> General -> Theme variant: Dark
- To open terminal in new tab press Ctrl+Shift+T
-
To open more GUI applications press Activities at the top left corner and icon at the bottom left
-
If GUI run slow lower screen resolution in Remote Desktop Connections application before entering IP address by going to Show Options -> Display and sliding slider to small size. 1280x720 and 16 bit color depth is a good compromise
Sources:
- Other desktop alternatives: https://linuxconfig.org/ubuntu-20-04-gui-installation
- How to install tightvnc source: https://sbcguides.com/install-tightvnc-server-on-raspberry-pi/
-
Further commands can be executed via VNC on Ubuntu terminal (Ctrl+Shift+T) or via SSH on Win10 machine both methods are equivalent. Run commands line by line (be careful with wrapped lines)
-
Setup locale
sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8
-
Setup resources
sudo apt update && sudo apt install -y curl gnupg2 lsb-release curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - sudo sh -c 'echo "deb [arch=$(dpkg --print-architecture)] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/ros2-latest.list'
-
Install ROS2 and helper packages
sudo apt update sudo apt install -y ros-foxy-desktop sudo apt install -y python3-colcon-common-extensions sudo apt install -y python3-argcomplete
-
Setup ROS2
echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc source ~/.bashrc
-
Check if installation successful by connecting VNC server (via Remote Desktop Connections) opening terminal (Ctrl+Shift+T) and running
rviz2
Source: https://roboticsbackend.com/install-ros2-on-raspberry-pi/