Return to the Raspberry Pi!

Since I published my last post on the fencing score box system I have been contacted by a hardware manufacturer who is interested in embedding a Raspberry Pi in their new range of equipment.  As a result, this has put the Pi firmly back on my agenda!  I will return to the build process for the FreePascal compiler in another article, but before then I want to cover the method I am now using to connect to the Pi as I think it is far more convenient for a developer, than having the Pi set-up with a dedicated screen, keyboard and mouse.

The basic idea is to create a local subnet via a direct cable connection to the Pi and then interact with the Pi via SSH using the laptops own peripherals.  There are quite a number of ways of doing this, but I will describe the process I use as I think it is the simplest to set-up (at least from an Kubuntu/Ubuntu point of view).  To start with the Pi needs to be attached to a power source.  This can be a micro-USB mains charger, or a USB to micro-USB cable to draw the power off the laptop.  If you choose the second method, be sure your laptop is capable of reliably supplying the additional current required.  I prefer to power the Pi independently, to avoid any issue with straining my already hot laptop PSU.

Next the Pi is connect to the laptop via a standard Ethernet cable.  A cross-over cable is not required as the Pi is smart enough to detect this type of connection and reconfigure itself accordingly.  Once plugged in, you will need to know the IP address allocated to the Pi to be able to communicate.  This is where the confusion begins.  There seem to be four approaches to doing this.  Two require editing configuration files on the PI itself.  As with any editing of configuration files, it is always a wise precaution to make a backup copy of the file before making changes!  To edit configuration files on the Pi, I plugged the Raspian SD card directly into my laptop and edited it there before re-inserting it into the Pi.

The first way to allocate an IP address is to edit the ‘/etc/network/interfaces’ file on the Pi to define a static address for the eth0 interface.  This is the first method I tried, but I could not get this to work.  I suspect there are other start-up processes on the Pi that override this Linux configuration method.

After a bit more googling I found the second method.  It is also possible to pass a boot command line argument to the Pi that allocates an IP address.  This is achieved by editing the ‘cmdline.txt’ file in the boot partition of the Pi by adding ‘ip=169.254.0.1’, for example, to the end of this file.  Care must be taken not to insert a return as this must be all on one line.  This enabled a basic SSH connection to the Pi with the command ‘ssh pi@169.254.0.1’. However, the Pi was isolated from the wider network by the host laptop, so for example: ‘sudo apt-get update’ would not connect to the repositories.

The last two solutions solve this problem.  One is to set-up the laptop as a full-blown DHCP server.  This is certainly possible, but I feel it is overkill for what I wanted to achieve.  The last solution is to use internet connection sharing on the laptop, to allow network traffic to be passed through the laptop’s network connections.  My laptop uses an internal WIFI card to connect to our home ADSL rooter, or at work, the company’s wireless network.  This leaves the Ethernet port free to connect to the Pi. Internet connection sharing, permits traffic to be passed from one interface to the other.  In Kubuntu, and I believe Ubuntu also, this can quickly be set through the network connection editor.

ConnectionPropertiesThe default mode for cable connections is ‘Automatic’ on the ‘IPv4’ tab.  Changing this to ‘Shared to other computers’ sets up the interface for internet connection sharing.  I also set the option to ignore ‘IPv6’ connections as I did find an article which suggests this can cause problems with a Pi, although I don’t know if that is really required.  I also switched off automatic connection as I want to be able to manually choose between this and a standard DCHP connection.

ConnectionEditor

I also discovered that once internet sharing was enabled, it was not necessary to set the boot parameter IP address as one was allocated anyway.  In my case it was ‘10.42.0.44’. This can be discovered with the arp command.  Knowing this, I then edited the ‘/etc/hosts’ file on my laptop to look like this:

127.0.0.1 localhost
127.0.1.1 laptop01
10.42.0.44 rpi

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

This enabled the SSH command to connect using the name ‘rpi’ rather than having to remember the IP address.  Its worth pointing out two useful features of SSH for those that are new to it.  The first is the ‘-X’ parameter.  This enables remote X Windows applications to be started over SSH.  The second is that modern Linux desktops can use it as a networking protocol to provide remote folders in their visual file managers.

Desktop

In this screenshot I have started the Pi’s Midori browser via an X Windows link and opened a Dolphin file browser looking at the Pi’s FreePascal folder.  So for Linux the full SSH command line for the default pi user looks like this:

ssh -X pi@rpi

Its worth mentioning for Windows users, that they can also use SSH by installing a utility called Putty.  I have not used this myself, but I have read several articles where this has been successfully used to achieve the same working environment as this.  At some point, I will also investigate using RSA keys which may be combined with SSH to avoid having to use passwords every time you connect.

One thought on “Return to the Raspberry Pi!

  1. Pingback: Cross-compiling to Pi Zero | Michell Computing News

Leave a Reply