/
Connecting to the Raspberry Pi in RPRK

Connecting to the Raspberry Pi in RPRK

You can communicate with your robot either through serial or over a network connection. Serial is usually the most reliable form of communication, but it is slow and only allows access to the text terminal. Connecting using a network connection, either WiFi or Ethernet, gives you a much greater bandwidth, allowing you to transfer files, and have graphical access to your Pi.

Serial

Provided as part of your kit is a USB to UART adapter. It should have been pre-installed onto the GPIO of the Raspberry Pi. This allows you to easily access the serial UART port of the Raspberry Pi over USB. Simply connect a microUSB cable between the USB to UART board and your computer, and power the Raspberry Pi.

On Windows it will show up as a COM port, you can find out the COM port number by looking in Device Manager. You will need to use a terminal program to communicate using the COM port. Our recommended program in PuTTY, which is pre-installed on the lab PCs. In PuTTY you must first change the connection type to serial, then specify the COM port, which you will have found from Device Manager (in this example it is 4, but yours may be different), and finally the speed of the port, which by default on the Pi is 115200.

 

image-20240229-113911.png

 

 

On Linux/Mac the USB to Serial converter will usually appear as /dev/ttyUSBx or /dev/ttyACMx – use dmesg to check the name of the last plugged in device.  You can easily watch output from the serial port by setting the baud rate with stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb and then concatenating the output with cat /dev/ttyUSB0.  This is less convenient than a terminal, so two easy to use Linux terminals are minicom and picocom which can both be installed on a Raspberry Pi or Ubuntu PC with sudo apt install minicom picocom.  Picocom is started with picocom -b 115200 /dev/ttyUSB0 and exiting is a little complicated – hold <ctrl> and type ‘a’ then ‘x’.

When you first connect in this way, the terminal may be blank, even if it is properly connected. If this is the case, you should be able to just press ‘enter’ to reach the login prompt. The default login username is ‘pi’, and the password is ‘raspberry’. Once you are connected, it should look like this:

You can now use the terminal to execute commands on the Pi, such as ifconfig, which you can use to find your IP address.

Networking

Connecting your Pi to a network gives you a higher bandwidth, which allows you to transfer files between your Pi and computer, and use graphical programs remotely. You can connect you Pi either through WiFi or Ethernet. You will most likely be using WiFi, as it is more convenient as it doesn't require a physical connection, which is useful for a mobile robot, but Ethernet may be useful for debugging.

WiFi

robotlab WiFi

In the Robot Lab there is available a special WiFi network called robotlab. This has less restrictions the eduroam WiFi network, which allows us to connect with a simple passphrase like a home network, and allows us to access the Pis from the lab PCs. The Raspberry Pi OS image we have provided to you is preconfigured to connect to the robotlab network. If you are using the lab PCs, they are able to connect directly to the robotlab network, but if you are using your own laptop, you will need to connect your laptop to the robotlab WiFi to be able to connect to your Pi. The credentials are as follows:

The SSID is: robotlab

The passphrase is: vertzlentath

IP addresses on the robotlab network and most networks are set dynamically. This means that you cannot guarantee that your IP address will stay the same between sessions. If you are unable to connect to your Pi then please reconnect over serial to check your IP address. There is also a chance that the IP address you previously had will be reassigned to another Pi, so if you see files on your Pi that are not your own you may be connected to someone else’s robot!

Other WiFi networks

You can configure your Raspberry Pi to connect to other WiFi networks if needed. After connecting to your robot with the serial terminal, type sudo raspi-config to open the configuration screen, go to “2: Network Options” and then “N2 Wireless LAN” to enter an SSID and passphrase. Once you have done this, go to ‘Finish’. After a few moments, the robot should connect to the specified network. Note that this will only work with networks that are setup to connect with a simple passphrase, like a home WiFi network. Networks setup with enterprise authentication that require a username and password login, such as eduroam, or the networks in many student halls will not work, and you will have to use another option if that is the only network available to you.

Direct

Included with the premade image you have been given is a script that will automatically detect if the Pi cannot connect to any WiFi network, and if it cannot, it will broadcast its own access point for you to connect to. This will allow you to connect directly to your Pi wirelessly without needing a network. The credentials for the network are as follows:

The SSID is: RPRK-WiFi

The passphrase is: vertzlentath

The IP address of the Pi is static when using the direct WiFi connection. The IP will be 192.168.50.5

Ethernet

You may also want to connect to your robot over Ethernet. This is less desirable than WiFi as it means tethering your robot with an Ethernet cable, but it can sometimes be more reliable than WiFi in some situations. You can either connect your Pi to a switch that is also connected to your computer, or you can connect an Ethernet cable directly between the two.

Finding your IP address

