RaspberryPi 05: Remote Desktop

UPDATE:

This article is out of date, RealVNC is now installed on Raspbian, see this article for more info

(excerpt from page 27 of MRE-RPi book)

Often all you need to control your Raspberry Pi is an SSH connection, however sometimes it is useful to be able to remotely control your RPi using the mouse and seeing just what you would see on the screen of your RPi.

VNC (Virtual Network Connection) is a standard for doing just this. To use it, you have to install some software on your Pi. There are a number of VNC server applications, and the one we are going to use is called “tightvnc”.
We can install the VNC server software using the SSH connection that we established earlier.

**sudo apt-get install tightvncserver**
“vncserver :1 -geometry 1024×768 -depth 24”

on mac: open screen sharing
“vnc://192.168.10.70:5901”

Starting TightVNCServer on Boot

Having a remote desktop is extremely useful, but if we need to run the tightvncserver program on the Raspberry Pi each time we want to use the remote desktop, it would be extremely inconvenient. What we will do instead is set up tightvncserver so that it starts automatically each time the Raspberry Pi boots up.

To do this we are going to use a little bit of Linux cleverness. We’ll explain it as we go along, but be aware, some will find the explanations a little tiresome (if you’re already familiar) but I’m sure that there will be some readers who will benefit.

Our first task will be to edit the file /etc/rc.local. This file can contain commands that get run on start-up. If we look at the file we can see that there is already few entries in there;

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0” on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address

_IP=$(hostname -I) || true
if [ $_IP” ]; then
printf “My IP address is %sÄn” “$_IP”
fi

exit 0

We will add the following command into rc.local;
su – pi -c ‘/usr/bin/tightvncserver :1’

To do this we will edit the rc.local file with the following command;
sudo nano /etc/rc.local

RaspberryPi 03: Connecting RPi to WiFi

Overview

For these tutorials we will not use the Emily Carr Wifi network as it is problematic, instead we’ll be using my own network for this course, here is the login:

  • SSID: wifi network name is ecu-ixd
  • Password: wifi password is babelfish67

To connect to this network from your Raspberry Pi, we’ll need to edit the /etc/network/interfaces file.

We’re going to use nano to do this. Nano is a text editor for Unix-like computing systems or operating environments using a command line interface.

To edit the file type:
sudo nano /etc/network/interfaces

Modify the file so it looks the same as below:

auto lo
 
iface lo inet loopback
iface eth0 inet dhcp
 
allow-hotplug wlan0
auto wlan0
 
 
iface wlan0 inet dhcp
        wpa-ssid "ecu-ixd"
        wpa-psk "babel67"

Now save the file by using the key combination ctl+O (press the control button and the o button at the same time) Press ‘return’ to confirm the file name. Finally, to exit nano press ctl+X.

We’ll need to restart the network interface in order for it to connect to the network. We can do that with:
sudo /etc/init.d/networking stop

and then
sudo /etc/init.d/networking start

Now that we’re connected to Wifi let’s connect our computer to the RPI

RaspberryPi 02: Exploring Command Line Basics

The command prompt

Now that you’ve logged in you’ll see a command prompt with:

pi@raspberrypi ~ $

What does it mean?

  1. The pi section is your username followed by @.
  2. The raspberrypi (the default hostname), the ~ is your current working directory.
  3. The ~ symbol is short hand for your home directory. When you log into your Raspberry Pi, you first land in your home directory.
  4. The tailing $ is your shell prompt, anything you type to the right of it gets executed as commands.

Poking around the home directory

When you first login, you’re in the home directory. The home directory is represented as ~ on the command prompt. The ~ character can be used as a shortcut to jump into your home directory.

To see what’s inside your home directory use the ls command.

Other Directories

Your home directory has the following path /home/pi. There are other folders/directories above your home directory.

Don’t believe me? We can ask Linux to tell us what our current directory is by running:

pwd

you should see the following output:

/home/pi

pwd stands for print working directory.

Changing directory

To change directory use the cd command. What did you think cd stands for?

Moving up a directory

To move up a directory from pi’s home directory to the /home directory use the following command:

cd ..

Now when you print the current working directory, you should see.

/home

To go back to your home directory you would use the command:

cd pi however the following commands could also do the trick:

  • cd /home/pi (specifying the full path)
  • cd ~ (using the ~ shorthand)
  • cd (even typing just cd takes you back to your home directory, the maker of cd sure hates to type extra characters)
  • cd - (the - argument takes us to the directory we were immediately previously in, so this command would also work)

Other directories

Of course there’s more to your Pi than the /home directory. Let’s have an explore.

The folder structure on your Raspberry Pi looks something like this (with your home directory highlighted).’

folder-structure

Directory Description
/ The upper most of your hard disk (or SD Card)
/bin Programs and commands that all users can run
/boot All the files needed for booting your Raspberry Pi
/dev Files that represent devices on your Raspberry Pi
/etc Configuration files
/etc/init.d Scripts to start, stop and otherwise command services
/etc/X11 X11 Configuration Files
/home All the user home directories (except for root’s)
/home/pi The Pi user’s home directory
/lib This is where the Kernel modules / drivers live.
/media There is where hard disks, SD Cards and other removable media are mounted
/proc Virtual directory that provides details of running processes
/sbin Programs primarily used for systems maintenance
/sys Another special folder that represents hardware devices
/tmp A space for temporary files
/usr Programs and data usable by every user
/usr/bin Most programs you’ll run live in here
/usr/lib Libraries to support programs and programming languages
/usr/local By convention software specific to a machine goes here.
/usr/sbin More system software
/usr/share Supporting files that aren’t specific to chip architecture
/usr/src Source code!
/var System logs
/var/backups Typically compressed copies of system logs
/var/cache apt-get and other programs keep their data here
/var/log/ All the system and service logs
/var/mail This is where your mail goes (if you’ve set it up)
/var/spool Data that is waiting to be processed or dealt with lives here (e.g. mail or print jobs)

