Raspberry Pi 4 — Install Ubuntu 18.04 Server, Setup VNC & SSH, and Publish Image Stream from Camera Module in ROS
By: Muhammet Furkan Nargül
Tags: Raspberry Pi, Ssh, Vnc, Ubuntu, Robot Operating System

Hello everyone! This will be my first blog post on Medium. It’s gonna be about the installation of Ubuntu 18.04 Server on Raspberry Pi 4, using VNC & SSH, and image stream publishing by using camera module integrated to Raspberry Pi, in ROS (Robot Operating System). I’m using Ubuntu 18.04 as the operating system for this tutorial.

Firstly, let me tell you what purpose I have for this tutorial. The reason why I’m writing this tutorial is is that I’m currently working on a “Drone Localization Project” as a capstone project at my university. In the project, the drone is supposed to fly autonomously and localize itself by using computer vision algorithms and UWB sensors so Raspberry Pi is the most commonly used small single-board computer for this purpose. That’s why I had to make it prepared for this use. Additionally, it took too much time for me to complete installations and setups. Hence, I hope this tutorial will be utilized by those who work on this.

WHAT YOU NEED: - Ubuntu 18.04 on your computer - Raspberry Pi 4 (Model B) - Ethernet Cable - Camera Module - Cooling Fan (Recommended) - SD card - Basic knowledge on Linux and ROS

Now, let’s come to how we do it. I’ll go step by step:

Download a Ubuntu Server. This was the most tricky step that took a couple of weeks to find the most suitable one. I’ve tried many operation systems including Raspbian but those didn’t work properly for the use of ROS and camera module. Finally, I’ve preferred Ubuntu 18.04 Server with 32-bit (armhf) because I’m normally using Ubuntu 18.04 and wanted to avoid any compatibility problem. The reason why I’ve chosen the 32-bit version is that the 64-bit version caused some errors in /etc/apt/sources.list when I try to add some necessary packages into the list. You can download the servers through the following link: http://old-releases.ubuntu.com/releases/18.04.4/ubuntu-18.04.4-preinstalled-server-armhf+raspi4.img.xz

This was the most tricky step that took a couple of weeks to find the most suitable one. I’ve tried many operation systems including Raspbian but those didn’t work properly for the use of ROS and camera module. because I’m normally using Ubuntu 18.04 and wanted to avoid any compatibility problem. The reason why I’ve chosen the 32-bit version is that the 64-bit version caused some errors in /etc/apt/sources.list when I try to add some necessary packages into the list. You can download the servers through the following link: http://old-releases.ubuntu.com/releases/18.04.4/ubuntu-18.04.4-preinstalled-server-armhf+raspi4.img.xz Mount the Server into an SD Card. In this step, we should install an image mounter application. I’ve used Raspberry Pi Imager. Choose the server as “Operating System” and an SD card you plugged in as “SD Card”. Then, write it. After a while, remove the SD card once the process is completed.

Insert the SD card into Raspberry Pi.

Connect Raspberry Pi with your computer by using an ethernet cable and power it.

Type nm-connection-editor on terminal and change IP4 Setting as “Shared to other computers”. For this, you can check out the tutorial: https://askubuntu.com/questions/1039907/how-to-share-wired-network-connection-in-18-04/1039918

nm-connection-editor For this, you can check out the tutorial: https://askubuntu.com/questions/1039907/how-to-share-wired-network-connection-in-18-04/1039918 Type cat /var/lib/misc/dnsmasq.leases on terminal to get the name and IP address of Raspberry Pi.

cat /var/lib/misc/dnsmasq.leases Type sudo ssh “name of raspberry pi”@”ip of raspberry pi” on terminal to connect access Raspberry Pi from your computer. Example: sudo ssh ubuntu@10.42.0.64 . Then, it requires a password. Just type ubuntu since it’s the default password. Next, determine a new password when it asks for it.