Before you can connect to your Pi over any sort of network, you must know its IP address. You can find out the IP address by running the ifconfig command in the terminal. As you cannot yet connect to your Pi over the network, you must use an alternative connection method to find your IP. The easiest way is to connect over serial, as described in the first section. Once you have a serial connection, you can run the ifconfig command to find your IP. Another alternative is to connect your Pi to a monitor and keyboard and run the command that way.

The output of the ifconfig command should look something like this:

There will be multiple sections in the output, as the Pi has multiple network interfaces. For WiFi connections, we will be looking for the section labelled wlan0, as in the screenshot. For Ethernet, we would be looking for a section labelled eth0. For either connection type we will be looking for the inet entry in that section. This will be the IPv4 address of our Pi. If there is no inet entry, the Pi may have not finished connecting to the network. Wait a few moments and run the command again. In this example the IP address of the WiFi connection is 144.32.70.200. All of the IP addresses on the robotlab network should be in the 144.32.70.xxx address space. IP addresses on different networks will be different.

Using SSH

Now you have your Pi connected to a network and you have its IP address, you can connect to it over the network. SSH (Secure SHell) lets you connect to a terminal (shell) over a network, allowing you to run terminal commands on your Pi. Using some additional features you are also able to send the output of graphical apps from your Pi to your computer.

Windows

On Windows you will need to install an SSH client. We recommend PuTTY, which is installed on the lab PCs. Make sure the connection type is set to SSH, and in the hostname box put pi@xxx.xxx.xxx.xxx, as shown in the screenshot. In this case the IP is 144.32.70.200, so we type pi@144.32.70.200.

 

image-20240301-103940.png

There are two additional options that you will want to enable, although they are optional for the basic terminal usage. Under “Connection” > “SSH”, tick the “Enable compression” box as shown in screenshot:

 

image-20240301-104157.png

This will allow the connection between your computer and the Pi to be compressed, increasing the throughput of the connection. This is most useful when you are using X11 forwarding to display graphical output from your Pi on your computer. The X Window System, also called X11 or just X, is part of how Linux applications display graphical content to the screen. When running applications locally, the client X11 applications connect to a locally running X server to display graphics, but they can be made to connect to a remote X server instead. To enable this in PuTTY go to “Connection” > “SSH” > “X11” and tick the box labelled “Enable X11 forwarding” as shown in the screenshot:

 

image-20240301-104836.png

This will tell the SSH server on the Pi that our computer can accept X11 connections, and to forward any X11 requests on the Pi to our computer, over the SSH connection. For this to work, we need to be running an X server on our computer. Windows does not use X11, we need to install our own X server. We use a program called XMing to do this, it has been pre-installed on the lab PCs. Make sure that XMing is running before you start your SSH connection.

To save these settings for later go back to the “Session” screen, type a name for the session in the “Saved Sessions” textbox and click “Save”, which will add it to the list of saved session. To load these settings again, select the name from the list and click the “Load” button.

Linux

Generally speaking, the command line SSH program will be preinstalled on most Linux systems, if not, it should be available from your package manager. The lab PCs will have it preinstalled. You can connect to your Pi using the command ssh -XC pi@xxx.xxx.xxx.xxx, replacing xxx.xxx.xxx.xxx with your IP address. The -X flag indicates that graphical programs opened on the Pi will be tunneled through ssh to show on your local X server on your PC. The -C flag requests that the connection is compressed. This should improve performance on the WiFi.

Transferring Files

With a full network connection you are also able to transfer files between the Pi and your computer. This is important as you should be backing up your work at the end of every session.

Windows

On Windows we recommend you use the program WinSCP, which is available on the lab PCs. You use the same information to login as you do for SSH, se seen in this screenshot:

This will open a file explorer, showing your local computer on the left, and the Pi on the right. You can browse the files on the Pi, copy files between locations, and if you open a code file on the Pi, it will be opened locally as a local copy in a text editor. You can make changes to the code, and when you save it, the modified file will be written back to the Pi. By default this will use Notepad – you may want to change this to a more appropriate editor for code, such as Notepad++, which is pre-installed on the lab PCs.

 

 

To make your choice the preferred editor, you will need to move it up to the top of the editor preference using the ‘up’ button.

Linux

You can access your files from the regular file browser on Linux on the lab PCs. First go to "Other Locations" in the left-hand sidebar:

 

Then in the "Connect to Server" bar at the bottom, type "sftp://" then your Pi's IP address. For example, if your Pi has the address 144.32.70.236 you would type "sftp://144.32.70.236" in this box, then click connect:

You should now be presented with the files from your Pi, and the location should stay in the sidebar until you either manually disconnect or until you logoff. There are also other programs you can use on Linux, such as FileZilla which is more similar to WinSCP.

Related content