Ok, enough exploring let’s see what other commands we can do on the Pi!

RaspberryPi 01: Console Cable

Overview

Despite having four full sized USB ports and one micro USB port (for power), you can’t connect to your Raspberry Pi from your computer via USB (without additional hardware).

You can however connect to your Raspberry Pi via a “USB to TTL Serial Cable”, also sometimes called a Console Cable. This cable allows you to access the command line of your Raspberry Pi, by plugging the USB end into your computer and the other end into specific serial GPIOs on the Raspberry Pi.

For the most current information on Connecting with the Console look here. http://elinux.org/RPi_Serial_Connection

Note for RaspberryPi 3:
Add the following two lines in config.txt file on your RPi SD Card:
dtoverlay=pi3-disable-bt
enable_uart=1

What you’ll need

For this exercise you’ll need a console cable:

Caveat: Make sure your computer delivers at least 500 mA (milliamps) at 5 V (Volts). This will assure you that your RPi will receive the power it needs otherwise there’s a chance you’ll fry your Pi!

Software Installation (Mac)

Mac OS X includes a Terminal (inside /Applications/Utilities/), so the only other software you need to install is the drivers for the cable.

You can download the Mac drivers here.

Software Installation (Windows)

Windows does not include a Terminal application that you can use to connect over serial.

For this workshop we’ll use Putty. You can get the “putty.exe” app from the puttywebsite.

Download the one called “PuTTY” under For Windows on Intel x86 (direct link).

Putty downloads as an uncompressed binary.

Now that you’ve got Putty, you’ll also need to install the cable drivers here.

Software Installation (Linux)

Assuming you’re running a v2.6 kernel or later you shouldn’t need to install drivers for the cable. If you find that your distribution doesn’t have the drivers installed you can download the drivers from the FTDI website.

You may also need to install screen. The screen command (some Linux distributions such as Ubuntu 12.10 don’t include the screen software). To see if you’ve got screen installed type screen and if you get an error install screen by running: sudo apt-get install screen.

Connecting the cable

The console cable handily provides the name of the line on the side of the terminal header.

Connect the console cable to the following pins:

  • DC → RPi Pin 02 (DC Power 5V)
  • GND → RPi Pin 06 (Ground)
  • RXD → RPi Pin 08 (Data Transmit)
  • TXD → RPi Pin 10 (Data Receive)

Connecting via the Shell

Bringing up the Shell On Mac / Linux

TL;DR:

If you’re running Mac OS X all you need to do is open a Terminal window and run screen in the command line using the command:

screen -L /dev/tty.usbserial 115200

screen is the command. /dev/cu.usbserial is the path to your serial device and 115200 is the baud rate (the speed at which we send data across the serial interface).

If you’re on Linux you’ll need to escalate your privileges by putting sudo in front of the command.

E.g:

sudo screen /dev/cu.usbserial 115200

Bringing up the Shell on Windows

If you’re running Windows, you’ll need to find out what com port the console cable is using.

  1. Search for Device Manager
  2. Expand the Ports (COM & LPT) section

You now need to open putty

  1. Select Serial as the connection type
  2. Enter the name of the COM port you’ve found
  3. Set the speed to 115200
  4. Click Open and you should see the terminal

Logging In

Once you’ve brought up the shell, you’ll be faced with a login prompt. You can log into your Raspberry Pi with the following credentials:

  • username: pi
  • password: raspberry

Ok we’re in! Let’s have a look around in the next tutorial.

Raspberry Pi 00: Introduction & Flashing SD Card

The Raspberry Pi is an incredible little computer made up of a components and connectors on an unfeasibly small printed circuit board that is approximately the dimensions of a credit card. Depending upon your intended use, your Rasberry Pi may have a keyboard, monitor and mouse added. Regardless of your intended use, you are going to need an SD (Secure Digital) card on which to install an operating system.

This tutorial describes how to install an operating system onto an SD card for use in your Raspberry Pi.

What You Need to Do and Why

In order to get up and running with your Raspberry Pi, you will first need to flash an SD card. Whilst your Mac, or PC, uses a magnetic hard disc drive (HDD) or a Solid State Drive (SSD), your Raspberry Pi has no internal storage of its own.

Instead, the Raspberry Pi uses a Secure Digital (SD) card, such as is common as storage in many digital cameras.

This means that the Raspberry Pi will run from whatever operating system you install on an SD card. You can do from your main computer regardless of whether you are using Apple OS X, Linux or Microsoft Windows.

For the purposes of this tutorial I will be downloading Raspian, for Raspberry Pi.

The download will be compressed as a .zip file. You will need to extract to .img or .iso file before proceeding.

Tip: You can download a number of different operating systems, including RISC OS, Raspian, Raspbmc, Openelec and pidora, from the Raspberry Pi downloads site or you can download the NOOBS, New Out Of Box Software

Good Installation Guide:

https://www.raspberrypi.org/documentation/installation/installing-images/README.md

The easiest method on the Mac is to install Apple Pi Baker, it’s got a simple user interface so you don’t have to muck about with command lines.

Now it’s time to connect all the peripherals and boot our Raspberry Pi up.