sudo ssh “name of raspberry pi”@”ip of raspberry pi” Example: sudo ssh ubuntu@10.42.0.64 . Then, it requires a password. Just type ubuntu since it’s the default password. Next, determine a new password when it asks for it. Install Ubuntu Mate Desktop on Ubuntu Server. Since we have installed Ubuntu Server, we have no desktop to monitor Raspberry Pi so we should install a Desktop on it. Ubuntu Mate Desktop properly fits for it. You can use the following commands to install it.

sudo apt install tasksel sudo apt update sudo tasksel install ubuntu-mate-desktop

Install Raspi-Config. This a necessary step to provide the functionality for making configuration changes. Here you can enable some options such as SSH, VNC, and camera module which are a must for our purpose.

cd /etc/apt sudo nano sources.list

Add “deb http://archive.raspberrypi.org/debian/ jessie main” to the end of the lines. Save (Ctrl+S) it and exit(Ctrl+X). Then; arrange the keyserver, make the update and install it with the following commands.

sudo apt-key adv - -keyserver hkp://keyserver.ubuntu.com:80 - -recv-keys 7FA3303E sudo apt update sudo apt upgrade sudo apt-get install raspi-config

Open Raspi-Config.

sudo mount /dev/mmcblk0p1 /boot sudo raspi-config

Here are many options. Select “Interfacing Options” and make enable Camera, SSH, and VNC. SSH stands for headless communication between Raspberry Pi and computer while VNC is used to monitor the desktop of Raspberry Pi on the computer.

Download and install RealVNC Viewer via the following link: https://www.realvnc.com/en/connect/download/viewer/ . After clicking the link, select Linux and DEB x64. Then, download it.

After clicking the link, select Linux and DEB x64. Then, download it. Install tightvncserver and start it at 720p to initialize the environment for VNC. It’ll ask you to create a password to use the VNC session. Set it to be the same as your Raspberry Pi password.

sudo apt update sudo apt install tightvncserver tightvncserver -geometry 1280x720

Open VNC Viewer, type “name of your Raspberry Pi”.local:1 and connect it. Example: ubuntu.local:1. Now, you can remotely control Raspberry Pi. Don’t forget to always type tightvncserver -geometry 1280x720 on terminal before opening VNC Viewer. Now, you should have accessed the desktop of Raspberry Pi.

From now on, we will continue the process on VNC Viewer.

Install ROS Melodic and make sure that ROS is working by typing roscore on terminal. Follow the tutorials: http://wiki.ros.org/melodic/Installation/Ubuntu & http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment

roscore Follow the tutorials: http://wiki.ros.org/melodic/Installation/Ubuntu & http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment Setup Raspberry Pi Camera. Make sure that the camera module is properly connected to Raspberry Pi.

Make sure that the camera module is properly connected to Raspberry Pi. Install camera libraries and reboot.

sudo apt-get install libraspberrypi-dev sudo apt update sudo apt install python-pip sudo pip install picamera sudo reboot

Connect it with ssh again after rebooting. Create a python script named cam.py and copy the code below. Then, run it by typing python cam.py . You can also follow the link: https://www.theconstructsim.com/publish-image-stream-ros-kinetic-raspberry-pi/

import picamera

camera = picamera.PiCamera()

camera.capture(‘mytest_image.jpg’)

camera.close()

Now, it should work and create a picture on the same folder where the code is located. If you get an error such that “ImportError: No module named ‘picamera’”, then fix it by the following link: https://picamera.readthedocs.io/en/release-1.13/install.html

Publish the image stream in ROS. Clone the raspicam node and compile it. Then, publish Raspberry Pi Camera images into an image rostopic.

cd ~/catkin_ws/src git clone https://github.com/dganbold/raspicam_node.git cd ~/catkin_ws/ catkin_make

Start the node with all services for the camera module and publish images.

cd ~/catkin_ws/ source devel/setup.bash roslaunch raspicam_node camera_module_v2_640x480_30fps.launch

It has now been launched. Open another terminal and type:

rosservice call /raspicam_node/start_capture

Now, video capture has been started. Open one another terminal and type.

rosrun image_view image_view image:=/raspicam_node/image_raw

Finally, it shows you the image streaming. You have now accessed to the camera module and been receiving images from it.

Thank you for reading the tutorial! Here are the references I’ve utilized: